LabWindows/CVI

取消
显示结果 
搜索替代 
您的意思是: 

Monitor height does not include task bar

已解决!
转到解答

I'm trying to implement a full screen window (like viewing a PowerPoint slide show).  I need the actual resolution height of the screen regardless of whether the task bar is present, visible, shown on the top/bottom/left right edge, etc.  My program allows the user to drag the main window to any monitor before invoking the full screen mode, so I need the resolution of the monitor that my main panel is sitting on.  I can get the monitor ID of the main panel and then use GetMonitorAttribute to return the height and width, but the this function returns the "workable" size of the monitor which doesn't include the task bar.

Is there a way to get the actual resolution of a particular monitor?  If not, is there some way to determine if the task bar is visible, what monitor it is on, and how big it is?

 

Tony G

0 项奖励
1 条消息(共 9 条)
6,368 次查看

The easiest way would to just add a fixed number of pixels to the attribute or using a percentage base, although I could not find a good resource as to if this value is fixed.  The other way is to find the Windows dll that contains the screen size, import that into CVI and then calling the Windows function.

 

Thanks,

 

Sean

Applications Engineering Specialist - Semiconductor Test
National Instruments
0 项奖励
2 条消息(共 9 条)
6,353 次查看

Sean,

 

The user can resize the task bar, so it is definately not fixed.  There is a reference in another thread on getting monitor info directly from the system via Win API calls, but those calls are based on the system monitor ID.  Do you know if the monitor ID returned by the GetMonitorFromPanel function is the same ID as the system ID?

 

Tony G

0 项奖励
3 条消息(共 9 条)
6,351 次查看

The monitor ID returned is the monitor number that is displayed in the Windows display settings (usually 1, 2, etc..).

 

Capture.JPG

 

Applications Engineering Specialist - Semiconductor Test
National Instruments
0 项奖励
4 条消息(共 9 条)
6,347 次查看

Interesting.  The other thread I mentioned uses the API function EnumDisplayDevices to get the display info.  According to the MS website the monitor ID number used by this function is zero-based and the first monitor is 0.  I'll have to do some experimenting to determine if the two indices match up with just an off-by-one offset, or if they are totally different.

 

Tony G

0 项奖励
5 条消息(共 9 条)
6,344 次查看

I wrote you a little test program showing how this can be done using the Win32 GetMonitorInfo function.

 

 

Kevin B.
0 项奖励
6 条消息(共 9 条)
6,343 次查看
解答
已被主题作者 TonyG614 接受

Aewsome!  That should work perfectly, thanks!

 

Tony G

0 项奖励
7 条消息(共 9 条)
6,337 次查看

Based on an example from stackoverflow, I was able to create an example for your situation. The only problem with what I have so far is that it only works on the primary monitor. There is an attribute of the DEVMODE fullscreenSettings structure called dmPosition of type POINTL, but I could not figure out what inputs would move it to the other screen. Below is what I have so far:

 

int CVICALLBACK FullScreenCB (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	HWND hwnd;
	int status;
	int width;
	int height;
	HDC windowHDC;
	DWORD fullscreenWidth;
	DWORD fullscreenHeight;
	DWORD colourBits;
	DWORD refreshRate;
	DEVMODE fullscreenSettings;
	int isChangeSuccessful;
	RECT windowBoundary;
	POINTL position;
	switch (event)
	{
		case EVENT_COMMIT:
			hwnd = (HWND) GetCVIWindowHandle ();
			windowHDC = GetDC(hwnd);
			fullscreenWidth  = GetDeviceCaps(windowHDC, HORZRES);
			fullscreenHeight = GetDeviceCaps(windowHDC, VERTRES);
			colourBits       = GetDeviceCaps(windowHDC, BITSPIXEL);
			refreshRate      = GetDeviceCaps(windowHDC, VREFRESH);

			status = SetPanelSize (panelHandle, fullscreenHeight, fullscreenWidth);
			status = SetPanelPos (panelHandle, 0, 0);
			
		    EnumDisplaySettings(NULL, 0, &fullscreenSettings);
		    fullscreenSettings.dmPelsWidth        = fullscreenWidth;
		    fullscreenSettings.dmPelsHeight       = fullscreenHeight;
		    fullscreenSettings.dmBitsPerPel       = colourBits;
		    fullscreenSettings.dmDisplayFrequency = refreshRate;
			fullscreenSettings.dmPosition		  = position;
		    fullscreenSettings.dmFields           = DM_PELSWIDTH |
		                                            DM_PELSHEIGHT |
		                                            DM_BITSPERPEL |
		                                            DM_DISPLAYFREQUENCY;

		    SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
		    SetWindowLongPtr(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
		    isChangeSuccessful = ChangeDisplaySettings(&fullscreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
		    ShowWindow(hwnd, SW_MAXIMIZE);
			
			break;
	}
	return 0;
}

 

Edit: While I was working on this it looks like many more people have posted. Popular topic.

National Instruments
0 项奖励
8 条消息(共 9 条)
6,332 次查看

So I took what Kevin wrote and combined it with what I wrote and came up with a good example. Attached is an example that does expand a UI to fullscreen on all monitors.

National Instruments
0 项奖励
9 条消息(共 9 条)
6,328 次查看