Solved

SetWindowsHookEx() question

Posted on 1997-10-12
11
536 Views
Last Modified: 2013-12-03
Hello.

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?
0
Comment
Question by:alexo
11 Comments
 
LVL 3

Expert Comment

by:byang
ID: 1407318
use CreateDialogParam or DialogBoxParam and pass in some unique value for each window you create.
0
 
LVL 11

Author Comment

by:alexo
ID: 1407319
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.

0
 
LVL 7

Expert Comment

by:faster
ID: 1407320
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?
0
 
LVL 11

Author Comment

by:alexo
ID: 1407321
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.

0
 
LVL 11

Author Comment

by:alexo
ID: 1407322
Time to reopen the question
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Accepted Solution

by:
mnguyen021997 earned 100 total points
ID: 1407323
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.
0
 
LVL 11

Author Comment

by:alexo
ID: 1407324
No go.

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

0
 
LVL 2

Expert Comment

by:mnguyen021997
ID: 1407325
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..
0
 
LVL 11

Author Comment

by:alexo
ID: 1407326
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?


0
 
LVL 2

Expert Comment

by:mnguyen021997
ID: 1407327
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.
0
 
LVL 11

Author Comment

by:alexo
ID: 1407328
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?

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now