GetWindowRect与GetClientRect

简介: GetWindowRect与GetClientRect

先调用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::GetWindowRectvoid GetWindowRect( LPRECT lpRect ) const;Parameters:lpRectPoints 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 ClientToScreenThe 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);ParametershWnd 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 ValuesIf 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函数进行了重新整理和优化,在获取控件或窗口的屏幕坐标和客户区坐标时更方便的多,只需要得到与控件或窗口相对应屏幕坐标和客户区坐标属性值就可以了。 ScreenToClientThe 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.

相关文章
|
3月前
|
移动开发 安全 前端开发
优化 uniapp 发行操作:一键打包、混淆代码
优化 uniapp 发行操作:一键打包、混淆代码
241 0
|
3月前
uniapp如何安装vant
uniapp如何安装vant
450 1
|
10月前
|
JavaScript 前端开发
vue3瀑布流布局(使用 Vue 3 框架的单文件组件格式(Single-File Component)编写的)
vue3瀑布流布局(使用 Vue 3 框架的单文件组件格式(Single-File Component)编写的)
314 0
|
JavaScript 数据库
uni-app的多环境部署配置
分享下如何对uni-app项目进行多环境打包部署改造
2088 0
|
机器学习/深度学习 传感器 算法
基于matlab模拟鲁棒孤子分布
基于matlab模拟鲁棒孤子分布
|
12月前
|
资源调度 前端开发 JavaScript
vue3 使用axios post方式使用
在Vue3中使用Axios进行POST请求的步骤如下:
560 0
|
3月前
|
开发者 iOS开发
UniApp打包教程:使用HBuilder X和AppUploader完成原生App云打包和上架指南
UniApp打包教程:使用HBuilder X和AppUploader完成原生App云打包和上架指南
149 0
|
3月前
|
小程序 API 数据安全/隐私保护
uniapp中uview的text组件
uniapp中uview的text组件
160 0
|
3月前
|
移动开发 安全 小程序
优化 uniapp 发行操作:一键打包、混淆代码
小程序发行后代码会自动打包到unpackage/dist/build文件中(生产环境)unpackage/dist/dev文件是发行旁边的运行按钮打包出来的文件(开发环境)
|
9月前
|
移动开发 小程序 Java
用uniapp开发跨端应用开发打包发布完整指南
用uni-app开发多端项目,一套代码可同时打包出各端小程序、h5和app,uni-app支持通过 HBuilderX可视化界面 和 vue-cli命令行 两种方式创建项目
514 0