如果获取桌面区域大小,除去任务栏,注意任务栏是否隐藏?
如果获取桌面区域大小,除去任务栏,注意任务栏是否隐藏? 问题点数:100、回复次数:14Top
1 楼pomelowu(羽战士)回复于 2006-03-13 11:34:02 得分 70
SystemParametersInfo,用SPI_GETWORKAREATop
2 楼tufaqing()回复于 2006-03-13 11:41:53 得分 10
桌面区域大小:
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
或
HDC hdcScreen = GetDC( NULL );
int cx = GetDeviceCaps( hdcScreen, HORZRES );
int cy = GetDeviceCaps( hdcScreen, VERTRES );
DeleteObject( hdcScreen );
任务栏:
CWnd* pTaskWnd = FindWindow( _T("Shell_TrayWnd"), NULL );
if( pTaskWnd ) pTaskWnd->ShowWindow( FALSE );
Top
3 楼ljyzc(展翅)回复于 2006-03-13 11:45:21 得分 0
谢谢上面的两位,补充说明,我是在VC6下面,需要获取除去任务栏的屏幕大小,有一办法是获取桌面的大小再减去任务栏的大小,但如果任务栏隐藏了,获取的窗口大小就是错的。Top
4 楼pomelowu(羽战士)回复于 2006-03-13 11:55:40 得分 0
看来你并没有按我说的去尝试啊。Top
5 楼pomelowu(羽战士)回复于 2006-03-13 11:56:08 得分 0
RECT rc;
SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID) &rc, 0);
Top
6 楼ljyzc(展翅)回复于 2006-03-13 11:57:54 得分 0
谢谢你, 我获取来的那个东东是错的啊, 看不见正确的值。Top
7 楼tufaqing()回复于 2006-03-13 12:22:04 得分 0
任务栏是否隐藏:
LONG lStyle = GetWindowLong( pTaskWnd->GetSafeHwnd(), GWL_STYLE );
if( lStyle & WS_VISIBLE )
{
//可见
}
else
{
//隐藏
}Top
8 楼Snow_Ice11111(雪上加冰)回复于 2006-03-13 13:00:04 得分 0
EnumDisplaySettings函数可以。Top
9 楼Mackz(在相互)回复于 2006-03-13 13:03:01 得分 0
羽战士的方法光荣又正确,搂主理解能力怎么样?
SPI_GETWORKAREA Retrieves the size of the work area on the primary display monitor. The work area is the portion of the screen not obscured by the system taskbar or by application desktop toolbars. The pvParam parameter must point to a RECT structure that receives the coordinates of the work area, expressed in virtual screen coordinates.
To get the work area of a monitor other than the primary display monitor, call the GetMonitorInfo function.
Top
10 楼Snow_Ice11111(雪上加冰)回复于 2006-03-13 13:03:55 得分 0
BOOL flag;
LPDEVMODE gpCurrentMode;
gpCurrentMode = new DEVMODE;
flag = EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, gpCurrentMode);
gpCurrentMode->dmFields = DM_BITSPERPEL | DM_PELSWIDTH |
DM_PELSHEIGHT | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY ;
//格式化字符串
m_CurrentColorMode.Format(
"%d",gpCurrentMode->dmBitsPerPel);
m_CurrentDifferency.Format(
"%d * %d",
gpCurrentMode->dmPelsWidth,
gpCurrentMode->dmPelsHeight);
m_CurrentFrequency.Format(
"%d",gpCurrentMode->dmDisplayFrequency);
AfxMessageBox(m_CurrentDifferency); //显示分辨率
AfxMessageBox(m_CurrentColorMode); //色彩位数Top
11 楼Snow_Ice11111(雪上加冰)回复于 2006-03-13 13:10:27 得分 20
不好意思,前面的代码忘了释放指针了,在最后加上:
delete gpCurrentMode;
gpCurrentMode=NULL;Top
12 楼ljyzc(展翅)回复于 2006-03-13 13:12:59 得分 0
TO Mackz(在相互)
我有说他的方法错吗?
可在我的机器上得到的RECT是错的,上下左右都是-858993460,何故?Top
13 楼pomelowu(羽战士)回复于 2006-03-13 13:13:53 得分 0
晕噢。。。我再测了一次,结果正确。Top
14 楼ljyzc(展翅)回复于 2006-03-13 13:21:17 得分 0
谢谢pomelowu(羽战士)
已经OK了。Top




