VC MFC 獲取屏幕大小 程序窗口大小位置 控件大小位置

//下邊兩個函數獲取的是顯示屏幕的大小,但不包括任務欄等區域
int cx = GetSystemMetrics(SM_CXFULLSCREEN);
int cy = GetSystemMetrics(SM_CYFULLSCREEN);

printf("屏幕大小(不含任務欄):寬:%d,高:%d \r\n",  cx,cy);



//下邊這兩個函數獲取的是真正屏幕的大小:屏幕分辨率
int nWidth = GetSystemMetrics(SM_CXSCREEN);  //屏幕寬度    
int nHeight = GetSystemMetrics(SM_CYSCREEN); //屏幕高度

printf("屏幕大小:寬:%d,高:%d \r\n", nWidth,nHeight);



//對話框窗體大小及其屏幕座標
CRect rectDlg;
//GetClientRect(rectDlg);//獲得窗體的大小 //法1:
GetWindowRect(rectDlg);//獲得窗體在屏幕上的位置 //法2:
ScreenToClient(rectDlg);

printf("窗口位置大小:底:%d, 右:%d, 寬:%d, 高:%d\r\n", rectDlg.bottom, rectDlg.right, rectDlg.Width(), rectDlg.Height());



//控件大小和位置
CRect rectCtrl;
CStatic *p = (CStatic*)GetDlgItem(IDC_VIDEOSHOW1);
//p->MoveWindow(100, 100, 100, 100);//更改控件大小並移動其到指定位置
p->GetWindowRect(rectCtrl);
this->ScreenToClient(rectCtrl);
//GetDlgItem(IDC_STATIC_TEST)->GetClientRect(rectCtrl);

printf("控件位置大小:左:%d, 頂:%d, 寬:%d, 高:%d\r\n", rectCtrl.left, rectCtrl.top, rectCtrl.Width(), rectCtrl.Height());


發佈了13 篇原創文章 · 獲贊 9 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章