设置windows程序客户区大小(个人感觉很好用以后就直接拿来用得了)
发布日期:2022-03-03 10:44:02 浏览次数:11 分类:技术文章

本文共 746 字,大约阅读时间需要 2 分钟。



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

转载地址:https://blog.csdn.net/yangjie6898862/article/details/34859897 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:设计一个只能在堆上或栈上实例化的类
下一篇:矩阵-DirectX与OpenGL的不同

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月06日 12时36分56秒