问题虽小,难度很大?MFC 打开系统对话框可以使其居中吗?

一个私有云从业者 2011-12-28 01:46:44
背景: vs2005/2008 MFC 应用程序开发 。C++
开发一个应用程序,在有些功能上发现通过dos 命令调用windows 自带的设置窗口较好。
所以就在应用程序窗口上增加了按钮,通过执行下面的语句 命令打开系统窗口。
	ShellExecute(NULL, NULL, L"desk.cpl", NULL, NULL, SW_SHOW);
//打开windows 自带的系统设置窗口。cmd-> dest.cpl 打开可查看


问题:
发现1、打开的窗口不居中? 我想将其居中且在我的父窗口没关闭的情况下,其始终在桌面的
最前面?

各位高手: 能指导一二吗?

感激。
...全文
183 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-01-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhchongyao 的回复:]
结贴是种文明。总结:上述3楼的方法只针对自己新建的对话框有效,针对windows 自带的对话框不起作用,也许使用钩子等可行,但是现在我还没有找到方法,先结贴。会的人麻烦告诉我下。谢谢
[/Quote]
不会遍历所有窗口或查找指定标题窗口的句柄hWnd吗?
  • 打赏
  • 举报
回复
结贴是种文明。总结:上述3楼的方法只针对自己新建的对话框有效,针对windows 自带的对话框不起作用,也许使用钩子等可行,但是现在我还没有找到方法,先结贴。会的人麻烦告诉我下。谢谢
Gloveing 2011-12-28
  • 打赏
  • 举报
回复
CWnd::CenterWindow
cobra_chen 2011-12-28
  • 打赏
  • 举报
回复
被3楼真相了~~!!
赵4老师 2011-12-28
  • 打赏
  • 举报
回复
MoveWindow
The MoveWindow function changes the position and dimensions of the specified window. For a top-level window, the position and dimensions are relative to the upper-left corner of the screen. For a child window, they are relative to the upper-left corner of the parent window's client area.

BOOL MoveWindow(
HWND hWnd, // handle to window
int X, // horizontal position
int Y, // vertical position
int nWidth, // width
int nHeight, // height
BOOL bRepaint // repaint flag
);

Parameters
hWnd
Handle to the window.
X
Specifies the new position of the left side of the window.
Y
Specifies the new position of the top of the window.
nWidth
Specifies the new width of the window.
nHeight
Specifies the new height of the window.
bRepaint
Specifies whether the window is to be repainted. If this parameter is TRUE, the window receives aWM_PAINT message. If the parameter is FALSE, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of moving a child window. If this parameter is FALSE, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, callGetLastError.

Remarks
If the bRepaint parameter is TRUE, the system sends the WM_PAINT message to the window procedure immediately after moving the window (that is, the MoveWindow function calls the UpdateWindow function). If bRepaint is FALSE, the system places the WM_PAINT message in the message queue associated with the window. The message loop dispatches the WM_PAINT message only after dispatching all other messages in the queue.

MoveWindow sends WM_WINDOWPOSCHANGING, WM_WINDOWPOSCHANGED, WM_MOVE, WM_SIZE, and WM_NCCALCSIZE messages to the window.

vichal 2011-12-28
  • 打赏
  • 举报
回复
貌似Widnows自己打开的时候都不是固定位置的,观望中。。。
  • 打赏
  • 举报
回复
坐等结帖......

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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