MessageBox(),当弹出对话框时,等2秒后让它自动关闭

果菲 2008-08-27 05:20:44
如何实现????
...全文
709 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
ycoder 2008-08-28
  • 打赏
  • 举报
回复
Delay MessageBox with auto-close option
http://www.codeproject.com/KB/dialog/delaymessagebox.aspx
healer_kx 2008-08-28
  • 打赏
  • 举报
回复
最好是自己做,又不是很困难。
HuiChen 2008-08-28
  • 打赏
  • 举报
回复
不错不错!
whp320 2008-08-28
  • 打赏
  • 举报
回复
sleep(2000);
SendMessage(WM_CLOSE);
starytx 2008-08-28
  • 打赏
  • 举报
回复
还是自己做一个比较方便,也好控制,做的像一点就完了
Cricketol 2008-08-28
  • 打赏
  • 举报
回复
支持7楼的做法
用户 昵称 2008-08-28
  • 打赏
  • 举报
回复
最简单的就是自己做
maomaoxiong 2008-08-28
  • 打赏
  • 举报
回复
自己做一个
nevergone 2008-08-27
  • 打赏
  • 举报
回复

/******************************************************************************
Module: TimedMsgBox.cpp
Notices: Copyright (c) 2000 Jeffrey Richter
******************************************************************************/


#include "..\CmnHdr.h" /* See Appendix A. */
#include <tchar.h>


//////////////////////////////////////////////////////////////////////////////


// The caption of our message box
TCHAR g_szCaption[] = TEXT("Timed Message Box");


// How many seconds we'll display the message box
int g_nSecLeft = 0;


// This is STATIC window control ID for a message box
#define ID_MSGBOX_STATIC_TEXT 0x0000ffff


//////////////////////////////////////////////////////////////////////////////


VOID WINAPI MsgBoxTimeout(PVOID pvContext, BOOLEAN fTimeout) {

// NOTE: Due to a thread race condition, it is possible (but very unlikely)
// that the message box will not be created when we get here.
HWND hwnd = FindWindow(NULL, g_szCaption);

if (hwnd != NULL) {
// The window does exist; update the time remaining.
TCHAR sz[100];
wsprintf(sz, TEXT("You have %d seconds to respond"), g_nSecLeft--);
SetDlgItemText(hwnd, ID_MSGBOX_STATIC_TEXT, sz);

if (g_nSecLeft == 0) {
// The time is up; force the message box to exit.
EndDialog(hwnd, IDOK);
}
} else {

// The window does not exist yet; do nothing this time.
// We'll try again in another second.
}
}


//////////////////////////////////////////////////////////////////////////////


int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {

chWindows9xNotAllowed();

// How many seconds we'll give the user to respond
g_nSecLeft = 10;

// Create a multishot 1 second timer that begins firing after 1 second.
HANDLE hTimerQTimer;
CreateTimerQueueTimer(&hTimerQTimer, NULL, MsgBoxTimeout, NULL,
1000, 1000, 0);

// Display the message box
MessageBox(NULL, TEXT("You have 10 seconds to respond"),
g_szCaption, MB_OK);

// Cancel the timer & delete the timer queue
DeleteTimerQueueTimer(NULL, hTimerQTimer, NULL);

// Let us know if the user responded or if we timed-out.
MessageBox(NULL,
(g_nSecLeft == 0) ? TEXT("Timeout") : TEXT("User responded"),
TEXT("Result"), MB_OK);

return(0);
}


//////////////////////////////// End of File /////////////////////////////////


来自windows核心编程的东西
期待你会喜欢:-)
hucailai 2008-08-27
  • 打赏
  • 举报
回复
SetTimer(2000)
OnTimer里
SendMessage(WM_CLOSE)
hjcy_2002 2008-08-27
  • 打赏
  • 举报
回复
做个自己的窗口,或者给系统对话框发退出消息
lijpbasin 2008-08-27
  • 打赏
  • 举报
回复
学习
caimps 2008-08-27
  • 打赏
  • 举报
回复
自定义对话框吧
gaoxiaowei 2008-08-27
  • 打赏
  • 举报
回复
获取窗口句柄,PostQuitMessage()
cnzdgs 2008-08-27
  • 打赏
  • 举报
回复
先SetTimer定时2秒,然后显示MessageBox,在定时程序中,先KillTimer,再用FindWindow查找MessageBox窗口,然后向其发WM_CLOSE消息。
cwc270 2008-08-27
  • 打赏
  • 举报
回复
自己做个提示框吧,然后用它实现比较容易

16,547

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧