如果用MessageBox()发出消息!会不会使程序暂停?

windforce1210 2012-02-14 12:14:57
用MessageBox()发出消息,是否会使程序中断在这里等待用户点击确定再继续运行?如果会,有没有别的弹出消息框的方式,可以在弹出消息的同时,不影响程序继续向下运行?谢谢
...全文
686 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
孙郎 2013-11-28
  • 打赏
  • 举报
回复
不好意思,挖个坟,这个最后怎么解决的啊
hankcs 2012-02-14
  • 打赏
  • 举报
回复
这个号[Quote=引用 5 楼 jennyvenus 的回复:]
带超时功能的MessageBox吧


C/C++ code
1)
http://www.codeproject.com/KB/dialog/delaymessagebox.aspx

2)
http://www.codeproject.com/KB/dialog/AutoCloseMessageBox.aspx

3)
过一段时间消失的MessageBox(源自MSDN)
……
[/Quote]
wyangwo 2012-02-14
  • 打赏
  • 举报
回复
会的,之前写了一个多线程的程序,没用MessageBox函数,程序运行一段时间就死了,用了MessageBox后,弹出对话框,点了确定后,程序一直都能存活运行下去
Ginie 2012-02-14
  • 打赏
  • 举报
回复
是会暂停
向立天 2012-02-14
  • 打赏
  • 举报
回复
没有
除非自己做一个非模态的对话框
xiaoguailong3 2012-02-14
  • 打赏
  • 举报
回复
会暂停
用户 昵称 2012-02-14
  • 打赏
  • 举报
回复
带超时功能的MessageBox吧

1)
http://www.codeproject.com/KB/dialog/delaymessagebox.aspx

2)
http://www.codeproject.com/KB/dialog/AutoCloseMessageBox.aspx

3)
过一段时间消失的MessageBox(源自MSDN)
void CALLBACK MessageBoxTimer(HWND hwnd, UINT uiMsg, UINT idEvent, DWORD dwTime)
{
PostQuitMessage(0);
}
UINT TimedMessageBox(HWND hwndParent, LPCTSTR ptszMessage, LPCTSTR ptszTitle, UINT flags, DWORD dwTimeout)
{
MSG msg;
UINT idTimer = SetTimer(NULL, 0, dwTimeout, (TIMERPROC)MessageBoxTimer);
UINT uiResult = MessageBox(hwndParent, ptszMessage, ptszTitle, flags);
KillTimer(NULL, idTimer);
if (PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE)) {
uiResult = 0;//默认值
}
return uiResult;
}
使用方法同MessageBox,只是多了个DWORD参数 dwTimeout

4)微软以前未公开的函数

#include <windows.h>
#include <tchar.h>

//Functions & other definitions required-->
typedef int (__stdcall *MSGBOXAAPI)(IN HWND hWnd,
IN LPCSTR lpText, IN LPCSTR lpCaption,
IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);
typedef int (__stdcall *MSGBOXWAPI)(IN HWND hWnd,
IN LPCWSTR lpText, IN LPCWSTR lpCaption,
IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);

int MessageBoxTimeoutA(IN HWND hWnd, IN LPCSTR lpText,
IN LPCSTR lpCaption, IN UINT uType,
IN WORD wLanguageId, IN DWORD dwMilliseconds);
int MessageBoxTimeoutW(IN HWND hWnd, IN LPCWSTR lpText,
IN LPCWSTR lpCaption, IN UINT uType,
IN WORD wLanguageId, IN DWORD dwMilliseconds);

#ifdef UNICODE
#define MessageBoxTimeout MessageBoxTimeoutW
#else
#define MessageBoxTimeout MessageBoxTimeoutA
#endif

#define MB_TIMEDOUT 32000

int MessageBoxTimeoutA(HWND hWnd, LPCSTR lpText,
LPCSTR lpCaption, UINT uType, WORD wLanguageId,
DWORD dwMilliseconds)
{
static MSGBOXAAPI MsgBoxTOA = NULL;

if (!MsgBoxTOA)
{
HMODULE hUser32 = GetModuleHandle(_T("user32.dll"));
if (hUser32)
{
MsgBoxTOA = (MSGBOXAAPI)GetProcAddress(hUser32,
"MessageBoxTimeoutA");
//fall through to 'if (MsgBoxTOA)...'
}
else
{
//stuff happened, add code to handle it here
//(possibly just call MessageBox())
return 0;
}
}

if (MsgBoxTOA)
{
return MsgBoxTOA(hWnd, lpText, lpCaption,
uType, wLanguageId, dwMilliseconds);
}

return 0;
}

int MessageBoxTimeoutW(HWND hWnd, LPCWSTR lpText,
LPCWSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds)
{
static MSGBOXWAPI MsgBoxTOW = NULL;

if (!MsgBoxTOW)
{
HMODULE hUser32 = GetModuleHandle(_T("user32.dll"));
if (hUser32)
{
MsgBoxTOW = (MSGBOXWAPI)GetProcAddress(hUser32,
"MessageBoxTimeoutW");
//fall through to 'if (MsgBoxTOW)...'
}
else
{
//stuff happened, add code to handle it here
//(possibly just call MessageBox())
return 0;
}
}

if (MsgBoxTOW)
{
return MsgBoxTOW(hWnd, lpText, lpCaption,
uType, wLanguageId, dwMilliseconds);
}

return 0;
}
//End required definitions <--Call the function as follows:

//you must load user32.dll before calling the function
HMODULE hUser32 = LoadLibrary(_T("user32.dll"));

if (hUser32)
{
int iRet = 0;
UINT uiFlags = MB_OK|MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_ICONINFORMATION;

iRet = MessageBoxTimeout(NULL, _T("Test a timeout of 2 seconds."),
_T("MessageBoxTimeout Test"), uiFlags, 0, 2000);
//iRet will = 1

uiFlags = MB_YESNO|MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_ICONINFORMATION;

iRet = MessageBoxTimeout(NULL, _T("Test a timeout of 5 seconds."),
_T("MessageBoxTimeout Test"), uiFlags, 0, 5000);
//iRet will = MB_TIMEDOUT if no buttons pressed, button values otherwise

//only unload user32.dll when you have no further need
//for the MessageBoxTimeout function
FreeLibrary(hUser32);
}
MagicFuzzX 2012-02-14
  • 打赏
  • 举报
回复
MessageBoxTimeout
jiuzhoulh 2012-02-14
  • 打赏
  • 举报
回复
你还可以创建一个线程来处理弹出对话框
oldmtn 2012-02-14
  • 打赏
  • 举报
回复
你设断点啊。。
雪山青木 2012-02-14
  • 打赏
  • 举报
回复
可以自己创建一个对话框,非模态显示,Create然后ShowWindow

16,548

社区成员

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

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

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