Click here to Skip to main content
15,893,161 members
Articles / Programming Languages / C++

Writing Win32 Apps with C++ only classes (part 3)

Rate me:
Please Sign up or sign in to vote.
4.76/5 (14 votes)
20 Jun 2004CPOL26 min read 69K   979   56  
C++ classes and wrappers to write W32 apps without MFC, ATL or other (part 3).
#include "StdAfx.h"
#include "msgloop.h"

namespace GE_{namespace NWin{


	GE_INLINE bool SMsgLoop::IsIdleMessage(UINT msg)
	{
		// These messages should NOT cause idle processing
		switch(msg)
		{
		case WM_NCMOUSEMOVE:
		case WM_MOUSEMOVE:
		case WM_PAINT:
		case 0x0118:	// WM_SYSTIMER (caret blink)
			return false;
		}
		return true;
	}


	GE_INLINE bool SMsgLoop::LoopBody()
	{
		MSG msg;
		
		if(!GetMessage(&msg, 0,0,0)) //wait next message
			return false; //peeked up a quit message
		STRACE(trc,0,("Msg rcv CMessageLoop: HWND %p, Msg %p\n", msg.hwnd, msg.message));
		
		//do eventual message filtering
		if(!SMsgFilterEvent::GetGlobal()(msg))
		{	
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		//do Idle processing (if any)
		static bool bMustDoIdle = false;
		bMustDoIdle |= IsIdleMessage(msg.message);
		if(bMustDoIdle && !PeekMessage(&msg, 0,0,0, PM_NOREMOVE))
		{
			SIdleEvent::GetGlobal()(this);
			bMustDoIdle = false;
		}

		return true; //continue the loop
	}

	GE_INLINE bool SMsgLoop::LoopWhile(bool& bContinue)
	{
		while(bContinue)
			if(!LoopBody())
				return false;
		return true;
	}

	GE_INLINE void SMsgLoop::Loop(HWND hMainWnd)
	{
		bool b = true;
		if(hMainWnd)
			_hWnd = hMainWnd;
		STRACE(trc, 1, ("Entering message loop %s %p\n", typeid(*this).name(), this));
		LoopWhile(b);
		STRACE(trc1,1,("Leaving message loop %s %p\n", typeid(*this).name(), this));
	}

}}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Italy Italy
Born and living in Milan (Italy), I'm an engineer in electronics actually working in the ICT department of an important oil/gas & energy company as responsible for planning and engineering of ICT infrastructures.
Interested in programming since the '70s, today I still define architectures for the ICT, deploying dedicated specific client application for engineering purposes, working with C++, MFC, STL, and recently also C# and D.

Comments and Discussions