+ -
当前位置:首页 → 问答吧 → 问题虽小,难度很大?MFC 打开系统对话框可以使其居中吗?

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

时间:2011-12-28

来源:互联网

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



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

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

作者: zhchongyao   发布时间: 2011-12-28

坐等结帖......

作者: zhchongyao   发布时间: 2011-12-28

貌似Widnows自己打开的时候都不是固定位置的,观望中。。。

作者: vichal   发布时间: 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. 

Specifies the new position of the left side of the window. 

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. 

作者: zhao4zhong1   发布时间: 2011-12-28

被3楼真相了~~!!

作者: cobra_chen   发布时间: 2011-12-28