Strange: GetMessage keeps returning message

This is a discussion on Strange: GetMessage keeps returning message within the Windows Programming forums, part of the Platform Specific Boards category; Hi There, The following codes keeps returning messages even nothing is preesed in the keyboard and mouse is not moved ...

  1. #1
    wow
    wow is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    42

    Strange: GetMessage keeps returning message

    Hi There,

    The following codes keeps returning messages even nothing is preesed in the keyboard and mouse is not moved and touched.
    Code:
        
         while ( bRet = GetMessage (&msg, NULL, 0, 0))
         {
              bRet = TranslateMessage (&msg) ;
              if (0 == bRet)
                   MessageBox (NULL, TEXT ("Error: GetMessage return 0!"), 
                          szAppName, MB_ICONERROR) ;
              DispatchMessage (&msg) ;
         }
    Three returns are:
    Code:
     
    meg        1st                       2nd                      3rd
    hwnd       0x00000000       0x00000000       0x00000000
    message 49368                 49368                 49368
    wParam  17                        17                      17
    lParam    657624                854138              1050746
    time       143047484           143249515        143362468
    pt           {x=830 y=237}    {x=653 y=563} {x=611 y=561}
    For these messages, TranslateMessage returns 0.

    The OS is Windows 2000 with Service pack 4 or Windows XP with service pack 2.

    What're these message? Where are they from?

    Note about TranslateMessage Return Value

    If the message is translated (that is, a character message is posted to the thread's message queue), the return value is nonzero.

    If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the return value is nonzero, regardless of the translation.

    If the message is not translated (that is, a character message is not posted to the thread's message queue), the return value is zero.

    Thanks,
    Last edited by wow; 07-25-2007 at 07:12 AM.

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    1st, GetMessage returns -1, not 0, to indicate an error see GetMessage

    2nd, there are no system generated messages in the range 49368. Are you sending messages to the window somewhere else in your code or maybe a custom control?

    3rd, HWND of 0 is not a valid window, or maybe the desktop, maybe you should post more of your code.
    Last edited by Darryl; 07-25-2007 at 08:08 AM.

  3. #3
    wow
    wow is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Quote Originally Posted by Darryl View Post
    1st, GetMessage returns -1, not 0, to indicate an error see GetMessage

    2nd, there are no system generated messages in the range 49368. Are you sending messages to the window somewhere else in your code or maybe a custom control?

    3rd, HWND of 0 is not a valid window, or maybe the desktop, maybe you should post more of your code.
    Thanks Darryl for your quick response.

    All three return results from GetMessage are 1, and all three results from TranslateMessage are 0. All three hwnd is 0, that's right (get all message from all windows of the thread).

    That's the question, what's the message 49368? Where they come from? I don't know any program in the system keep sending the message. They are tested on both 2000 and XP, two completely different systems, even there is no any other app is running except the test one.

    Thanks,
    Last edited by wow; 07-25-2007 at 08:36 AM.

  4. #4
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Ok I just tried this on my system and got nothing

    Code:
    MSG msg;
         int rtn;
         while((rtn=GetMessage(&msg, NULL, 0, 0)) != 0)
         {
              if (msg.message == 49368)
              {
                   ::MessageBox(0,TEXT("Hello"),TEXT("Hello"), MB_OK);
              }
              if (rtn == -1)
              {
                   return ::GetLastError();
              }
              else 
                   if (!IsDialogMessage(swinc::SwincWindowBase::g_current_dialog_hwnd, &msg))
                   {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                   }
         }
    Maybe you can run something like spy++ or better win inspector spy and try and trace the message

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    I have no solution for your problem
    but you should check return value - before checking the msg contents...
    If GetMessage failed - msg contents will be probably invalid
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    wow
    wow is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    Good idea, Darryl. Can you tell how I can use Spy++ to trace where is the message come from? I launch Spy++ but get no clue how it can be used.

    Thanks,

  7. #7
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Ok on MSDN that number falls in the range:

    0xC000 through 0xFFFF String messages for use by applications.

    Message numbers in the fourth range (0xC000 through 0xFFFF) are defined at run time when an application calls the RegisterWindowMessage function to retrieve a message number for a string. All applications that register the same string can use the associated message number for exchanging messages. The actual message number, however, is not a constant and cannot be assumed to be the same between different sessions.

  8. #8
    wow
    wow is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    I change the codes to the following:

    Code:
         while ( bRet = GetMessage (&msg, NULL, 0, 0))
         {
              bRet = TranslateMessage (&msg) ;
    		  if (0 == bRet) {
                   wsprintf (szBuffer, TEXT("Error: Message: 0x%x %u, wParam: %u, lParam:0x%08x"),
    				          msg.message, msg.message, msg.wParam, msg.lParam);
                   MessageBox (NULL, szBuffer, szAppName, MB_ICONERROR) ;
    		  }
              DispatchMessage (&msg) ;
         }
    This time the message number changes to: 0xcobd, i.e., 49341. For every click on the OK on the dialog box, the lParam beeps increasing as the following:

    1st
    ---------------------------
    KeyView1
    ---------------------------
    Error: Message: 0xc0bd 49341, wParam: 17, lParam:0x00b208f4
    ---------------------------
    OK
    ---------------------------
    2nd
    ---------------------------
    KeyView1
    ---------------------------
    Error: Message: 0xc0bd 49341, wParam: 17, lParam:0x00b308f4
    ---------------------------
    OK
    ---------------------------
    3rd
    ---------------------------
    KeyView1
    ---------------------------
    Error: Message: 0xc0bd 49341, wParam: 17, lParam:0x00b408f4
    ---------------------------
    OK
    ---------------------------
    4th
    ---------------------------
    KeyView1
    ---------------------------
    Error: Message: 0xc0bd 49341, wParam: 17, lParam:0x00b508f4
    ---------------------------
    OK
    ---------------------------
    5th
    ---------------------------
    KeyView1
    ---------------------------
    Error: Message: 0xc0bd 49341, wParam: 17, lParam:0x00b608f4
    ---------------------------
    OK
    ---------------------------
    6th
    ---------------------------
    KeyView1
    ---------------------------
    Error: Message: 0xc0bd 49341, wParam: 17, lParam:0x00b708f4
    ---------------------------
    OK
    ---------------------------


    My desktop computer seems running normal if I do not run this small piece of codes or if check from TranslateMessage is removed. I do every thing as usual.
    Thanks,
    Last edited by wow; 07-25-2007 at 02:07 PM.

  9. #9
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    I am curious, why are you checking the return on translate message anyway? 0 does not indicate error, only that the message was not translated, ie. not a character message.

    I step through some code of mine in the debugger and was getting message of similar value. As I stated in the other post, this range is for privately registered messages. If I had to guess, I would say some system component is sending out broadcast messages. I would just ignore it.

  10. #10
    wow
    wow is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    You know, it uses and occupies a lot of system time and resources, slows down its response and sometime causes application collapse. How do I notice it exists? One of my app crashes at it.

    Is it a computer virus? What reason for a valid app keeps generating these nonsense messages?

    Thanks,

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Interesting that the lParams are all the max storage size of an int32 apart.

    Try following the msg into the dialog. It may be background window msgs.

    Does IsDialogMessage() process it?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  12. #12
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    if your application is crashing becuase it is receiving a broadcast message that it doesnt know how to handle, then the problem is that your application is not properly handling messages. Any message that your application does not specifically handle needs to be passed to DefWndProc(). This message is probably an auto-discovery message for applications in a suite or sometimes peeps will broadcast a message as a way of ensuring that every thread in their application recieves the message. Its sloppy coding, but its easier than maintaining an internal list of every hwnd of every thread in your application. As long as you arent sending a lot of broadcasts, it shouldnt degrade system performance noticeably, btu it is still a kludge.


    Quote Originally Posted by novacain View Post
    Interesting that the lParams are all the max storage size of an int32 apart.
    Dont you mean int16 ?
    Last edited by abachler; 07-27-2007 at 12:48 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Opps
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  14. #14
    wow
    wow is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    42
    It collapses at the inside of TranslateMessage: illegal instruction. I have no idea what's going on inside of the function, and why it crashes. So I try to check the return from it but fail because of the nonsence message keeping coming.

    Thanks,

  15. #15
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by wow View Post
    It collapses at the inside of TranslateMessage: illegal instruction.
    How do you come to this conclusion? TranslateMessage, either translates or doesn't, it doesn't return any errors.

    Just to test, comment out TranslateMessage, (unless your app relies on keyboard input), and see if your app still crashes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a message with wanted lparam from queue
    By BrownB in forum Windows Programming
    Replies: 6
    Last Post: 12-24-2007, 07:37 PM
  2. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 01:22 AM
  3. Warning Message: Undefined; Assuming extern returning int
    By alanhomer in forum C++ Programming
    Replies: 2
    Last Post: 10-31-2005, 10:21 AM
  4. Middle button mouse capture in another program
    By Gayak in forum Windows Programming
    Replies: 5
    Last Post: 06-13-2002, 05:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21