LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Monitor height does not include task bar

Solved!
Go to solution

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 Kudos
Message 1 of 9
(6,075 Views)

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 Kudos
Message 2 of 9
(6,060 Views)

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 Kudos
Message 3 of 9
(6,058 Views)

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 Kudos
Message 4 of 9
(6,054 Views)

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 Kudos
Message 5 of 9
(6,051 Views)

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

 

 

Kevin B.
0 Kudos
Message 6 of 9
(6,050 Views)
Solution
Accepted by TonyG614

Aewsome!  That should work perfectly, thanks!

 

Tony G

0 Kudos
Message 7 of 9
(6,044 Views)

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 Kudos
Message 8 of 9
(6,039 Views)

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 Kudos
Message 9 of 9
(6,035 Views)