Strange Behavior of MessageLoop
-
Hi: Ok guys let me narrate the prob: i've installed a windows hook monitoring some system events ,infact i am capturing the keb-keys,arrival of each message is followed by some writing of values in a text file .the writing of this key event was done in the KeyboardProc() present in the dll,but this did'nt work well because obviously i had to call the next hook in the chain as soon as possible but i was doing some file processing... the result of this was that when i typed the keyboard-keys quickly ,i found that the file has not recorded the exact sequence of the keys, rather some keys were swaped ...for example when i typed "my name is ahmed" i received something like this in the file "my anme si ......" this behavior is seen when i type quickly i tried an alternative using Critical section in key keboardproc but this could not work also ,perhaps we can't block the system who calls the KeyboardProc()..... /************************************************/ ok guys i've changed my approach now but still some problems are there as explained below now i am simply Posting the character(key) received in the keyboardproc() to a thread in a seperate process and calling the next hook imidiately as shown below ... KeboardProc(.........) { .............................................. /*hThread is the handle of the window associated with a thread in a seperate process*/ //imediately return after posting unlike SendMessage() PostMessage(hThread,...,...,..); return CallNextHook(..); } /***********************************************/ Message loop in the thread that is receiving messages from hook while( GetMessage( &msg, NULL, 0, 0 )) { 1: TranslateMessage(&msg); 2: AfxMessageBox(" key notification "); //DispatchMessage(&msg); } My target is that the next key in the message que is not extracted from the que untill the previous has been processed.. Problem: the problem here is that when i press a key i get an AfxMessageBox() as desired in the message loop , now when i press the second key without dismissing the "AfxMessageBox" that was showed for the first key,a new "AfxMessageBox" box appears and this keeps happening as long as i keep pressing keys so message window keep on increasing why is this happening.....? Because the rule says if do not dimiss a messagebox the control should not go to the next statement.. so why the next message is processes while the previous message is still not completely processed 1: while( GetMessage( &msg, NULL, 0, 0 )) { 2