请问如何使Dialog定位在屏幕中央? 1.将Dialog的父窗口设为桌面.2.得到屏幕尺寸再根据比例SetWindowPos. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 好象dialog有个方法不过忘了 :( CDialog dlgdlg.CenterWindow(); 选中DIALOG对话框属性页-》more style->Center属性即可 你也可以取得屏幕的宽高,取得你的DIALOG的宽高,再计算出DIALOG的位置,然后使用MoveWindow。试试看,祝你好运!有空到我的主页去看看。http://shadowsoft.126.com 在调用MessageBox()前,通过安装一个WH_CBT HOOK, 来监视window的create动作,通过WH_CBT HOOK中作为参数得到的HWND,进行你想要的操作. 操作完成后,卸载WH_CBT HOOK. 微软的MFC中,经常可以见到类似的用法, 比如subclass...以下是将调用MessageBox()产生的Dialog居中的例子,不过有些大材小用了.//Set up the CBT hookthreadId = GetCurrentThreadId();hHook = SetWindowsHookEx(WH_CBT, HookProc, NULL,threadId);int bContinue = ::MessageBox(hParent,"Shutdown HTTP Service?", "HTTP Service", MB_YESNO|MB_ICONWARNING);****************************************LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam){ RECT rectMsg,rectForm; if( nCode == HCBT_ACTIVATE ) { int x,y; //Get the coordinates of desktop to //determine where the center of desktop is GetWindowRect( ::GetDesktopWindow(), &rectForm); GetWindowRect((HWND)wParam, &rectMsg); x = (rectForm.left + (rectForm.right - rectForm.left) / 2) - ((rectMsg.right - rectMsg.left) / 2); y = (rectForm.top + (rectForm.bottom - rectForm.top) / 2) - ((rectMsg.bottom - rectMsg.top) / 2); // Position the location of msgbox SetWindowPos( (HWND)wParam, 0, x, y, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE); //Release the CBT hook UnhookWindowsHookEx(hHook); return FALSE; } return CallNextHookEx(hHook,nCode,wParam,lParam);} 我觉得只要在OnInitDialog()函数中调用以下语句就可以了;AfxGetMainWnd()->CenterWindow();如果你要改变窗口的宽高则只要重载BOOL CAboutDlg::PreCreateWindow(CREATESTRUCT& cs) 函数,其中的cs.cx为高, cs.cy为宽 在OnInitDialog()中使用CenterWindow() 把Dialog的父窗口设为NULL或用CenterWindow 考,这么简单还需要hookCDialog::OnMove(int x, int y){int cx,cy,x,y;CRect rtMe;this->GetWindowText(&rtMe);cx=rtMe.Width();cy=rtMe.Height();HWND hDeskWnd=::GetDesktopWindow();CRect rtDesk;::GetClientRect(hDeskWnd,&rtDesk);int m_nScrW=rtDesk.Width();int m_nScrH=rtDesk.Height();x=(m_nScrW-cx)/2;y=(m_nScrH-cy)/2;this->MoveWindow(x,y,cx,cy);} 楼上的xghome(东楼) ,你的方法能将 调用 SDK API函数::MessageBox(...);产生的弹出窗口放到desktop的任意指定位置吗? 再说一点,Dialog默认是在父窗口的中心出现,只要我们的窗口能在屏幕中心不动,以我们为父窗口的所有派生窗口只要是DoModel状态,默认都是在父窗口中心,也就是屏幕中心 请教下UDP通信? 关于“Windows桌面扩展到该显示器”的问题(多显示器的问题),兄弟姐妹们看看 怎么设置按钮的形状为圆角椭圆 请问下怎么实现工具栏的下拉三角箭头呢? 求《Visual C++ 6.0实效编程百例》,收到送分。感谢! 自制Active控件中,自定义的属性如何保存 看下,定义函数的问题 网络序,主机序 请教线程的挂起与恢复问题。 哪里有讲解如何编写email服务器端程序的资料? 在VC中怎样用pragma告诉编译器某个cpp文件在编译的时候不使用pch预编译? 求助:怎么样可以设定CEdit对象在Disable后的字体、颜色(背景、前景)!
不过忘了 :(
dlg.CenterWindow();
试试看,祝你好运!
有空到我的主页去看看。http://shadowsoft.126.com
以下是将调用MessageBox()产生的Dialog居中的例子,不过有些大材小用了.//Set up the CBT hook
threadId = GetCurrentThreadId();
hHook = SetWindowsHookEx(WH_CBT, HookProc, NULL,threadId);int bContinue = ::MessageBox(hParent,"Shutdown HTTP Service?",
"HTTP Service",
MB_YESNO|MB_ICONWARNING);
****************************************
LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
RECT rectMsg,rectForm;
if( nCode == HCBT_ACTIVATE )
{
int x,y;
//Get the coordinates of desktop to
//determine where the center of desktop is
GetWindowRect( ::GetDesktopWindow(), &rectForm); GetWindowRect((HWND)wParam, &rectMsg); x = (rectForm.left + (rectForm.right - rectForm.left) / 2) -
((rectMsg.right - rectMsg.left) / 2);
y = (rectForm.top + (rectForm.bottom - rectForm.top) / 2) -
((rectMsg.bottom - rectMsg.top) / 2); // Position the location of msgbox
SetWindowPos( (HWND)wParam, 0, x, y, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
//Release the CBT hook
UnhookWindowsHookEx(hHook);
return FALSE;
}
return CallNextHookEx(hHook,nCode,wParam,lParam);
}
AfxGetMainWnd()->CenterWindow();
如果你要改变窗口的宽高则只要重载BOOL CAboutDlg::PreCreateWindow(CREATESTRUCT& cs) 函数,
其中的cs.cx为高, cs.cy为宽
中使用CenterWindow()
或用CenterWindow
CDialog::OnMove(int x, int y)
{
int cx,cy,x,y;
CRect rtMe;
this->GetWindowText(&rtMe);
cx=rtMe.Width();
cy=rtMe.Height();
HWND hDeskWnd=::GetDesktopWindow();
CRect rtDesk;
::GetClientRect(hDeskWnd,&rtDesk);
int m_nScrW=rtDesk.Width();
int m_nScrH=rtDesk.Height();
x=(m_nScrW-cx)/2;
y=(m_nScrH-cy)/2;
this->MoveWindow(x,y,cx,cy);}
::MessageBox(...);
产生的弹出窗口放到desktop的任意指定位置吗?