Message loop not working...

This is a discussion on Message loop not working... within the Windows Programming forums, part of the Platform Specific Boards category; Oh shoot, I hate it when I do this sort of thing Everything works fine and as expected if I ...

  1. #16
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Oh shoot, I hate it when I do this sort of thing Everything works fine and as expected if I check for WM_COMMAND and WM_CLOSE in the dialog procedure, although for some reason it doesn't work when I check in the message loop. The reason I checked in the message loop was to avoid using yet another global variable, but in this case I can't see how to avoid it Any ideas, or should I just get on with my life and leave the global variable there?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #17
    id id
    Guest
    I encountered this a while ago.
    It turns out WM_CLOSE (and others) is a sent message. This means Windows calls your Window Proc directly. It will not be returned by GetMessage. The last message you get is something like WM_NCLBUTTONUP. After this when you call GetMessage Windows takes the opportunity to call your Window Proc directly with WM_CLOSE.

  3. #18
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by Hunter2
    Oh shoot, I hate it when I do this sort of thing Everything works fine and as expected if I check for WM_COMMAND and WM_CLOSE in the dialog procedure, although for some reason it doesn't work when I check in the message loop. The reason I checked in the message loop was to avoid using yet another global variable, but in this case I can't see how to avoid it Any ideas, or should I just get on with my life and leave the global variable there?
    Never check for messages in the message loop; ALWAYS check in the window procedure. The window procedure's mission in life is to respond to messages; this is where messages should be handled, without exception.

    As to ways around a global variable, you can use the UserData long in the window to store information, see GetWindowLongPtr() and SetWindowLongPtr() for info.

  4. #19
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Wow, thanks a bunch! I never knew Windows had a UserData to use. Except, shouldn't it be GetWindowLong() instead of GetWindowLongPtr()?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #20
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by Hunter2
    Wow, thanks a bunch! I never knew Windows had a UserData to use. Except, shouldn't it be GetWindowLong() instead of GetWindowLongPtr()?
    GetWindowLongPtr() replaces GetWindowLong(). Compiled for 32-bit systems they have the same effect. But GetWindowLongPtr() and SetWindowLongPtr() are the newer and recommended way to access the window data because they are compatible with 64-bit versions of Windows. SetWindowLong() can only store 32 bits of data regardless; on Win32 this is OK, because pointers are 32 bits, but under Win64, pointers are 64 bits.

    SetWindowLongPtr() sets a 32 bit value under Win32, 64 bit value under Win64, so you should prefer it. Likewise with GetWindowLongPtr().

  6. #21
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Odd, it gives me a compile error: undeclared identifier. Are you sure that I don't need any special include or something?

    *EDIT*
    Also, they don't appear in my MSDN when I type them in the index...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #22
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Probably an out-of-date library.

    It's no big deal assuming you're writing for Win32 and don't care about Win64, you can just omit the -Ptr.

    http://msdn.microsoft.com/library/de...dowLongPtr.asp

  8. #23
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Oh ok, thanks. But what exactly is win64? Is it Windows NT and 2000?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #24
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Win64 is Windows for 64-bit CPUs. It's been around in the server world for a while, but XP is the first to offer a general 64-bit version for desktops. CPUs like the Itanium2 are 64-bit (as opposed to Athlon, Pentium, etc. which are 32-bit).

    XP 64 allows you to have workstations with up to 16 gigs of RAM and 8 terabytes of virtual memory; the 16 GB limit will probably be relaxed in later OSs (e.g. Longhorn). Theoretically, a 64-bit machine could have 16.7 million terabytes (= 17.1 billion gigabytes) of memory.

    It is backwards compatible (it can run Win32 applications), but Win32 applications will not be able to benefit from the large amount of RAM; the virtual memory space of the Win32 application would still be 4 GB, and no more.

  10. #25
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    The light dawns. Thanks for the explanation!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to understand the message loop
    By bling in forum Windows Programming
    Replies: 4
    Last Post: 08-08-2008, 09:27 AM
  2. Message loop
    By beene in forum Game Programming
    Replies: 2
    Last Post: 11-26-2007, 04:19 PM
  3. "try again" loop not working
    By scwizzo in forum Game Programming
    Replies: 5
    Last Post: 04-01-2007, 09:56 PM
  4. Pausing in the message loop
    By IdioticCreation in forum Game Programming
    Replies: 7
    Last Post: 01-22-2007, 06:21 PM
  5. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM

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