Showing tag results for Code

Aug 29, 2013
Post comments count0
Post likes count1

How can I write to a file only as long as nobody's looking?

Raymond Chen
Raymond Chen

A customer wanted to know how to detect that the user has opened Notepad to view a particular file. They had come up with method based on polling and sniffing the Notepad title bar, but they found that it consumed a lot of CPU. (They hadn't noticed yet that it doesn't localize, and that it can trigger false positives since Notepad shows only the fi...

Code
Aug 28, 2013
Post comments count0
Post likes count1

The format of data and custom resources

Raymond Chen
Raymond Chen

Continuing the highly-sporadic series of Win32 resource formats, today we'll look at the format of resources, which are declared in resource files as . Also the format of custom resources, which are declared in resource files by just giving the custom resource name or ordinal as the second word on the declaration. The format is very simple: It's ...

Code
Aug 26, 2013
Post comments count0
Post likes count1

Why doesn't the "Automatically move pointer to the default button in a dialog box" work for nonstandard dialog boxes, and how do I add it to my own nonstandard dialog boxes?

Raymond Chen
Raymond Chen

The Mouse control panel has a setting called Automatically move pointer to the default button in a dialog box, known informally as Snap to default button or simply Snap To. You may have discovered that it doesn't work for all dialog boxes. Why not? The Snap To feature is implemented by the dialog manager. When the window is shown and the setting...

CodeTips/Support
Aug 23, 2013
Post comments count0
Post likes count1

If I attach a file to an existing completion port, do I have to close the completion port handle a second time?

Raymond Chen
Raymond Chen

There are two ways of calling the function. You can pass a null pointer as the parameter, indicating that you would like to create a brand new completion port, associated with the file handle you passed (if you passed one). Or you can pass the handle of an existing completion port, and the file handle you passed will be associated with that por...

Code
Aug 22, 2013
Post comments count0
Post likes count1

All I/O on a synchronous file handle is serialized; that's why it's called a synchronous file handle

Raymond Chen
Raymond Chen

File handles are synchronous by default. If you want asynchronous file handles, you need to pass the flag when you create the handle. And all operations on a synchronous file handle are serialized. You'd think this was a simple and obvious rule, but "Someone" finds it "very surprising that operations can block which only handle file metadata." I...

Code
Aug 19, 2013
Post comments count0
Post likes count1

The tiny table sorter – or – you can write LINQ in JavaScript

Raymond Chen
Raymond Chen

I had a little side project that displayed status information in a table, and I figured, hey, let me add sorting. And it was a lot easier than I thought. I just put the header row in the and the table contents in the , then I could use this code to sort the table: Each cell can have an optional custom attribute which specifies how the item sh...

Code
Aug 16, 2013
Post comments count0
Post likes count1

If I signal an auto-reset event and there is a thread waiting on it, is it guaranteed that the event will be reset and the waiting thread released before SetEvent returns?

Raymond Chen
Raymond Chen

Let's go straight to the question: I have two programs that take turns doing something. Right now, I manage the hand-off with two auto-reset events. In Thread A, after it finishes doing some work, it signals Event B and then immediately waits on Event A. Thread B does the converse: When its wait on Event B completes, it...

Code
Aug 15, 2013
Post comments count0
Post likes count1

How do I control the order of the pages in property sheets from my shell extension?

Raymond Chen
Raymond Chen

A customer wanted to know whether a shell extension can control the order of the property sheet pages in a property sheet. The interface lets you add pages and replace pages, but nothing about rearranging them. Naturally a shell extension can control the relative order of its own pages (by changing in the order in which it calls ) but how can it...

Code
Aug 14, 2013
Post comments count0
Post likes count1

What's the point of letting you change the GCL_CBCLSEXTRA if it has no effect?

Raymond Chen
Raymond Chen

The documentation for the function mentions GCL_CB­CLS­EXTRA: Sets the size, in bytes, of the extra memory associated with the class. Setting this value does not change the number of extra bytes already allocated. What's the point of letting the application change a value if it has no effect? The class long grants access to the v...

Code
Aug 12, 2013
Post comments count0
Post likes count1

How do I convert a synchronous file handle into an asynchronous one?

Raymond Chen
Raymond Chen

Say you opened a file in synchronous mode, and then you realize that you want to issue asynchronous I/O on it, too. One way to do this is to call a second time with the , but this requires you to know the file name, and the file name may not be readily available to the function that wants to do the conversion, or it may not even be valid any long...

Code