• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 34, comments - 0, trackbacks - 0, articles - 1
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            GetWindowRect與GetClientRect的區(qū)別

            Posted on 2012-02-13 20:01 polly 閱讀(481) 評論(0)  編輯 收藏 引用 所屬分類: VC++學(xué)習(xí)

            先調(diào)用GetWindowRect后再調(diào)用ScreenToClient,這個(gè)時(shí)候得到的rect和直接使用GetClientRect得到的值是相等的。有時(shí)候需要獲得窗口矩形的大小和客戶區(qū)矩形的大小二者的值,故需要分別調(diào)用GetWindowRect和GetClientRect。如果只需要獲得客戶區(qū)矩形的大小,調(diào)用GetClientRect就行了。GetWindowRect和GetClientRect函數(shù)的說明如下:

            CWnd::GetClientRect  
                void GetClientRect( LPRECT lpRect ) const;
            Parameters:
            lpRect
                Points to a RECT structure or a CRect object to receive the client coordinates. The left and top members will be 0. The right and bottom members will contain the width and height of the window.
            Remarks:
                Copies the client coordinates of the CWnd client area into the structure pointed to by lpRect. The client coordinates specify the upper-left and lower-right corners of the client area. Since client coordinates are relative to the upper-left corners of the CWnd client area, the coordinates of the upper-left corner are (0,0).

            CWnd::GetWindowRect
            void GetWindowRect( LPRECT lpRect ) const;
            Parameters:
            lpRect
            Points to a CRect object or a RECT structure that will receive the screen coordinates of the upper-left and lower-right corners.
            Remarks:
            Copies the dimensions of the bounding rectangle of the CWnd object to the structure pointed to by lpRect. The dimensions are given in screen coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.

            GetWindowRect() 得到的是在屏幕坐標(biāo)系下的RECT;(即以屏幕左上角為原點(diǎn)
            GetClientRect() 得到的是在客戶區(qū)坐標(biāo)系下的RECT; (即以所在窗口左上角為原點(diǎn)

            GetWindowRect()取的是整個(gè)窗口的矩形;
            GetClientRect()取的僅是客戶區(qū)的矩形,也就是說不包括標(biāo)題欄,外框等;

            第一個(gè)函數(shù)獲得的是窗口在屏幕上的位置,得到的結(jié)果可能是這樣CRect(10,10,240,240);
            第二個(gè)函數(shù)和它不同,它只獲得了客戶區(qū)的大小,因此得到的結(jié)果總是這樣CRect(0,0,width,height);

            ScreenToClient() 就是把屏幕坐標(biāo)系下的RECT坐標(biāo)轉(zhuǎn)換為客戶區(qū)坐標(biāo)系下的RECT坐標(biāo)。

            The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).

            GetClientRect得到的是客戶區(qū)的大小,也就是說這樣得到的左上角永遠(yuǎn)是(0,0)

            The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.

            GetWindowRect 是窗口相對于整個(gè)屏幕的坐標(biāo),屏幕左上點(diǎn)為0,0

            相互轉(zhuǎn)化用ScreenToClient 或者 ClientToScreen

            ClientToScreen
            The ClientToScreen function converts the client coordinates of a specified point to screen coordinates.
            BOOL ClientToScreen(
               HWND hWnd,        // window handle for source coordinates
               LPPOINT lpPoint   // pointer to structure containing screen coordinates
            );

            Parameters
            hWnd
            Handle to the window whose client area is used for the conversion.
            lpPoint
            Pointer to a POINT structure that contains the client coordinates to be converted. The new screen coordinates are copied into this structure if the function succeeds.
            Return Values
            If the function succeeds, the return value is nonzero.
            If the function fails, the return value is zero.
            雖然存在調(diào)用GetWindowRect后再調(diào)用ScreenToClient==GetClientRect,但ScreenToClient()和ClientToScreen()兩者都是屬于WINDOWS API函數(shù),可能是存在一定的冗余設(shè)計(jì),但意義不同。
            不過在.Net Framework下對WINDOWS API函數(shù)進(jìn)行了重新整理和優(yōu)化,在獲取控件或窗口的屏幕坐標(biāo)和客戶區(qū)坐標(biāo)時(shí)更方便的多,只需要得到與控件或窗口相對應(yīng)屏幕坐標(biāo)和客戶區(qū)坐標(biāo)屬性值就可以了

            ScreenToClient
            The ScreenToClient function converts the screen coordinates of a specified point on the screen to client coordinates.
            BOOL ScreenToClient(
               HWND hWnd,         // window handle for source coordinates
               LPPOINT lpPoint    // address of structure containing coordinates
            );
            Parameters:
            hWnd
            Handle to the window whose client area will be used for the conversion.
            lpPoint
            Pointer to a POINT structure that contains the screen coordinates to be converted.
            Return Values:
            If the function succeeds, the return value is nonzero.
            If the function fails, the return value is zero.
            国内精品欧美久久精品| 久久久久久无码Av成人影院| 国产精品99久久不卡| 久久久久久国产精品美女| 亚洲国产成人久久综合野外| 国产成人久久精品一区二区三区| 久久亚洲AV成人无码国产 | 久久久WWW成人免费毛片| 思思久久精品在热线热| 99久久无色码中文字幕| 久久国产精品无| 久久91精品国产91久久小草| 午夜视频久久久久一区| 国产精品美女久久久久| 国产A三级久久精品| 精品乱码久久久久久夜夜嗨| 久久亚洲精品成人av无码网站| 久久精品成人影院| 国产精品久久久久久久久免费| 青春久久| 久久性生大片免费观看性| 精品国产一区二区三区久久久狼| 亚洲午夜精品久久久久久浪潮| 亚洲AV无码一区东京热久久| 色综合久久88色综合天天 | 色综合久久久久| 狠狠色丁香婷婷综合久久来| 亚洲愉拍99热成人精品热久久 | 性高湖久久久久久久久AAAAA| 久久精品国产一区| 久久久91精品国产一区二区三区| 久久A级毛片免费观看| 久久亚洲美女精品国产精品| 婷婷综合久久中文字幕蜜桃三电影| 久久亚洲2019中文字幕| 亚洲精品无码久久毛片| 一本色道久久88综合日韩精品| 亚洲欧美另类日本久久国产真实乱对白| 精品久久久久久久中文字幕| 国产亚州精品女人久久久久久| 伊人色综合久久|