Thomas Weidenmueller wrote
Murphy, Ged (Bolton) wrote:
This should really be
while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
as GetMessage returns <0 on failure. It will then break on failure or WM_QUIT
Just being anal though as GetMessage should never really fail ;)
See http://msdn.microsoft.com/library/default.asp?url=/library/en- us/winui/WinUI/WindowsUserInterface/Windowing/MessagesandMessa geQueues/MessagesandMessageQueuesReference/MessagesandMessageQ ueuesFunctions/GetMessage.asp
The loop shouldn't be broken if GetMessage returns -1.
- Thomas
True, I suppose it depends on the reasoning behind the GetMessage error.
MSDN does have this to say:
"Warning Because the return value can be nonzero, zero, or -1, avoid code like this:
while (GetMessage( lpMsg, hWnd, 0, 0)) ..."
For a bit of light hearted fun, here is the MSDN suggestion:
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } }
which, IIRC (I don't have a compiler to hand) would throw up 'assignment in expression' errors with our MSVC /w4 setting. We would therefore need something like :
bRet = GetMessage( &msg, NULL, 0, 0 ); while( bRet != 0 ) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } bRet = GetMessage( &msg, NULL, 0, 0 ); }
Which has suddenly become rather long for a normally simple message loop routine ..... LOL A nice case for a #pragma warning() ..... or reduce the warning level for non core components (ping)
Ged
************************************************************************ The information contained in this message or any of its attachments is confidential and is intended for the exclusive use of the addressee. The information may also be legally privileged. The views expressed may not be company policy, but the personal views of the originator. If you are not the addressee, any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited. If you have received this message in error, please contact postmaster@exideuk.co.uk mailto:postmaster@exideuk.co.uk and then delete this message.
Exide Technologies is an industrial and transportation battery producer and recycler with operations in 89 countries. Further information can be found at www.exide.com
Murphy, Ged (Bolton) wrote:
which, IIRC (I don't have a compiler to hand) would throw up 'assignment in expression' errors with our MSVC /w4 setting. We would therefore need something like :
Then don't use that warning level if it rejects good code that's not even confusing.
Which has suddenly become rather long for a normally simple message loop routine ..... LOL
It's exactly the same, just ugly IMO.
- Thomas