您的位置:首页 > 其它

SetWindowPlacement和WINDOWPLACEMENT

2016-02-23 00:14 351 查看
SetWindowPlacement()函数讲解:

函数功能:该函数设置指定窗口的显示状态和恢复,最大化,最小化位置。

  函及原型;BOOL SetWindowPlacement(HWND hWnd,CONST WINDOWPLACEMENT★lpwndpl);

  参数:

  1、hWnd:窗口句柄。

  2、lpwndpl:指向一个WINDOWPLACEMWNT结构的指针,该结构给出了新的显示状态和窗口位置。

  在调用函数SetWindowPlacement之前,将WINDOWPLACEMWNT结构的长度单元置为sizeof(WINDOWPLACEMENT)。如果lpwndpl->length设置不正确,函数SetWindowPlacement将失败。

  返回值:如果函数成功,返回值为非零。如果函数失败,返回值为零。若想获得更多错误信息,请调用callGetLastErro函数。

  备注:如果在WIDNOWPLACEMENT中指定的信息使窗口完全显示在屏幕之外,系统自动调整坐标以使窗口可见,兼顾屏幕设置和多种监视器配置。

  WINDOWPLACEMENT的长度成员信息设置为sizeof(WINDOWPLACEMENT),如果设置不正确,函数将返回FLASE

WINDOWPLACEMENT 结构:

typedef struct _WINDOWPLACEMENT {

UINT length;

UINT flags;

UINT showCmd;

POINT ptMinPosition;

POINT ptMaxPosition;

RECT rcNormalPosition;

} WINDOWPLACEMENT;

length : 设置为 sizeof(WINDOWPLACEMENT) ,否则将调用失败

flags : 指定窗口最小化时的位置

showCmd:指定当前窗口状态 具体值可查看MSDN

ptMinPosition :指定窗口最小化时的左上角坐标

ptMaxPosition :指定窗口最大化时的左上角坐标

rcNormalPosition :指定窗口恢复时的窗口坐标

Members:来源于MSDN

lengthSpecifies the length, in bytes, of the structure. Before calling the GetWindowPlacement or SetWindowPlacement functions, set this member to sizeof(WINDOWPLACEMENT).
GetWindowPlacement andSetWindowPlacement fail if this member is not set correctly.

flagsSpecifies flags that control the position of the minimized window and the method by which the window is restored. This member can be one or more of the following values.
WPF_ASYNCWINDOWPLACEMENTWindows 2000/XP: If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents
the calling thread from blocking its execution while other threads process the request.WPF_RESTORETOMAXIMIZEDSpecifies that the restored window will be maximized, regardless of whether it was maximized before it was minimized. This setting is only valid the next time the window is restored. It does not change the
default restoration behavior.
This flag is only valid when theSW_SHOWMINIMIZED value is specified for the
showCmd member.

WPF_SETMINPOSITIONSpecifies that the coordinates of the minimized window may be specified.
This flag must be specified if the coordinates are set in theptMinPosition member.

showCmdSpecifies the current show state of the window. This member can be one of the following values.
SW_HIDEHides the window and activates another window.SW_MAXIMIZEMaximizes the specified window.SW_MINIMIZEMinimizes the specified window and activates the next top-level window in the z-order.SW_RESTOREActivates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.SW_SHOWActivates the window and displays it in its current size and position.SW_SHOWMAXIMIZEDActivates the window and displays it as a maximized window.SW_SHOWMINIMIZEDActivates the window and displays it as a minimized window.SW_SHOWMINNOACTIVEDisplays the window as a minimized window.
This value is similar to
SW_SHOWMINIMIZED, except the window is not activated.

SW_SHOWNADisplays the window in its current size and position.
This value is similar to
SW_SHOW, except the window is not activated.

SW_SHOWNOACTIVATEDisplays a window in its most recent size and position.
This value is similar to
SW_SHOWNORMAL, except the window is not actived.

SW_SHOWNORMALActivates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the
first time.
ptMinPositionSpecifies the coordinates of the window's upper-left corner when the window is minimized.ptMaxPositionSpecifies the coordinates of the window's upper-left corner when the window is maximized.rcNormalPositionSpecifies the window's coordinates when the window is in the restored position.

实例:

WINDOWPLACEMENT wndpl;

wndpl.length=sizeof(WINDOWPLACEMENT);

wndpl.flags=0;

wndpl.showCmd=SW_SHOWNORMAL;

wndpl.rcNormalPosition=m_FullScreenRect;

pFrame->SetWindowPlacement(&wndpl);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: