类似360消息弹出框,实现方式一见http://blog.csdn.net/segen_jaa/article/details/7848598。
本文采用另外的API实现渐入渐出效果。
主要API:SetLayeredWindowAttributes。
实现功能:
采用管理器控制消息框每次只显示一个。
消息框独立显示在右下角,不随主窗口放大缩小变化。
鼠标进入消息框区域,渐入渐出效果停止。
1、消息框实现
创建对话框类CMsgTipDlg,设置对话框属性。
Tool Window:true。设置对话框为消息框,任务栏上将没有图标。
Topmost:true。设置对话框置顶。
MsgTipDlg.h。
#pragma once
// CMsgTipDlg dialog
class CMsgTipMng;
class CMsgTipDlg : public CDialog
{
DECLARE_DYNAMIC(CMsgTipDlg)
public:
CMsgTipDlg(CMsgTipMng* pTipMng, const CString& strTipInfo, CWnd* pParent = NULL); // standard constructor
virtual ~CMsgTipDlg();
// Dialog Data
enum { IDD = IDD_MCMSG_DLG };
void ShowMsgWindow();
int GetTipID() const
{
return m_nTipID;
}
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL OnInitDialog();
virtual void OnCancel();
virtual void PostNcDestroy();
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnBnClickedOk();
afx_msg void OnBnClickedCancel();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP()
private:
void InitDlgPosition();
private:
CMsgTipMng* m_pTipMng;
CString m_strTipInfo;
int m_nTipID;
BYTE m_bAlpha;//淡入淡出透明效果
};
MsgTipDlg.cpp。
// MCMsgTipDlg.cpp : implementation file
//
#include "stdafx.h"