dcsimg
 

Window Finder OLE Control

Tuesday Feb 23rd 1999 by shellreef shellreef

Window Finder OLE Control

Visual C++ 4.0 Project

Window Finder is an OLE control that is similar to Spy++'s Window Finder control. The user can drag the circle over a window (a dark border will be drawn around the window) to select it, and the program can figure out what the handle of the window is.

Note: You can tell in the example screenshot, but the cursor has changed to a circle and is over the "Microsoft (R) Notepad" static control.

To use the Window Finder OLE Control, you will will need to register it first (by loading the MDP file and chosing register control, or using regsvr32), and then have Visual C++ generate a class for it. Choose Insert|Component and then scroll down to "WinFinder Control" and press Insert (the control has to be registered or it will not be there).

In the demo project, I inserted the Window Finder control by right-clicking on the dialog and chosing "WinFinder Control". I then brought up ClassWizard (Ctrl+W) and added a varible that represents the window handle by double-clicking on the ID (in the member varibles tab) and specifing "targetWindow" as the catagory. The "dragging" property is mainly used internally but if you want to figure out if the user is dragging it or not this is how to do it...

Note: The varible type for the catagory targetWindow is "long" because it seems that I could only use certain varible types, and HWND was not one of them.

Now you can access the member varible made by ClassWizard previously, but how do you know when it changed? The Window Finder OLE Control has a callback function that is call whenever the window under the mouse changes (when dragging).

I first tried to make the callback function a property, but that did not work, so you have to post a message to the control. The message should be WM_SETWFCALLBACK, or WM_USER + 100. LPARAM should be the address to a struct that looks like this:


typedef int (*WINFINDERCALLBACK)(HWND);

typedef struct
{
    WINFINDERCALLBACK pfn;
} *LPWINFINDERCALLBACKSTRUCT;

'pfn' should point to the address of the callback function. The WPARAM parameter to the message should be zero if you want the callback function set to the one specified in the LPARAM structure, or zero if you don't wan't to set it. The return value of the message handler is always the address of the callback function, so setting WPARAM to a non-zero value can be used to retrive the address to the function.

More on the callback function. It should return one of the following:

Use Window 0
Ignore Window 1
A return value of 0 indicates that an outline should be drawn around the window, or a value of 1 means that the window should be ignored (this is useful for ignoring the dialog that the control is in, like Spy++ does). The declaration of the callback following should be similar to:


int WindowFinderSelected(HWND hWnd);

'hWnd' is the handle of the currently selected window, which can also be retreived by the "targetWindow" property.

The sample project displays the the window handle of the window that is selected by the Window Finder Control. The callback function sets the caption of the window handle to the window handle of the selected window.

That's all. I hope you like it.

By the way, I'm making an application that manipluates Windows using this control.

Download ActiveX control - 11KB

Download demo project - 27.4KB

Home
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved