VC對話方塊大小和位置設定
阿新 • • 發佈:2019-01-02
軟體開發中,我們通常需要設定對話方塊到我們需要的大小,並且希望能在我們希望的位置顯示,那麼就需要設定對話方塊的大小和位置了。
步驟:
1.新建對話方塊
新建對話方塊應用程式,為了方便對比,我們還另外新建兩個對話方塊。2.設定對話方塊大小和位置
為了方便對比,一個對話方塊使用預設效果,另一個對話方塊重寫OnInitDialog函式。預設效果 設定後效果BOOL CDialog2::OnInitDialog() { CDialog::OnInitDialog(); //對話方塊背景圖片寬和高 const int nBkBmpWidth = 480; const int nBkBmpHeight = 300; int xPos = 0; int yPos = 0; //獲得電腦顯示器的畫素寬度和畫素高度 int ax = GetDC()->GetDeviceCaps(HORZRES) - nBkBmpWidth; int ay = GetDC()->GetDeviceCaps(VERTRES) - nBkBmpHeight; int nWidth = 0; int nHeight = 0; if(ax <= 0) { ax = 0; } else { ax = ax/2; } if(ay <= 0) { ay = 0; } else { ay = ay/2; } RECT clientRect; RECT rt; clientRect.left = ax; clientRect.top = ay; clientRect.right = clientRect.left + nBkBmpWidth; clientRect.bottom = clientRect.top + nBkBmpHeight; MoveWindow(&clientRect); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
原始碼下載