Thread: windowproc vs. peekmessage

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    6

    windowproc vs. peekmessage

    Thanks in advance for any response

    I am having difficulties understanding why it is necessary for me to use peekmessage() to read into the windows message queue when we are forced to register a windows message handling function in the WNDCLASSEX structure. isn't this registered function called by windows to handle all the messages in the queue? thats what i gathered while splunking through msdn.
    My difficulty in grasping its use comes from the apparent need to call peekmessage() then, if necessary, call dispatchmessage() which then runs the wndproc function, which then may in fact run defwndproc(). it just seems a bit of a nasty potential chain of events and a waste of resources (imho) which could all be done by one function - which in turn would not have to be registered with the WNDCLASSEX struct.

    Im working on a small opengl app. using nehe's tuts and msdn. novice c++ programmer who chose to just dive in so bear with me if the question is a bit...as the gamers say...n00bish.

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    6
    this link was buried in the anals of the forum somewheres:

    http://www.winprog.org/tutorial/

    on this site i found a reference that states specifically the affirmation of my suspicion...the system does not call the windowproc. why then are we required to register this function with the WNDCLASSEX struct? it still seems a bit in excess if we can do all the message handling with get/peekmessage() else defwndproc().

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Message handling is far more complicated than you think.

    You call GetMessage or PeekMessage. Then you might call IsDialogMessage, which may call the registered WndProc. Then you might call IsAccelerator, which may call the registered WndProc. Then you usually call TranslateMessage, which also may call the registered WndProc. Then you call DispatchMessage, which also calls the registered WndProc.
    CreateWindow calls the registered WndProc several times. UpdateWindow does, too.
    The SendMessage family of calls all call the registered WndProc one way or another.
    Without a registered WndProc, subclassing windows would not be possible.

    Have I left anything out?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Some msgs bypass the message que and are posted directly to the wndproc (eg UpdateWindow() ).


    MSDN
    "The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. "
    "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

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    6
    appreciate it, thats what i was wondering about, cleans up my understanding

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PeekMessage function
    By Micko in forum Windows Programming
    Replies: 9
    Last Post: 09-14-2004, 03:06 PM
  2. 100%cpu usage with PeekMessage
    By glUser3f in forum Windows Programming
    Replies: 6
    Last Post: 08-19-2003, 06:56 AM
  3. PeekMessage
    By xds4lx in forum Windows Programming
    Replies: 13
    Last Post: 08-26-2002, 10:51 PM
  4. PeekMessage
    By Garfield in forum Windows Programming
    Replies: 9
    Last Post: 12-16-2001, 01:52 PM
  5. WindowProc in a class
    By Mox in forum Windows Programming
    Replies: 3
    Last Post: 10-24-2001, 04:46 PM