OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include <windows.h> |
| 9 #include <tchar.h> |
| 10 |
| 11 #include "SkTypes.h" |
| 12 #include "Window_win.h" |
| 13 #include "../Application.h" |
| 14 |
| 15 static char* tchar_to_utf8(const TCHAR* str) { |
| 16 #ifdef _UNICODE |
| 17 int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL,
NULL); |
| 18 char* str8 = (char*)sk_malloc_throw(size + 1); |
| 19 WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL); |
| 20 str8[size] = '\0'; |
| 21 return str8; |
| 22 #else |
| 23 return _strdup(str); |
| 24 #endif |
| 25 } |
| 26 |
| 27 // This file can work with GUI or CONSOLE subsystem types since we define _tWinM
ain and main(). |
| 28 |
| 29 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv); |
| 30 |
| 31 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
dLine, |
| 32 int nCmdShow) { |
| 33 |
| 34 // convert from lpCmdLine to argc, argv. |
| 35 char* argv[4096]; |
| 36 int argc = 0; |
| 37 TCHAR exename[1024], *next; |
| 38 int exenameLen = GetModuleFileName(NULL, exename, SK_ARRAY_COUNT(exename)); |
| 39 // we're ignoring the possibility that the exe name exceeds the exename buff
er |
| 40 (void)exenameLen; |
| 41 argv[argc++] = tchar_to_utf8(exename); |
| 42 TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next); |
| 43 while (arg != NULL) { |
| 44 argv[argc++] = tchar_to_utf8(arg); |
| 45 arg = _tcstok_s(NULL, _T(" "), &next); |
| 46 } |
| 47 int result = main_common(hInstance, nCmdShow, argc, argv); |
| 48 for (int i = 0; i < argc; ++i) { |
| 49 sk_free(argv[i]); |
| 50 } |
| 51 return result; |
| 52 } |
| 53 |
| 54 int main(int argc, char**argv) { |
| 55 return main_common(GetModuleHandle(NULL), SW_SHOW, argc, argv); |
| 56 } |
| 57 |
| 58 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv) { |
| 59 |
| 60 Application* app = Application::Create(argc, argv, (void*)hInstance); |
| 61 |
| 62 MSG msg = { 0 }; |
| 63 // Main message loop |
| 64 while (WM_QUIT != msg.message) { |
| 65 if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { |
| 66 TranslateMessage(&msg); |
| 67 DispatchMessage(&msg); |
| 68 } |
| 69 |
| 70 app->onIdle(0.0f); |
| 71 } |
| 72 |
| 73 delete app; |
| 74 |
| 75 return (int)msg.wParam; |
| 76 } |
OLD | NEW |