# HG changeset patch # User John Tsiombikas # Date 1309166354 -10800 # Node ID e4c79d2c7f789e4df67f1fce2c082d015e68e685 # Parent 0eb6abc43ac616475fef78f5b847a5e240dfed66 finishing win32 module diff -r 0eb6abc43ac6 -r e4c79d2c7f78 src/wsys_w32.c --- a/src/wsys_w32.c Mon Jun 27 12:05:51 2011 +0300 +++ b/src/wsys_w32.c Mon Jun 27 12:19:14 2011 +0300 @@ -34,6 +34,7 @@ /* window management */ static int set_active(int id); static struct window *find_window(int id); +static struct window *find_window_handle(HWND wh); static int activate_window(struct window *win); static int set_title(const char *str); static void redisplay(void); @@ -49,6 +50,7 @@ static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static int mouse_button(unsigned int msg); +static void calc_win_size(int w, int h, int *width, int *height, int *posx, int *posy); static struct wsys_module ws = { @@ -258,7 +260,20 @@ struct window *win = winlist; while(win) { - if(win->win == id) { + if(win->id == id) { + return win; + } + win = win->next; + } + return 0; +} + +static struct window *find_window_handle(HWND wh) +{ + struct window *win = winlist; + + while(win) { + if(win->win == wh) { return win; } win = win->next; @@ -423,6 +438,41 @@ return -1; } +static void calc_win_size(int w, int h, int *width, int *height, int *posx, int *posy) +{ + RECT rect; + DEVMODE dmode; + unsigned int style = WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_POPUP | WS_SYSMENU | WS_VISIBLE; + + rect.left = rect.top = 0; + rect.right = w; + rect.bottom = h; + + AdjustWindowRect(&rect, style, 0); + + *width = rect.right - rect.left; + *height = rect.bottom - rect.top; + + *posx = *posy = 0; + + memset(&dmode, 0, sizeof dmode); + dmode.dmSize = sizeof dmode; + + if(EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dmode)) { + int x, y; + + x = (dmode.dmPelsWidth - *width) / 2; + if(x > 0) { + *posx = x; + } + + y = (dmode.dmPelsHeight - *height) / 2; + if(y > 0) { + *posy = y; + } + } +} + #else int sgl_wsys_w32_silence_the_fucking_empty_file_warnings; #endif