www.pudn.com > WinGOS.rar > MsgObject.h


#ifndef _GOS_MSGOBJECT_H_ 
#define _GOS_MSGOBJECT_H_ 
 
#define MAKEMSG(pri,cls,index) (((pri)<<24)|((cls)<<16)|(index)) 
#define GetMsgPriority(msg) ((msg)>>24) 
#define GetMsgClass(msg) (((msg)>>16)&0xff) 
#define GetMsgIndex(msg) ((msg)&0xffff) 
#define	IsUniqueMessage(msg) ((msg) & 0x8000) 
#define MakeEventMessage(pri) MAKEMSG(pri,0,0x7ffeL) 
#define IsEventMessage(msg) (((msg) & 0xffffff)==0x007ffe) 
#define MakeTimerMessage(pri) MAKEMSG(pri,0,0x7fff) 
#define IsTimerMessage(msg) (((msg) & 0xffffff)==0x007fff) 
 
enum _tagMsgObject 
{ 
	PriorityNull=0, 
	PriorityRealTime, 
	PriorityTimeCritical=225, 
	PriorityHighest=238, 
	PriorityAboveNormal=239, 
	PriorityNormal=240, 
	PriorityBelowNormal=241, 
	PriorityLowset=242, 
	PriorityIdle=255, 
 
	MsgPriMask=0xFF000000, 
	MsgClassMask=0x00FF0000, 
	MsgNumberMask=0x0000FFFF, 
 
	MsgClassNull=0, 
	MsgClassPower, 
	MsgClassHINT, 
	MsgClassSINT, 
	MsgClassGPIO, 
	MsgClassDPC, 
	MsgClassAPC, 
	MsgClassHAL, 
	MsgClassDriver, 
	MsgClassKernel, 
	MsgClassThread, 
	MsgClassFS, 
	MsgClassService, 
	MsgClassAPP, 
	MsgClassGUI, 
	MsgClassIdle=255, 
 
	msgNull=0, 
	msgSendMessage=MAKEMSG(PriorityHighest,MsgClassNull,1L), 
	msgUser=MAKEMSG(PriorityNormal,MsgClassNull,1L), 
	msgGetMQThread=0xffffFFFB, 
	msgEvent, 
	msgTimer, 
	msgIdle, 
	msgQuit, 
}; 
 
class CMsgObject; 
class CThread; 
 
typedef struct _tagMSG 
{ 
	CMsgObject* pObj; 
    UINT  message; 
    WPARAM wParam; 
    LPARAM lParam; 
}MSG,*PMSG; 
 
class CMsgObject 
{ 
public: 
	virtual LRESULT MsgProc(UINT message, WPARAM wParam, LPARAM lParam); //消息处理函数 
public: 
	CThread* GetMQThread(void) 
		{ return (CThread*)MsgProc(msgGetMQThread,0,0);} 
	LRESULT SendMessage(UINT message, WPARAM wParam, LPARAM lParam); //发送消息 
	HANDLE PostMessage(UINT message, WPARAM wParam, LPARAM lParam); //邮寄消息 
	HANDLE SetMessageEvent(int nPriority); 
	BOOL RemoveMessage(HANDLE hMsg); 
	BOOL RemoveMessage(UINT nMessage); 
	BOOL RemoveAllMessage(); 
	void PulseMessageEvent(HANDLE hMsg,WPARAM wParam, LPARAM lParam); 
	void SetTimer(HANDLE hMsg,UINT nElapse); 
	HANDLE SetTimer(UINT nIDEvent,UINT nElapse,int nPriority=PriorityIdle); 
	BOOL KillTimer(UINT nIDEvent); 
}; 
 
#endif //_GOS_MSGOBJECT_H_