Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In the following code we have a CBT hook proc.

Nothing to it. Upon launching a window of interest with the mouse HCBT_ACTIVATE is caught and WindowString is obtained then checked for "The window I want".

We'll call them, Window 1, Window2, and TheWindowIWant.

If I put a breakpoint at the call to CheckWindowString(), I can see 3 windows being created
with the 3rd of the three being the one I am after.

If I remove that breakpoint and let the code rip, only the first two windows are "caught"

Windows 1 and Window 2.

I could not believe it so I put a break and continue breakpoint that printed out the WindowText then continued execution to prove it. It indeed showed that HCBT_ACTIVATE was indeed apparently "missing" the activation of the desired window even though, there it is on the desktop, all nice and activated.

Unless execution is stopped by the breakpoint that window is never seen by HCBT_ACTIVATE and consiquently never acted upon as I wish.

Out of desparation tried Sleep(1000) where the breakpoint was - That didn't work.

HELP! :-)

:Ron


C++
LRESULT CBCRMaster::MyCBTProc(int nCode,WPARAM wParam,LPARAM lParam)
{
	if(nCode == HCBT_ACTIVATE)
	{

		CBTACTIVATESTRUCT *cwp = (CBTACTIVATESTRUCT*) lParam;
		
		char WindowString[255];
		GetWindowText((HWND)wParam,WindowString,255)

		CheckWindowString();
}
Posted
Comments
Sergey Alexandrovich Kryukov 5-Aug-14 18:01pm    
Is it a global or local hook? If the hook is global, did you put a hook in a separate DLL, as Microsoft recommends?
—SA
Ron Anders 5-Aug-14 18:09pm    
Sorry I did not specify, it is Local
Richard MacCutchan 6-Aug-14 4:11am    
Are you sure it's missing the window, and not that the check for the Window's text is failing for some reason?
Ron Anders 6-Aug-14 9:18am    
During troubleshooting I also included the return from GetWindowText as well as wParam. Sometimes even under "breakpoint throttling" the return is 0. One between each of the Activated Windows where title text was obtained. There were no more 0s logged when running without the breakpoints than there was stopping by hand. That's all I have been able to gleen there.

This a child window. The first Activtated window that arrives has the parent window's title. I ignore that. The next one is has the document name that is open in the parent window. I also ignore that. Then the full child window is to be activated and it's title contains what I am looking for. But again only if I break the code with the debugger.

Thanks for the help. I am grounded until I am able to implement either a work around or just get it working. :-)

:Ron

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900