设置MessageBox的位置? [英] Set location of MessageBox?
本文介绍了设置MessageBox的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用MessageBox(或类似的东西)打印一条消息。我也想要控制在屏幕上的确切的框出现,但可以找到没有什么在MessageBox的允许您控制位置的描述。我错过了什么吗?如果MessageBox不能使用,那么是否有另一种方法?
I want to print out a message using MessageBox (or similar). I would also like control over where exactly on the screen the box appears but can find nothing in the description of MessageBox that allows you control over the location. Did I miss something? If MessageBox can not be used, then is there an alternative?
由于太复杂而不能进入这里的原因,我更喜欢一个不涉及自己并传递回调函数的地址。
For reasons too complex to go into here, I would prefer an answer which didn't involve making my own window and passing the address of a callback function.
推荐答案
步骤1:陷阱创建消息框:
// global hook procedure
HHOOK hhookCBTProc = 0;
LRESULT CALLBACK pfnCBTMsgBoxHook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_CREATEWND)
{
CREATESTRUCT *pcs = ((CBT_CREATEWND *)lParam)->lpcs;
if ((pcs->style & WS_DLGFRAME) || (pcs->style & WS_POPUP))
{
HWND hwnd = (HWND)wParam;
// At this point you have the hwnd of the newly created
// message box that so you can position it at will
SetWindowPos(hwnd, ...);
}
}
return (CallNextHookEx(hhookCBTProc, nCode, wParam, lParam));
}
步骤2:然后显示消息框:
// set hook to center the message box that follows
hhookCBTProc = SetWindowsHookEx(WH_CBT,
pfnCBTMsgBoxHook,
0, GetCurrentThreadId());
int sResult = MessageBox(hwndParent, pszMsg, pszTitle, usStyle);
// remove the hook
UnhookWindowsHookEx(hhookCBTProc);
这篇关于设置MessageBox的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文