GetWindowRect() 和 GetClientRect() 的区别
生活随笔
收集整理的這篇文章主要介紹了
GetWindowRect() 和 GetClientRect() 的区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
新建一個基于對話框的MFC的exe程序:
刪除對話框的所有按鈕,并添加一個test按鈕,添加一個Static控件,ID為IDC_STATIC:
?
雙擊test按鈕,在響應函數中添加以下代碼:
View Code 1 void CTestMapDlg::OnBtnTest() 2 { 3 // TODO: Add your control notification handler code here 4 CRect rect; 5 CString str; 6 7 CWnd* pStatic = (CWnd*) GetDlgItem(IDC_STATIC); 8 9 pStatic->GetWindowRect(&rect); 10 str.Format("In GetWindowRect: rect.left = %d, rect.top = %d, rect.right = %d, rect.bottom = %d", 11 rect.left, rect.top, rect.right, rect.bottom); 12 MessageBox(str); 13 14 pStatic->ScreenToClient(&rect); 15 str.Format("In GetWindowRect and after ScreenToClient: rect.left = %d, rect.top = %d, rect.right = %d, rect.bottom = %d", 16 rect.left, rect.top, rect.right, rect.bottom); 17 MessageBox(str); 18 19 pStatic->GetClientRect(&rect); 20 str.Format("In GetClientRect: rect.left = %d, rect.top = %d, rect.right = %d, rect.bottom = %d", 21 rect.left, rect.top, rect.right, rect.bottom); MessageBox(str); 22 23 pStatic->ClientToScreen(&rect); 24 str.Format("In GetClientRect and after ClientToScreen: rect.left = %d, rect.top = %d, rect.right = %d, rect.bottom = %d", 25 rect.left, rect.top, rect.right, rect.bottom); 26 MessageBox(str); 27 }?
?
?
?
?
這個顯示的是以屏幕左上角為原點的像素坐標。
說明GetWindowRect(&rect) 得到的矩形坐標是以屏幕左上角的點為原點的坐標。
?
這個顯示的是以TestMap對話框的靜態控件左上角為起點的像素坐標。
說明ScreenToClient(&rect) 能把以屏幕左上角的坐標轉換成以調用該函數對象所關聯的窗口(靜態控件)的左上角的坐標。
?
這個顯示的是以TestMap對話框的靜態控件左上角為起點的像素坐標。
說明GetClientRect(&rect) 得到的坐標等于以
GetWindowRect(&rect)和 ScreenToClient(&rect) 的組合。
PS:僅對于那些沒有邊框的靜態控件。
這個顯示的是以屏幕左上角為原點的像素坐標。
說明GetWindowRect(&rect) 等于
GetClientRect(&rect) 和 ScreenToWindow(&rect) 的組合。
轉載于:https://www.cnblogs.com/chenchenluo/archive/2012/10/08/2715586.html
總結
以上是生活随笔為你收集整理的GetWindowRect() 和 GetClientRect() 的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 连接池的工作原理
- 下一篇: Ubuntu adb devices :