zl程序教程

您现在的位置是:首页 >  其它

当前栏目

MFC中获取任务栏大小

获取 大小 mfc 任务栏
2023-09-11 14:16:46 时间

MFC怎么获得当前屏幕大小

你可以这样
HWND hwnd=GetDesktopWindow();
RECT rect;
GetClientRect(hwnd,&rect);//可以得到桌面大小
还有就是上面所说的
int nScreenWidth, nScreenHeight;
nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

 

 

获得桌面工作区大小,即不包括任务栏的大小,制作窗口全屏时经常用到,方法如下:

 

 
  1. RECT rt;

  2. SystemParametersInfo(SPI_GETWORKAREA,0,(PVOID)&rt,0);


 

 

获得任务栏高度与宽度方法有二:

1.判断位置

 

 
  1. RECT rt;

  2.  
  3. SystemParametersInfo(SPI_GETWORKAREA, 0, &rt, 0) // 获得工作区大小

  4.  
  5. //任务栏在下面的高度

  6.  
  7. int y = ::GetSystemMetrics(SM_CYSCREEN)-rt.Height();

  8.  
  9. //上面

  10.  
  11. int y = rt.top;

  12.  
  13. // 左

  14.  
  15. int y = rt.left;

  16.  
  17. // 右

  18.  
  19. int y = ::GetSystemMetrics(SM_CXSCREEN)-rt.Width();


2.得到高度,然后可判断位置

 

 
  1. CRect rect;

  2.  
  3. CWnd *pWndPrev= FindWindow("Shell_TrayWnd", ""); // 调用本对象即this的Findwindow函数,返回窗口指针

  4.  
  5. pWndPrev->GetWindowRect(&rect);

  6.  
  7. //rect.bottom-rect.top 就是任务栏的高度

  8.  
  9. if(rect.top>0) //下面

  10.  
  11. if(rect.left>0) //左面

  12.  
  13. 或者

  14.  
  15. CWnd* p = NULL ;

  16. HWND hwnd = ::FindWindow("Shell_TrayWnd",NULL) ; // 调用公有的FindWindow函数,返回窗口句柄

  17. if(hwnd)

  18. {

  19. p = CWnd::FromHandle(hwnd) ;

  20. }

  21. p->GetWindowRect();//包含有宽度


 

参考资料:

http://zhoumf1214.blog.163.com/blog/static/5241940201032010451992/