• <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>

            GetWindowRect() || GetClientRect()||ScreenToClient()||ClientToScreen

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

            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() 得到的是在屏幕坐標系下的RECT;(即以屏幕左上角為原點
            GetClientRect() 得到的是在客戶區坐標系下的RECT; (即以所在窗口左上角為原點

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

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

            ScreenToClient() 就是把屏幕坐標系下的RECT坐標轉換為客戶區坐標系下的RECT坐標。

             

            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得到的是客戶區的大小,也就是說這樣得到的左上角永遠是(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 是窗口相對于整個屏幕的坐標,屏幕左上點為0,0

            相互轉化用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.


            雖然存在調用GetWindowRect后再調用ScreenToClient==GetClientRect,但ScreenToClient()和ClientToScreen()兩者都是屬于WINDOWS API函數,可能是存在一定的冗余設計,但意義不同。
            不過在.Net Framework下對WINDOWS API函數進行了重新整理和優化,在獲取控件或窗口的屏幕坐標和客戶區坐標時更方便的多,只需要得到與控件或窗口相對應屏幕坐標和客戶區坐標屬性值就可以了

            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.

            posted on 2011-04-01 11:30 wrh 閱讀(959) 評論(1)  編輯 收藏 引用

            評論

            # re: GetWindowRect() || GetClientRect()||ScreenToClient()||ClientToScreen 2011-04-26 12:46 寧波停車棚

            這些東西好像我都沒怎么接觸過,呵呵不懂。  回復  更多評論   

            導航

            <2008年11月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            統計

            常用鏈接

            留言簿(19)

            隨筆檔案

            文章檔案

            收藏夾

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲精品乱码久久久久久| 国产精品欧美久久久天天影视| 99国内精品久久久久久久| 国产精品久久国产精麻豆99网站| 久久超乳爆乳中文字幕| 亚洲午夜精品久久久久久人妖| 久久99精品国产麻豆蜜芽| 欧美亚洲国产精品久久久久| 亚洲精品无码久久一线| 亚洲综合久久综合激情久久 | 九九99精品久久久久久| 久久久久久久综合日本亚洲| 国产高潮久久免费观看| 久久久久久免费视频| AAA级久久久精品无码片| 久久久久这里只有精品 | 久久精品麻豆日日躁夜夜躁| 久久se精品一区精品二区国产| 久久福利资源国产精品999| 久久99精品国产99久久| 97久久国产综合精品女不卡| 国产精品狼人久久久久影院| 中文精品久久久久人妻不卡| 久久人人爽人人澡人人高潮AV| 伊人久久综合成人网| 精品国产乱码久久久久软件| 香港aa三级久久三级| avtt天堂网久久精品| 色欲综合久久躁天天躁蜜桃| 亚洲国产成人久久一区久久| 久久久久99精品成人片牛牛影视| 国产精品18久久久久久vr| 亚洲国产精品无码久久98| 精品国产乱码久久久久久呢| 久久久久一级精品亚洲国产成人综合AV区| 91视频国产91久久久| 国内精品久久久久久99| 韩国无遮挡三级久久| 日本道色综合久久影院| 久久久亚洲精品蜜桃臀| 亚洲一级Av无码毛片久久精品|