有关程序最小化后的消息提示的问题

skyrakehell 2005-08-15 11:55:42
制作一个仿msn消息提示程序,但是当程序最小化时,消息框不能显示出来,只能在任务栏中出现,需要点击任务栏中的标题才能显示出来,请问大家有没有什么办法可使程序在最小化时,能正常show出提示框出来,
该提示程序源代码如下

#define ID_TIMER_POP_WINDOW 10
#define ID_TIMER_CLOSE_WINDOW 11
#define ID_TIMER_DISPLAY_DELAY 12
#define WIN_WIDTH 181
#define WIN_HEIGHT 116
// CMsgWnd

CMsgWnd::CMsgWnd()
{
m_Bitmap.LoadBitmap(MAKEINTRESOURCE(IDB_SHOWMSG)); //Load Bitmap
m_Bitmap.GetBitmap(&bmBitmap); //Get Bitmap Info
m_bFlag=false;
m_strMessage="消息提示";
m_strCaption="提示文字";
}

void CMsgWnd::CreateMsgWindow()
{ CreateEx(0,
AfxRegisterWndClass(
0,
::LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_HAND_1)),(HBRUSH)(COLOR_DESKTOP+1),NULL),
"",
WS_POPUP|WS_EX_TOPMOST|WS_TABSTOP,
0,
0,
0,//bmBitmap.bmWidth, //Bitmap Width = Splash Window Width
0,//bmBitmap.bmHeight, //Bitmap Height = Splash Window Height
NULL,//AfxGetMainWnd()->GetSafeHwnd(),
NULL,
NULL);
SetTimer(ID_TIMER_POP_WINDOW,2,NULL);
}
void CMsgWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC dcMemory;
CRect rect;
GetClientRect(&rect);
dcMemory.CreateCompatibleDC(NULL);
dcMemory.SelectObject(&m_Bitmap);
dc.StretchBlt(0,
0,
rect.right-rect.left,//bmBitmap.bmWidth,
rect.bottom-rect.top,//bmBitmap.bmHeight,
&dcMemory,
0,
0,
bmBitmap.bmWidth,
bmBitmap.bmHeight,
SRCCOPY);
CFont font;
font.CreatePointFont(90,"Impact");
dc.SelectObject(&font);
dc.SetTextColor(RGB(0,64,128));
dc.SetBkMode(TRANSPARENT);
dc.TextOut(30,10,m_strCaption);
rect.top=30;
dc.DrawText(m_strMessage,-1,&rect,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
// Do not call CWnd::OnPaint() for painting messages
}
void CMsgWnd::OnTimer(UINT nIDEvent)
{
static int nHeight=0;
int cy=GetSystemMetrics(SM_CYSCREEN);
int cx=GetSystemMetrics(SM_CXSCREEN);
RECT rect;
SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
int y=rect.bottom-rect.top;
int x=rect.right-rect.left;
x=x-WIN_WIDTH;

switch(nIDEvent)
{
case ID_TIMER_POP_WINDOW:
if(nHeight<=WIN_HEIGHT)
{
++nHeight; //连续增加两次,以加快上声速度
++nHeight;
++nHeight;
++nHeight;
MoveWindow(x,
y-nHeight,
WIN_WIDTH,
WIN_HEIGHT);

Invalidate(FALSE);
}
else
{
KillTimer(ID_TIMER_POP_WINDOW);
SetTimer(ID_TIMER_DISPLAY_DELAY,5000,NULL);
}
break;
case ID_TIMER_CLOSE_WINDOW:
if(nHeight>=0)
{
nHeight--; //连续递减两次,以加快下降速度
nHeight--;
MoveWindow(x,
y-nHeight,
WIN_WIDTH,
nHeight);
}
else
{
KillTimer(ID_TIMER_CLOSE_WINDOW);
SendMessage(WM_CLOSE);
}
break;
case ID_TIMER_DISPLAY_DELAY:
KillTimer(ID_TIMER_DISPLAY_DELAY);
SetTimer(ID_TIMER_CLOSE_WINDOW,2,NULL);
break;
}

CWnd::OnTimer(nIDEvent);
}

int CMsgWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
AnimateWindow(GetSafeHwnd(),1000,AW_CENTER|AW_VER_NEGATIVE);
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
BringWindowToTop();
return 0;
}
void CMsgWnd::OnKillFocus(CWnd* pNewWnd)
{
CWnd::OnKillFocus(pNewWnd);
if(m_bFlag)
SetTimer(ID_TIMER_DISPLAY_DELAY,3000,NULL);
// TODO: Add your message handler code here

}
恳请大侠帮忙提供方法解决,
小弟感激不尽!

...全文
83 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
调用SetForegroundWindow
回复
skyrakehell 2005-08-15
嗯,情况有所改善了,但是不知道为什么,如果当前开了别的程序,而且是最大化时候就显示不出来,
而当前程序没有最大化则可以显示出来,请问要该如何解决?
回复
hyg2008 2005-08-15
mark
回复
skyrakehell 2005-08-15
谢谢,我试试看!
回复
发帖
界面
创建于2007-09-28

1.5w+

社区成员

VC/MFC 界面
申请成为版主
帖子事件
创建了帖子
2005-08-15 11:55
社区公告
暂无公告