win32: selectable monitor in wgl context

This commit is contained in:
OV2 2012-10-12 19:39:55 +02:00
parent b80227cf81
commit 1aef7faacb
1 changed files with 19 additions and 2 deletions

View File

@ -28,6 +28,8 @@ static HWND g_hwnd;
static HGLRC g_hrc; static HGLRC g_hrc;
static HDC g_hdc; static HDC g_hdc;
static HMONITOR g_last_hm; static HMONITOR g_last_hm;
static HMONITOR g_all_hms[20];
static unsigned g_num_mons;
static bool g_quit; static bool g_quit;
static bool g_inited; static bool g_inited;
@ -186,6 +188,12 @@ static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
} }
} }
BOOL CALLBACK monitor_enum_proc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
g_all_hms[g_num_mons++] = hMonitor;
return TRUE;
}
static bool gfx_ctx_init(void) static bool gfx_ctx_init(void)
{ {
if (g_inited) if (g_inited)
@ -194,6 +202,9 @@ static bool gfx_ctx_init(void)
g_quit = false; g_quit = false;
g_restore_desktop = false; g_restore_desktop = false;
g_num_mons = 0;
EnumDisplayMonitors(NULL,NULL,monitor_enum_proc,0);
WNDCLASSEX wndclass = {0}; WNDCLASSEX wndclass = {0};
wndclass.cbSize = sizeof(wndclass); wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
@ -236,13 +247,19 @@ static bool gfx_ctx_set_video_mode(
unsigned bits, bool fullscreen) unsigned bits, bool fullscreen)
{ {
(void)bits; (void)bits;
int fs_monitor = 0;
DWORD style; DWORD style;
MONITORINFOEX current_mon = {{0}}; MONITORINFOEX current_mon = {{0}};
current_mon.cbSize = sizeof(MONITORINFOEX); current_mon.cbSize = sizeof(MONITORINFOEX);
if (!g_last_hm) if (!g_last_hm)
g_last_hm = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONEAREST); g_last_hm = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONEAREST);
GetMonitorInfo(g_last_hm, (MONITORINFO*)&current_mon); HMONITOR hm_to_use = g_last_hm;
if(fs_monitor > 0 && fs_monitor <= g_num_mons && g_all_hms[fs_monitor - 1])
hm_to_use = g_all_hms[fs_monitor - 1];
GetMonitorInfo(hm_to_use, (MONITORINFO*)&current_mon);
g_resize_width = width; g_resize_width = width;
g_resize_height = height; g_resize_height = height;
@ -264,7 +281,7 @@ static bool gfx_ctx_set_video_mode(
goto error; goto error;
// display settings might have changed, get new coordinates // display settings might have changed, get new coordinates
GetMonitorInfo(g_last_hm, (MONITORINFO*)&current_mon); GetMonitorInfo(hm_to_use, (MONITORINFO*)&current_mon);
g_restore_desktop = true; g_restore_desktop = true;
} }
} }