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

  • 10 Rules that Make or Break Enterprise App Development Projects In today's app-driven world, application development is a top priority. Even so, 68% of enterprise application delivery projects fail. Designing and building applications that pay for themselves and adapt to future needs is incredibly difficult. Executing one successful project is lucky, but making it a repeatable process and strategic advantage? That's where the money is. With help from our most experienced project leads and software engineers, …

  • Live Event Date: September 19, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT In response to the rising number of data breaches and the regulatory and legal impact that can occur as a result of these incidents, leading analysts at Forrester Research have developed five important design principles that will help security professionals reduce their attack surface and mitigate vulnerabilities. Check out this upcoming eSeminar and join Chris Sherman of Forrester Research to learn how to deal with the influx of new device …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds