10-27-2011 02:27 PM
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
Solved! Go to Solution.
10-28-2011 04:43 PM
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
10-28-2011 04:47 PM
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
10-28-2011 05:02 PM
The monitor ID returned is the monitor number that is displayed in the Windows display settings (usually 1, 2, etc..).
10-28-2011 05:08 PM
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
10-28-2011 05:09 PM
I wrote you a little test program showing how this can be done using the Win32 GetMonitorInfo function.
10-28-2011 05:14 PM
Aewsome! That should work perfectly, thanks!
Tony G
10-28-2011 05:21 PM - edited 10-28-2011 05:22 PM
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.
10-28-2011 05:51 PM
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.