1.参数的使用
MB_SYSTEMMODAL 所有窗口的Modal模式,含 WS_EX_TOPMOST 风格(该风格可通过MB_TOPMOST单独设定)
MB_SERVICE_NOTIFICATION 显示在当前桌面,即使没有用户登录(一般用于service 服务)
对话框中messagebox问题
http://community.csdn.net/Expert/topic/3318/3318010.xml?temp=.359234
2.MessageBoxIndirect (一般用于自定义图标)
MSGBOXPARAMS msgBox;
msgBox.cbSize = sizeof(MSGBOXPARAMS);
msgBox.dwStyle = MB_USERICON | nButtons;
msgBox.hInstance = AfxGetApp()->m_hInstance;
msgBox.hwndOwner = NULL;
msgBox.lpszCaption = lpszTitle;
msgBox.lpszIcon = MAKEINTRESOURCE(nResourceID);//资源中的ICON
msgBox.lpszText = lpszText;
MessageBoxIndirect(&msgBox);
如何在MessageBox中使用MB_USERICON属性?
http://community.csdn.net/Expert/topic/4193/4193253.xml?temp=.2414667
3.WH_CBT 钩子 (一般用于设定窗口位置和修改按钮文本)
a)设定窗口的位置(http://support.microsoft.com/default.aspx?scid=kb;en-us;180936)
HHOOK hHook;
LRESULT CALLBACK CBTProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if(nCode == HCBT_ACTIVATE)
{
RECT rect;
GetWindowRect(hWnd, &rect);
MoveWindow((HWND)hWnd, 0, 0, rect.right-rect.left, rect.bottom-rect.top, TRUE);
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
使用方法
hHook = SetWindowsHookEx(WH_CBT, CBTProc, GetModuleHandle(NULL), 0);
MessageBox(NULL, "hello world!", "info", MB_OK);
问题列表:
如何指定MessageBox框的弹出位置 急
http://community.csdn.net/Expert/topic/3695/3695161.xml?temp=.1622888
如何设置MessageBox弹出的位置?
http://community.csdn.net/Expert/topic/3196/3196290.xml?temp=.1177027
MessageBox弹出框的显示位置
http://community.csdn.net/Expert/topic/4035/4035756.xml?temp=.9125635
请问如何改变AfxMessageBox对话框的初始位置?
http://community.csdn.net/Expert/topic/3519/3519806.xml?temp=.5104181
b)修改按钮文本(一般用于国际化)
HHOOK hHook;
LRESULT __stdcall CBTHookProc( long nCode,WPARAM wParam,LPARAM lParam)
{
if (nCode==HCBT_ACTIVATE)
{
SetDlgItemText((HWND)wParam,IDYES,"&Yes");
SetDlgItemText((HWND)wParam,IDNO ,"&No");
SetDlgItemText((HWND)wParam,IDOK,"&OK");
SetDlgItemText((HWND)wParam,IDCANCEL,"&Cancel");
UnhookWindowsHookEx(hHook);
}
return 0;
}
使用方法:
hHook=SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);
问题列表:
messagebox的确定安钮怎么老是中文,如何显示英文
http://community.csdn.net/Expert/topic/4094/4094181.xml?temp=.3754541
P.S. 过一段时间消失的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