設置windows程序客戶區大小(個人感覺很好用以後就直接拿來用得了)



void SetClientSize(HWND hWnd,int width, int height)
{

  if(!hWnd)

  {

     MessageBox(NULL, "設置窗口失敗", NULL, 1);

     exit(1);

  }
  RECT  rectProgram,rectClient;
  GetWindowRect(hWnd, &rectProgram);   //獲得程序窗口位於屏幕座標
  GetClientRect(hWnd, &rectClient);      //獲得客戶區座標
  //非客戶區寬,高
  int nWidth = rectProgram.right - rectProgram.left -(rectClient.right - rectClient.left); 
  int nHeiht = rectProgram.bottom - rectProgram.top -(rectClient.bottom - rectClient.top); 
  nWidth += width;
  nHeiht += height;
  rectProgram.right =  nWidth;
  rectProgram.bottom =  nHeiht;
  int showToScreenx = GetSystemMetrics(SM_CXSCREEN)/2-nWidth/2;    //居中處理
  int showToScreeny = GetSystemMetrics(SM_CYSCREEN)/2-nHeiht/2;
  MoveWindow(hWnd, showToScreenx, showToScreeny, rectProgram.right, rectProgram.bottom, false);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章