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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

Most Popular Programming Stories

More for Developers

RSS Feeds