Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Strange Behavior of MessageLoop

Strange Behavior of MessageLoop

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Muhammad Ahmed 0
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups