Showing tag results for Code

Apr 8, 2013
Post comments count0
Post likes count0

The managed way to retrieve text under the cursor (mouse pointer)

Raymond Chen
Raymond Chen

Today's Little Program is a managed version of the text-extraction program from several years ago. It turns out that it's pretty easy in managed code because the accessibility folks sat down and wrote a whole framework for you, known as UI Automation. (Some people are under the mistaken impression that UI Automation works only for extracting d...

Code
Apr 5, 2013
Post comments count0
Post likes count1

How do I wait until all processes in a job have exited?

Raymond Chen
Raymond Chen

A customer was having trouble with job objects, specifically, the customer found that a Wait­For­Single­Object on a job object was not completing even though all the processes in the job had exited. This is probably the most frustrating part of job objects: A job object does not become signaled when all processes have exited. The s...

Code
Apr 4, 2013
Post comments count0
Post likes count0

Don’t forget, the fourth parameter to ReadFile and WriteFile is sometimes mandatory

Raymond Chen
Raymond Chen

The Read­File and Write­File functions have a parameter called lp­Number­Of­Byte­Read, which is documented as __out_opt LPDWORD lpNumberOfBytesRead, // or __out_opt LPDWORD lpNumberOfBytesWritten, "Cool," you think. "That parameter is optional, and I can safely pass NULL." My program runs fine if standard output ...

Code
Apr 3, 2013
Post comments count0
Post likes count0

How can I move an HTREEITEM to a new parent?

Raymond Chen
Raymond Chen

Suppose you have a TreeView control, and you created an item in it, and you want to move the to a new parent. How do you do that? You can't, at least not all in one motion. You will have to delete the and then re-create it in its new location. If you want to move an within the same parent (say, to reorder it among its siblings), then you...

Code
Mar 29, 2013
Post comments count0
Post likes count0

How do I convert a method name to a method index for the purpose of INTERFACEINFO?

Raymond Chen
Raymond Chen

The IMessage­Filter::Handle­Incoming­Call method describes the incoming call by means of an INTERFACE­INFO structure: typedef struct tagINTERFACEINFO { LPUNKNOWN pUnk; IID iid; WORD wMethod; } INTERFACEINFO, *LPINTERFACEINFO; The wMethod is a zero-based index of the method within the interface. For example, IUnknown...

Code
Mar 25, 2013
Post comments count0
Post likes count0

Using accessibility to monitor windows as they come and go

Raymond Chen
Raymond Chen

Today's Little Program monitors windows as they come and go. When people contemplate doing this, they come up with ideas like installing a WH_CBT hook or a WH_SHELL hook, but one of the major problems with those types of hooks is that they are injected hooks. Injection is bad for a number of reasons. It forces the hook to be in a DLL so it can be...

Code
Mar 22, 2013
Post comments count0
Post likes count1

When will GetMessage return -1?

Raymond Chen
Raymond Chen

A source of great consternation is the mysterious return value from : If there is an error, the return value is −1. For example, the function fails if is an invalid window handle or is an invalid pointer. That paragraph has caused all sorts of havoc, because it throws into disarray the standard message pump: But don't worry, the standard m...

Code
Mar 21, 2013
Post comments count0
Post likes count0

Does this operation work when file system redirection is disabled? The default answer is NO

Raymond Chen
Raymond Chen

A customer reported that when their program called to get the icon for a folder, the call failed. "It works on some machines but not others. We don't know what the difference is between the working and non-working machines." They included the offending function from their program, but everything in the function looked good. The problem was somethi...

Code
Mar 15, 2013
Post comments count0
Post likes count0

Playing with the Windows Animation Manager: Moving lots of stuff around

Raymond Chen
Raymond Chen

We saw last time a sample program that moved a circle around. Today I'll try to build the classic demo of animating a lot of objects in a list. This isn't the prettiest code, but I wanted to make as few changes as possible. Start with the Timer-Driven Animation, and make these changes to the Main­Window.h header file. struct Item { I...

Code