We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


SetWindowsHookEx() question

alexo asked
Medium Priority
Last Modified: 2013-12-03

I have written a program that uses a SetWindowsHookEx(WH_CALLWNDPROC) to set a hook that watches for WM_INITDIALOG messages and subclasses a dialog of another application.

Now, to minimize system impact, I'd like to use a SetWindowsHookEx(WH_CBT) hook and watch for HCBT_CREATEWND.

The problem is that this specific dialog has no title so I identify it by it's children (controls).  However, when HCBT_CREATEWND is processed, the children are not yet created so I cannot identify the correct dialog.

Any suggestions?
Watch Question

use CreateDialogParam or DialogBoxParam and pass in some unique value for each window you create.


The question explicitly states that I subclass a dialog created by ANOTHER APPLICATION which I have no control over.
I have no idea what parameter is passed to this dialog, whether it is guaranteed to be unique or even if there is one at all.

Then can you just watch for the creation of it child control?  From the handle of the child you can get the window itself, is that too late for your application?


It's difficult.

Those contols are static text and buttons which can be present on other dialogs as well.  I don't know their order of creation so checking the others when one is created won't work.


Time to reopen the question
are there no unique identifying features of this dialog.  use getclassname() & getclassinfo() & getwindowlong() to find out all the registration info for a window and try to match something unique (maybe dialog id?).  if the dialog is known to fire off by some command or menu maybe you'll need to filter the WM_COMMAND message.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


No go.

The class is the general "dialog" class used by almost any dialog on the planet.

how about the dialog id? use spy to figure out the dlg id then use getwindowlong( hDlg, GWL_ID ) to get the id of the dialog.  surely this is unique enough for you..


I was under the impression that the GWL_ID is application unique but not system-wide unique.  So it wouldn't work.
Am I wrong about it?  Can you point me to a document that says otherwise?

gwl_id is unique to the dialog to the application but not globally unique.  however if you combine it with class, id, size, title, icon, whatever you should be able to find a fairly unique combination of things to identify this object.


Hmmm...  Seems about jusr right.

I can traverse the GWL_HWNDPARENT until I can uniquely identify the application and then check GWL_ID to identify the dialog.
Does it sound reasonable?

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.