Click to See Complete Forum and Search --> : PeekMessage Expensive loop
wigga
June 8th, 2009, 09:25 AM
1. if WM_QUIT is send is it removed?( if so than the main msg loop will keep continueing while the WM_QUIT is send)
2. do i need to use translate/dispatch while specifieing PM_REMOVE?
i am populating a LISTVIEW control and i thought it would be better to process the queu for every added item.
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
_Superman_
June 8th, 2009, 11:16 AM
PeekMessage is normally used to check if a message is available or not and optionally remove the message from the queue.
You should be using GetMessage here instead of PeekMessage as GetMessage waits for a message till it encounters a WM_QUIT message.
And you need a DispatchMessage call if you want to get the message in your window procedure.
wigga
June 8th, 2009, 11:18 AM
Thats why axactly GetMessage is NOT what i want.
read my message again.
_Superman_
June 8th, 2009, 11:28 AM
What you have done is probably right.
Its just that if there is no message in the queue at any time, the control will come out of the while loop.
wigga
June 9th, 2009, 10:29 AM
nvm i solved it.
struct CMsg
{
inline CMsg(HWND hWnd = NULL):
hwnd(hWnd)
{
::memset(&msg, 0, sizeof(msg));
}
inline operator UINT() const
{
return Message();
}
inline bool Dispatch()
{
return ::DispatchMessage(&msg);
}
inline bool Get(UINT msgMin = 0, UINT msgMax = 0)
{
return ::GetMessage(&msg, hwnd, msgMin, msgMax);
}
inline UINT Message() const
{
return msg.message;
}
inline bool Peek(UINT msgMin = 0, UINT msgMax = 0) const
{
return ::PeekMessage(&msg, hwnd, msgMin, msgMax, PM_NOREMOVE);
}
inline bool Remove(UINT msgMin = 0, UINT msgMax = 0)
{
return ::PeekMessage(&msg, hwnd, msgMin, msgMax, PM_REMOVE);
}
inline bool Translate()
{
return ::TranslateMessage(&msg);
}
inline bool Wait() const
{
return ::WaitMessage();
}
inline WPARAM wParam() const
{
return msg.wParam;
}
private:
HWND hwnd;
mutable MSG msg;
};
CMsg msg;
while(msg.Peek())
{
if(msg == WM_QUIT)
break;
msg.Remove();
msg.Translate();
msg.Dispatch();
}
wigga
June 10th, 2009, 08:32 AM
message WM_QUIT is not recieved...? Does PeekMessage not recieve wm_quit?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.