SetWindowPos

SetWindowPos
昨天写了MoveWindow函数,今天又要写SetWindowPos函数,因为MoveWindow确实不好,浪费了差不多一天时间。。。对于主窗口,选择了Center属性就可以移动位置,不选就不行;窗口资源过大也不能移动;改变后窗口的尺寸大于等于屏幕尺寸的话,在它上面DoModal出来的新窗口不能移动。。原来,使用MoveWindow移动对话框位置似乎有很苛刻的条件,一不小心就原地不动了,而且我也实在琢磨不透这样的条件,网上也没有查处来。今天用了SetWindowPos后,才发现,果然好用!

BOOL SetWindowPos(
   
const  CWnd *  pWndInsertAfter,
   
int  x,
   
int  y,
   
int  cx,
   
int  cy,
   UINT nFlags 
);

Parameters

pWndInsertAfter
Identifies the CWnd object that will precede this CWnd object in the Z-order. This parameter can be a pointer to a CWnd or a Pointer to one of the following values:
  • wndBottom   Places the window at the bottom of the Z-order. If this CWnd is a topmost window, the window loses its topmost status; the system places the window at the bottom of all other windows.
  • wndTop   Places the window at the top of the Z-order.
  • wndTopMost   Places the window above all nontopmost windows. The window maintains its topmost position even when it is deactivated.
  • wndNoTopMost   Repositions the window to the top of all nontopmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a nontopmost window.
nFlags
Specifies sizing and positioning options. This parameter can be a combination of the following: 常用的是 SWP_SHOWWINDOW

注意:
    这里的坐标参数用的是Client坐标,对于子窗口用的是其父窗口的坐标系。然而对于用DoModal()弹出的窗口,如果在资源属性里没有选择Child属性的话,它的父窗口是DeskTop,而不是调用DoModal()的窗口。

你可能感兴趣的:(SetWindowPos)