1. 程式人生 > >VC MFC 獲取螢幕大小 程式視窗大小位置 控制元件大小位置

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());