VC 定时 messagebox 消息框

 HWND g_hwndTimedOwner = 0; 
 BOOL g_bTimedOut = 0; 
void CALLBACK MessageBoxTimer(HWND hwnd,  
UINT uiMsg,  
UINT idEvent,  
DWORD dwTime) 

g_bTimedOut = TRUE; 
if (g_hwndTimedOwner) 
EnableWindow(g_hwndTimedOwner, TRUE); 
PostQuitMessage(0); 

int TimedMessageBox(HWND hwndOwner, 
LPCTSTR pszMessage, 
LPCTSTR pszTitle, 
UINT flags, 
DWORD dwTimeout) 


UINT idTimer; 
int iResult; 


g_hwndTimedOwner = NULL; 
g_bTimedOut = FALSE; 


if (hwndOwner && IsWindowEnabled(hwndOwner)) 
g_hwndTimedOwner = hwndOwner; 


// Set a timer to dismiss the message box. 
idTimer = SetTimer(NULL, 0, dwTimeout, (TIMERPROC)MessageBoxTimer); 


iResult = MessageBox(hwndOwner, pszMessage, pszTitle, flags); 


// Finished with the timer. 
KillTimer(NULL, idTimer); 


// See if there is a WM_QUIT message in the queue if we timed out. 
// Eat the message so we do not quit the whole application. 
if (g_bTimedOut) 

MSG msg; 
PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); 
iResult = -1; 



return iResult; 



用法:

TimedMessageBox( theApp.m_pMainWnd->m_hWnd,   CString("设置2000毫秒显示,然后自动关闭"),  _T("消息框标题"), MB_OK, 2000 );



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值