【Demo 0035】获取窗体状态

本文详细介绍了GetWindowPlacement API的功能及使用方法,并通过一个代码示例展示了如何获取指定窗口的显示状态及其位置信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本章学习内容非常少就一个API(GetWindowPlacement)

1. 代码演示

//////////////////////////////////////////////////////////////////////////
BOOL CALLBACK WndEnumProc ( HWND hWnd , LPARAM lParam )
{
     HWND hListbox = ( HWND ) lParam ;
     if ( NULL == hWnd )     return FALSE ;

     if ( NULL != hListbox && IsWindow ( hListbox ) && IsWindowVisible ( hWnd ))
     {
         TCHAR szWndInfo [512]    = {0};
         TCHAR szWndTitle [256]    = {0};
         TCHAR szClsName [64]        = {0};
         WINDOWPLACEMENT wp         = {0};
         wp . flags                 = 0;
         wp . length                 = sizeof ( wp );

         RECT rtWnd , rtClient ;
         GetWindowRect ( hWnd , & rtWnd );
         GetClientRect ( hWnd , & rtClient );
         GetWindowText ( hWnd , szWndTitle , 256);
         GetClassName ( hWnd , szClsName , 64);
         GetWindowPlacement ( hWnd , & wp );
         _stprintf ( szWndInfo ,
                   _T ( "\"%s\"" )
                   _T ( "  %d " )
                   _T ( "wnd[%d,%d,%d,%d], client[%d,%d,%d,%d], normal[%d,%d,%d,%d] min[%d, %d] max[%d, %d]" ),
                   szWndTitle ,
                   wp . showCmd ,
                   rtWnd . left , rtWnd . top , rtWnd . right , rtWnd . bottom ,
                   rtClient . left , rtClient . top , rtClient . right , rtClient . bottom ,
                   wp . rcNormalPosition . left , wp . rcNormalPosition . top , wp . rcNormalPosition . right , wp . rcNormalPosition . bottom ,
                   wp . ptMinPosition . x , wp . ptMinPosition . y ,
                   wp . ptMaxPosition . x , wp . ptMaxPosition . y );
         SendMessage ( hListbox , LB_ADDSTRING , 0, ( LPARAM ) szWndInfo );
     }

     return TRUE ;
}

2.  BOOL GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT *lpwndpl )

     功能: 该函数返回指定窗口的显示状态以及被恢复的、最大化的和最小化的窗口位置

typedef struct _WINDOWPLACEMENT {
      UINT length;
      UINT flags;
      UINT showCmd;
      POINT ptMinPosition;
      POINT ptMaxPosition;
      RECT rcNormalPosition;
   } WINDOWPLACEMENT;
返回值说明: 
showCmd – 直接COPY MSDN
        SW_HIDE Hides 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_SHOWNORMAL  演示代码

转载于:https://www.cnblogs.com/ztercel/archive/2011/08/26/2155197.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值