Sign in to follow this  
dimensionX

Win32 Fullscreen mode + Multi-monitor configuration

Recommended Posts

I already did this code.... here is a snippet


struct tMONINFO
{
unsigned int count;
HMONITOR hmonitor;
RECT * rectptr;
char name[CCHDEVICENAME];

};

BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
tMONINFO * memptr = (tMONINFO *)dwData;

memptr->count --;

if (memptr->count)
{
return TRUE;

}
else
{
memptr->hmonitor = hMonitor;

MoveMemory(memptr->rectptr, lprcMonitor, sizeof(RECT));

MONITORINFOEX monitorinfoex;

monitorinfoex.cbSize = sizeof(MONITORINFOEX);

if (!GetMonitorInfo(hMonitor, &monitorinfoex))
{
goto error;

}

MoveMemory(memptr->name, monitorinfoex.szDevice, sizeof(char) * CCHDEVICENAME);

return TRUE;

}

error:

return FALSE;

}



WINGDIAPI void APIENTRY glwCreate (char * title, GLuint width, GLuint height, GLubyte bpp, GLuint screen)
{
// rest of function

RECT windowrect;
DWORD style;
tMONINFO monitorinfo;
HDC mdc;
bool changescreen;
DEVMODE devmode;
MONITORINFOEX monitorinfoex;
int screenwidth;
int screenheight;
HWND hwnd;

if (screen)
{
style = WS_POPUP;

// get hold of monitor information

monitorinfo.hmonitor = 0;
monitorinfo.count = screen;
monitorinfo.rectptr = &windowrect;

if (!EnumDisplayMonitors(0, 0, MonitorEnumProc, (LPARAM)&monitorinfo))
{
goto error;

}

if (!monitorinfo.hmonitor)
{
goto error;

}

// check the monitor against our width and height values

mdc = CreateDC(monitorinfo.name, monitorinfo.name, 0, 0);

if (!mdc)
{
goto error;

}

changescreen = (GetDeviceCaps(mdc, HORZRES) != width) || (GetDeviceCaps(mdc, VERTRES) != height);

DeleteDC(mdc);

// if width or height are different to current, change the screen settings

if (changescreen)
{
// change screen settings

ZeroMemory(&devmode, sizeof(DEVMODE));

devmode.dmSize = sizeof(DEVMODE);
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
devmode.dmBitsPerPel = bpp;
devmode.dmPelsWidth = width;
devmode.dmPelsHeight = height;

if (ChangeDisplaySettingsEx(monitorinfo.name, &devmode, 0, CDS_FULLSCREEN, 0) != DISP_CHANGE_SUCCESSFUL)
{
goto error;

}

}

// re-get information about the monitor we are using, incase it changed above

monitorinfoex.cbSize = sizeof(MONITORINFOEX);

if (!GetMonitorInfo(monitorinfo.hmonitor, &monitorinfoex))
{
goto error;

}

windowrect.left = monitorinfoex.rcMonitor.left;
windowrect.top = monitorinfoex.rcMonitor.top;
windowrect.right = width;
windowrect.bottom = height;

}
else // windowed mode
{
style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU;

// get the width and height of the frame around the window

windowrect.left = 0;
windowrect.top = 0;
windowrect.right = width;
windowrect.bottom = height;

if (!AdjustWindowRectEx(&windowrect, style, FALSE, 0))
{
goto error;

}

// centre position of whole window

screenwidth = GetSystemMetrics(SM_CXSCREEN);
screenheight = GetSystemMetrics(SM_CYSCREEN);

windowrect.right -= windowrect.left;
windowrect.bottom -= windowrect.top;
windowrect.left = (screenwidth - windowrect.right) / 2;
windowrect.top = (screenheight - windowrect.bottom) / 2;

}

hwnd = CreateWindowEx(0, CLASSNAME, title, style | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, windowrect.left, windowrect.top, windowrect.right, windowrect.bottom, GetDesktopWindow(), 0, hinstance, 0);

// rest of function

}

Copyright (c) 2005 ZedFx, license: http://www.gnu.org/copyleft/gpl.html, hahahha!



Sort out all the obvious things such as getting a hinstance and registering the window class and then you can use it! (my code was very different from usual for these bits so I decided not to include it.)

Share this post


Link to post
Share on other sites
Forgot to say, if you supply Zero in the screen argument, it will create a window on the Primary monitor. Otherwise, screen references the index of the screen (ie. 1, 2, 3 = 1st monitor, 2nd monitor, 3rd monitor ... etc)

enjoy.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by ZedFx
Forgot to say, if you supply Zero in the screen argument, it will create a window on the Primary monitor. Otherwise, screen references the index of the screen (ie. 1, 2, 3 = 1st monitor, 2nd monitor, 3rd monitor ... etc)

enjoy.


What will happen if I create a window on each monitor using size of window as the resolution of the screen and WS_POPUP ? Their locations being according to the monitor locations in the Virtual screen.

Share this post


Link to post
Share on other sites
.. Read the code and figure it out... ;-)

The monitors will automatically figure themselves out as regards positioning (ie, none will overlap etc). However, monitors MUST have windows created on them in chronological order, otherwise the screens can overlap etc. The following section of the code will work out where on the virtual screen the windows should go..


// re-get information about the monitor we are using, incase it changed above

monitorinfoex.cbSize = sizeof(MONITORINFOEX);

if (!GetMonitorInfo(monitorinfo.hmonitor, &monitorinfoex))
{
goto error;

}

windowrect.left = monitorinfoex.rcMonitor.left;
windowrect.top = monitorinfoex.rcMonitor.top;
windowrect.right = width;
windowrect.bottom = height;



but you would have known that had you read the comment in the code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this