📄 msgmgr.h
字号:
/*
* Openmysee
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#pragma once
typedef UINT MSGID;
class CMsgMgr
{
public:
CMsgMgr(void);
virtual ~CMsgMgr(void);
///这个类型中的数据定义了消息性质的各位意义
/*
消息性质的位格式(UINT)
0 ... 0 0 0 0 0 0 0 0
4 3 2 1 timeout
1: TIMELESS 一个没有生命期的消息,如果该位为0,则其后4位指定了消息的生存时间,分别表示0-15秒
2: FORCESHOW 需要强制用户了解的消息,一条消息的flags被更新为FORCESHOW后,在下一次dispatchmessage时就会被重置为0
3: WAIT 表示是一个等待过程中返回的消息
*/
enum MESSAGETYPE
{
TIMELESS = 0x10,
FORCESHOW = 0x20,
WAIT = 0x40,
FORCEHIDE = 0x80,
NOUPDATE = 0xFFFFFFFF
};
enum MESSAGELEVEL
{
MSGLV_TRIVAL,
MSGLV_NOTIFY,
MSGLV_WARNING,
MSGLV_FATAL
};
protected:
typedef struct _MSGDATA
{
UINT MsgFlags;
CString strMsg;
BOOL b_visited; //消息是否已经被getmessage所取出过?
DWORD m_updated_tickcount; //消息上次被updated的时间(tickcount)
MESSAGELEVEL m_msgLevel; //msg的等级,将一条高等级的消息更新成一条低等级的消息的行为将不会成功
} MSGDATA;
public:
MSGID CreateMsgID(UINT MsgFlags = 0);
void DeleteMsgID(MSGID MsgID);
UINT GetMsgNum();
void GetMsgIDArray(MSGID *pMsgIDArray);
void UpdateMessage(MSGID MsgID, const CString &strNewMsg, UINT msgFlags = NOUPDATE, MESSAGELEVEL msglv = MSGLV_NOTIFY);
void ClearMessage(MSGID MsgID);
///
/*
从消息ID获得消息字串。通过传入合适的flags来限制获得消息
Return
如果根据getflags的限制能成功获取消息,返回TRUE,并修改strMsg为消息字串,否则返回FALSE。此时strMsg未定义
Remark
默认情况下,该函数修改对应的MSGDATA对象:将MSGTYPE的FORCESHOW去掉,并将b_visited置为TRUE。这保证了一条消息被多次
取出时,FORCESHOW(导致汽泡提示弹出)的情况最多只有一次
*/
enum GETMESSAGEFLAGS
{
GMF_NOPP = 0,
GMF_NOOLDMSG = 0x1, //不获取旧的(已经被访问过的)消息
GMF_NOVISITEDFLAG = 0x100, //不对MSGDATA的b_visited进行标记
GMF_NOCLEANFORCEFLAG = 0x200 //不对MSGDATA的FORCESHOW或者FORCEHIDE属性进行清除动作
};
BOOL DispatchMessage(const MSGID MsgID, CString& strMsg,
const UINT getflags = GMF_NOPP, UINT* p_bMsgFlags = NULL);
///
/*
这一函数相当于调用GetMessageEx并使用GMF_NOVISITEDFLAG和GMF_NOCLEANFORCESHOW标志
*/
const CString PeerMessage(MSGID MsgID);
protected:
BOOL IsMsgExpired(MSGDATA& msg);
typedef std::map<MSGID, MSGDATA> MsgMap;
MsgMap m_MsgMap;
CCritSec m_CritSec;
UINT m_uMsgCounter;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -