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



Comments

  • WfTest.rc file missing

    Posted by Legacy on 10/22/2001 12:00am

    Originally posted by: Abeer

    Demo project doesnot compile. WfTest.rc file is missing. It will be great if you upload the code again or provide compiled version of the project.

    Reply
  • Your Demo/Test Project does not compile

    Posted by Legacy on 10/06/2001 12:00am

    Originally posted by: Peter

    Files missing and/or in the wrong place!
    Plus some very weird code!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date