win32窗口程序,请先辈们指导一下

win32窗口程序,请前辈们指导一下,
下面是Win32函数窗口程序中的消息循环,
while(TRUE)
{
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
        if(msg.message == WM_QUIT)break;
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    else{
        //其他的代码……
    }
}


我不知道什么情况下执行到else里的代码,是不是当消息队列(message queue)为空的时候,就执行else
中的代码?
------解决思路----------------------
因为你发错地方了吧。这个问题应该发到 c/c++ 开发语言版去;这里,只是 windows 使用方面的。
应该是你说的这个意思吧,看下 PeekMessage() 的 API 说明,注意和 GetMessage() 函数的区别。
------解决思路----------------------
你的理解是正确的
------解决思路----------------------
win32窗口程序,请先辈们指导一下查MSDN是Windows程序员必须掌握的技能之一。

PeekMessage
The PeekMessage function checks a thread message queue for a message and places the message (if any) in the specified structure. 

BOOL PeekMessage(
  LPMSG lpMsg,         // pointer to structure for message
  HWND hWnd,           // handle to window
  UINT wMsgFilterMin,  // first message
  UINT wMsgFilterMax,  // last message
  UINT wRemoveMsg      // removal flags
);
 
Parameters
lpMsg 
Pointer to an MSG structure that receives message information. 
hWnd 
Handle to the window whose messages are to be examined. 
wMsgFilterMin 
Specifies the value of the first message in the range of messages to be examined. 
wMsgFilterMax 
Specifies the value of the last message in the range of messages to be examined. 
wRemoveMsg 
Specifies how messages are handled. This parameter can be one of the following values: Value Meaning 
PM_NOREMOVE Messages are not removed from the queue after processing by PeekMessage. 
PM_REMOVE Messages are removed from the queue after processing by PeekMessage. 


You can optionally combine the value PM_NOYIELD with either PM_NOREMOVE or PM_REMOVE. This flag prevents the system from releasing any thread that is waiting for the caller to go idle (seeWaitForInputIdle). 

By default, all message types are processed. To specify that only certain message should be processed, specify one of more of the following values: Value Meaning 
PM_QS_INPUT Windows NT 5.0 and Windows 98: Process mouse and keyboard messages. 
PM_QS_PAINT Windows NT 5.0 and Windows 98: Process paint messages. 
PM_QS_POSTMESSAGE Windows NT 5.0 and Windows 98: Process all posted messages, including timers and hotkeys.  
PM_QS_SENDMESSAGE Windows NT 5.0 and Windows 98: Process all sent messages. 



Return Values
If a message is available, the return value is nonzero.

If no messages are available, the return value is zero. 

Remarks
Unlike the GetMessage function, the PeekMessage function does not wait for a message to be placed in the queue before returning. 

PeekMessage retrieves only messages associated with the window identified by the hWnd parameter or any of its children as specified by the IsChild function, and within the range of message values given by the wMsgFilterMin and wMsgFilterMax parameters. If hWnd is NULL, PeekMessage retrieves messages for any window that belongs to the current thread making the call. (PeekMessage does not retrieve messages for windows that belong to other threads.) If hWnd is –1, PeekMessage only returns messages with a hWnd value of NULL, as posted by the PostThreadMessage function. If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns all available messages (that is, no range filtering is performed). 

The WM_KEYFIRST and WM_KEYLAST constants can be used as filter values to retrieve all keyboard messages; the WM_MOUSEFIRST and WM_MOUSELAST constants can be used to retrieve all mouse messages. 

The PeekMessage function normally does not remove WM_PAINT messages from the queue. WM_PAINT messages remain in the queue until they are processed. However, if a WM_PAINT message has a null update region, PeekMessage does remove it from the queue.

Windows CE: WM_PAINT messages with a null update region are not removed from the queue.

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
Messages and Message Queues Overview, Message and Message Queue Functions, GetMessage, IsChild, MSG,WaitForInputIdle, WaitMessage 

 

------解决思路----------------------
看看peekmessage 和 getmessage的区别,一个是等待,一个是不等待