Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Super Big Problem with SetWindowsHookEx function!!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have writen a program with GUI in C++. It is used to get the many kinds of system message by using SetWindowsHookEx.
I have two functions.

The first is:

void createHook()
{
hMouseHook = SetWindowsHookEx( WH_MOUSE, (HOOKPROC) MouseHookProc, hInst, 0L );
}

The second is:

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam )
{
LPMOUSEHOOKSTRUCT MouseHookParam;
if ( nCode >= 0 )
if ( wParam == WM_MOUSEMOVE )
{
if ( nCode == HC_NOREMOVE )
strcpy(szType, "NOT Removed from Queue");
else
strcpy(szType, "REMOVED from Queue");
MouseHookParam = (MOUSEHOOKSTRUCT *) lParam;
printf("Mouse at X = %d, Y = %d is %s\n\n", MouseHookParam->pt.x, MouseHookParam->pt.y, szType );
/// write to file to show result
f1=fopen("c:\\report.txt","a+");
fprintf(f1, "Mosue Location At ( %d, %d )\n", MouseHookParam->pt.x, MouseHookParam->pt.y);
fclose(f1);
///
}
return ( CallNextHookEx(hMouseHook, nCode, wParam, lParam) );
}

The problem is that if the mouse moves inside the GUI frame, the data can be saved in a text file and printed out on the screen, but the mouse moves outside the GUI frame, the mouse data can be only saved in a text file, but it cannot be printed on the console screen.

The printf seems not to run and by-pass this statement.

Why? plz help me, Hero!!! Thz a lot!!!
 
It may be that nCode is < 0 if so you must pass the message to CallNextHookEx and return it's value. Since once the mouse exits the confines of your application another handler may well be hooked to trap its events.

HTH
William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top