Move WndProc to win32_common.c

This commit is contained in:
twinaphex 2015-11-11 18:26:10 +01:00
parent 8f6deb9dac
commit 3c5f4bd243
3 changed files with 82 additions and 73 deletions

View File

@ -31,6 +31,13 @@
#endif
#ifndef _XBOX
unsigned g_resize_width;
unsigned g_resize_height;
unsigned g_pos_x = CW_USEDEFAULT;
unsigned g_pos_y = CW_USEDEFAULT;
bool g_resized;
bool g_quit;
/* Power Request APIs */
typedef REASON_CONTEXT POWER_REQUEST_CONTEXT, *PPOWER_REQUEST_CONTEXT, *LPPOWER_REQUEST_CONTEXT;
@ -133,7 +140,69 @@ void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id)
GetMonitorInfo(*hm_to_use, (MONITORINFO*)mon);
}
bool win32_window_init(WNDCLASSEX *wndclass, LRESULT CALLBACK WndProc)
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
settings_t *settings = config_get_ptr();
switch (message)
{
case WM_SYSCOMMAND:
/* Prevent screensavers, etc, while running. */
switch (wparam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
return win32_handle_keyboard_event(hwnd, message, wparam, lparam);
case WM_CREATE:
create_gl_context(hwnd);
return 0;
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
{
WINDOWPLACEMENT placement;
GetWindowPlacement(g_hwnd, &placement);
g_pos_x = placement.rcNormalPosition.left;
g_pos_y = placement.rcNormalPosition.top;
g_quit = true;
return 0;
}
case WM_SIZE:
/* Do not send resize message if we minimize. */
if (wparam != SIZE_MAXHIDE && wparam != SIZE_MINIMIZED)
{
g_resize_width = LOWORD(lparam);
g_resize_height = HIWORD(lparam);
g_resized = true;
}
return 0;
case WM_COMMAND:
if (settings->ui.menubar_enable)
{
LRESULT ret = win32_menu_loop(g_hwnd, wparam);
(void)ret;
}
break;
}
if (dinput_handle_message(dinput_wgl, message, wparam, lparam))
return 0;
return DefWindowProc(hwnd, message, wparam, lparam);
}
bool win32_window_init(WNDCLASSEX *wndclass)
{
wndclass->cbSize = sizeof(*wndclass);
wndclass->style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;

View File

@ -35,6 +35,13 @@ extern "C" {
#ifndef _XBOX
#include "../drivers_wm/win32_resource.h"
extern unsigned g_resize_width;
extern unsigned g_resize_height;
extern unsigned g_pos_x;
extern unsigned g_pos_y;
extern bool g_resized;
extern bool g_quit;
LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam);
@ -48,7 +55,9 @@ void win32_monitor_get_info(void);
void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id);
bool win32_window_init(WNDCLASSEX *wndclass, LRESULT CALLBACK WndProc);
bool win32_window_init(WNDCLASSEX *wndclass);
void create_gl_context(HWND hwnd);
#endif
bool win32_suppress_screensaver(void *data, bool enable);

View File

@ -75,16 +75,10 @@ static HDC g_hdc;
static unsigned g_major;
static unsigned g_minor;
static bool g_quit;
bool g_quit;
static bool g_inited;
static unsigned g_interval;
static unsigned g_resize_width;
static unsigned g_resize_height;
static unsigned g_pos_x = CW_USEDEFAULT;
static unsigned g_pos_y = CW_USEDEFAULT;
static bool g_resized;
static dylib_t dll_handle = NULL; /* Handle to OpenGL32.dll */
static bool g_restore_desktop;
@ -111,8 +105,7 @@ static void setup_pixel_format(HDC hdc)
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
}
static void create_gl_context(HWND hwnd)
void create_gl_context(HWND hwnd)
{
bool core_context;
const struct retro_hw_render_callback *hw_render =
@ -243,68 +236,6 @@ bool dinput_handle_message(void *dinput, UINT message, WPARAM wParam, LPARAM lPa
static void *dinput_wgl;
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
settings_t *settings = config_get_ptr();
switch (message)
{
case WM_SYSCOMMAND:
/* Prevent screensavers, etc, while running. */
switch (wparam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_CHAR:
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
case WM_SYSKEYDOWN:
return win32_handle_keyboard_event(hwnd, message, wparam, lparam);
case WM_CREATE:
create_gl_context(hwnd);
return 0;
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
{
WINDOWPLACEMENT placement;
GetWindowPlacement(g_hwnd, &placement);
g_pos_x = placement.rcNormalPosition.left;
g_pos_y = placement.rcNormalPosition.top;
g_quit = true;
return 0;
}
case WM_SIZE:
/* Do not send resize message if we minimize. */
if (wparam != SIZE_MAXHIDE && wparam != SIZE_MINIMIZED)
{
g_resize_width = LOWORD(lparam);
g_resize_height = HIWORD(lparam);
g_resized = true;
}
return 0;
case WM_COMMAND:
if (settings->ui.menubar_enable)
{
LRESULT ret = win32_menu_loop(g_hwnd, wparam);
(void)ret;
}
break;
}
if (dinput_handle_message(dinput_wgl, message, wparam, lparam))
return 0;
return DefWindowProc(hwnd, message, wparam, lparam);
}
static void gfx_ctx_wgl_swap_interval(void *data, unsigned interval)
{
(void)data;