Solved

SetWindowsHookEx() question

Posted on 1997-10-12
11
550 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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
 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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