Window Finder OLE Control

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

Visual C++ 4.0 Project

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

To use the Window Finder ActiveX control, you will first need to register it using regsvr32 (type regsvr32 winfinder.ocx at the command line). In the Insert Control dialog, the control will be named "WinFinder Control".

Changes From 1.0 to 2.0
  • No global callback function needed, a WM_USER + 100 message is sent to parent window when selection changes
  • Demo project changes
  • Minor bugfixes

In the demo project, "targetWindow" is shown in the static control, it is updated in the callback function.

Note: The variable 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.

Notification Message

When the window selection changes, the WinFinder control sends a WM_CHAR + 100 message to it's parent window (usually a dialog). The LPARAM parameter contains the new selected window handle.

This replaces the callback function, but for compatability the callback function can still be used (see the next section). If you need more flexibility, use the callback function. Callback Function

To set a callback function that is called when the selected window c changes, you have to send a WM_USER + 100 message to the WinFinder control. LPARAM should be the address to a structure 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.

The callback function should return a value of "0" to allow the window to be selected, or "1" to ignore the window (this is ueful for ignoring the dialog that the control is in, like Spy++ does). The declaration of the callback function 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 default callback function allows all windows to be selected.

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.

Conclusion

The WinFinder control isn't very useful for many applications, but sometimes it may be just what you need.

Downloads

Download OCX - 11 Kb
Download demo project - 16 Kb
Download source - 33 Kb


Comments

  • WinControl

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

    Originally posted by: Venkatesh

    excellent tool

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

Top White Papers and Webcasts

  • Microsoft Azure® is a leading choice for businesses looking to take advantage of the cloud. Azure is particularly appealing to businesses that have already invested in Microsoft on-premises and are now considering running these applications and other workloads in the cloud. To understand how to make this move to Azure, many businesses are turning to managed service providers (MSPs) with specific Azure expertise. Read this white paper to learn the eight key areas to focus on when considering an MSP for an …

  • Many enterprises are working with an IT architecture that's evolved over time. As business needs evolve, IT must decide whether to modernize incrementally, or all at once. Each approach has its benefits and drawbacks. Identity Management is key to modernizing IT; it plays a crucial role in migrating to cloud apps like Office 365 or HR information systems, building web and mobile apps, and opening developer access to business systems. Read how Okta's modern approach to identity management helps business lower …

Most Popular Programming Stories

More for Developers

RSS Feeds

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