From 5dfdb6b58b2dc7bbd3348004c1fcd17e23fea48b Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 28 Jul 2020 00:30:33 +0800 Subject: *embed resource in exe --- src/extern/wog.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'src/extern/wog.c') diff --git a/src/extern/wog.c b/src/extern/wog.c index 4892f99..194f893 100644 --- a/src/extern/wog.c +++ b/src/extern/wog.c @@ -37,9 +37,12 @@ #define min(a, b) (a < b ? a : b) #define clamp(x, minv, maxv) (max(minv, min(x, maxv))) +static HINSTANCE g_hinstance = NULL; + typedef struct wog_Window { HWND hwnd; // Window handler + HINSTANCE hInstance; HDC hdc; // Device Context HDC mdc; // Memory Device Contexts #if WOG_API == WOG_GDI @@ -55,7 +58,6 @@ typedef struct wog_GLContext }wog_GLContext; #endif - // A mouse capture count is used void wog_setMouseCapture(wog_Window* wnd) { @@ -299,10 +301,11 @@ static int registerWindowClass() windowClass.cbSize = sizeof(WNDCLASSEX); // Size Of The windowClass Structure windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraws The Window For Any Movement / Resizing windowClass.lpfnWndProc = (WNDPROC)(WindowProc); // WindowProc Handles Messages - windowClass.hInstance = GetModuleHandle(0); // Set The Instance + windowClass.hInstance = g_hinstance; // Set The Instance windowClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE); // Class Background Brush Color windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer windowClass.lpszClassName = WINDOW_CLASS; // Sets The Applications Classname + windowClass.hIcon = (HICON)LoadIcon(g_hinstance, "icon.ico"); if (RegisterClassEx(&windowClass) == 0) // Did Registering The Class Fail? { @@ -357,6 +360,11 @@ wog_Window* wog_createWindow(const char* title, int width, int height, int x, in { int client_w = width, client_h = height; + if (g_hinstance == NULL) + { + g_hinstance = GetModuleHandle(NULL); + } + if (! registerWindowClass()) { printf("Register window class failed.\n"); @@ -395,6 +403,8 @@ wog_Window* wog_createWindow(const char* title, int width, int height, int x, in wnd ); + wnd->hInstance = g_hinstance; + if (wnd->hwnd == 0) return 0; @@ -625,22 +635,24 @@ int console_main(int argc, char* argv[]) */ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) { - char* temp = GetCommandLine(); - int len = strlen(temp) + 1; - char* cmd = stack_alloc(char, len); - strcpy(cmd, temp); - cmd[len - 1] = '\0'; + g_hinstance = hInst; - int argc = 0; - char** argv = 0; - argc = ParseCommandLine(cmd, 0); - ParseCommandLine(cmd, 0); - argv = stack_alloc(char*, argc + 1); - ParseCommandLine(cmd, argv); + char* temp = GetCommandLine(); + int len = strlen(temp) + 1; + char* cmd = stack_alloc(char, len); + strcpy(cmd, temp); + cmd[len - 1] = '\0'; - int status = console_main(argc, argv); + int argc = 0; + char** argv = 0; + argc = ParseCommandLine(cmd, 0); + ParseCommandLine(cmd, 0); + argv = stack_alloc(char*, argc + 1); + ParseCommandLine(cmd, argv); - return status; + int status = console_main(argc, argv); + + return status; } @@ -714,3 +726,8 @@ void wog_setcursorImage(wog_Window* wnd, Wog_Cursor icon) { SetCursor(icon); } + +HINSTANCE wog_get_instance() +{ + return g_hinstance; +} -- cgit v1.1-26-g67d0