X-Git-Url: https://gitweb.ps.run/autorec/blobdiff_plain/e00ad6704b8538b1a553960531af7b50d367fe73..20b46fb7ea34b0241a40f7565a9db8c0656da01e:/src/win.h diff --git a/src/win.h b/src/win.h index 1e761b6..0a734c9 100644 --- a/src/win.h +++ b/src/win.h @@ -1,7 +1,3 @@ -#pragma comment(linker, "\"/manifestdependency:type='win32' \ -name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ -processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") - #include #include @@ -42,11 +38,14 @@ namespace win { SetWindowLongPtrA(hwnd, GWL_STYLE, getStyle() & (~style)); } + void setActive(bool active) + { + EnableWindow(hwnd, active); + } }; struct Window : Hwnd { private: - NOTIFYICONDATAA niData = { 0 }; static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -62,17 +61,11 @@ namespace win DestroyWindow(hwnd); break; case WM_DESTROY: - Shell_NotifyIconA(NIM_DELETE, &window->niData); lay_destroy_context(&window->ctx); PostQuitMessage(0); break; case WM_SIZE: - if (wParam == SIZE_MINIMIZED) { - //TODO: auslagen - //ShowNotificationIcon(); - ShowWindow(hwnd, false); - } - else { + if (wParam != SIZE_MINIMIZED) { lay_set_size_xy(&window->ctx, window->lId, LOWORD(lParam), HIWORD(lParam)); lay_run_context(&window->ctx); @@ -81,23 +74,8 @@ namespace win break; case WM_NOTIFY: break; - case WM_APP + 1: - if (LOWORD(lParam) == NIN_SELECT) { - //TODO: auslagern - //HideNotificationIcon(); - ShowWindow(hwnd, true); - SetForegroundWindow(hwnd); - SetActiveWindow(hwnd); - } - break; case WM_CTLCOLORSTATIC: - return (LONG)GetStockObject(WHITE_BRUSH); - case WM_GETMINMAXINFO: { - MINMAXINFO *mmInfo = (MINMAXINFO*)lParam; - mmInfo->ptMinTrackSize.x = 400; - mmInfo->ptMinTrackSize.y = 200; - break; - } + return (LONG_PTR)GetStockObject(WHITE_BRUSH); default: defaultHandler = true; break; @@ -117,6 +95,12 @@ namespace win std::vector< std::function>> handlers; + struct Timer { + bool active = true; + std::function f; + }; + std::vector timers; + Window(std::string title, std::string className, HINSTANCE hInstance) { WNDCLASSEXA wc; @@ -126,12 +110,12 @@ namespace win wc.cbClsExtra = 0; wc.cbWndExtra = sizeof(Window*); wc.hInstance = hInstance; - wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION); - wc.hCursor = LoadCursor(nullptr, IDC_ARROW); + wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_WHITE)); + wc.hCursor = LoadCursor(hInstance, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszMenuName = nullptr; wc.lpszClassName = className.c_str(); - wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION); + wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON_WHITE)); RegisterClassExA(&wc); lay_init_context(&ctx); @@ -151,15 +135,6 @@ namespace win nullptr); SetWindowLongPtrA(hwnd, 0, (LONG_PTR)this); - - - niData.cbSize = sizeof(niData); - niData.uID = 12345; - niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; - niData.hIcon = LoadIconA(hInstance, MAKEINTRESOURCEA(IDI_MY_ICON)); - niData.hWnd = hwnd; - niData.uCallbackMessage = WM_APP+1; - niData.uVersion = NOTIFYICON_VERSION_4; } bool update() { @@ -174,7 +149,9 @@ namespace win void show() { ShowWindow(hwnd, true); - + } + void setDefaultFont() + { EnumChildWindows( hwnd, [](HWND hwnd, LPARAM lParam) -> BOOL { @@ -184,6 +161,19 @@ namespace win }, 0); } + void setTimer(UINT interval, std::function cb) + { + SetTimer(this->hwnd, timers.size() + 1000, interval, [](HWND hwnd, UINT uMsg, UINT_PTR uIdEvent, DWORD dwTime) { + Window *window = (Window*)GetWindowLongPtrA(hwnd, 0); + if (window == nullptr) + return; + + window->timers[uIdEvent-1000].f(); + }); + Timer t; + t.f = cb; + timers.push_back(t); + } }; struct Button : Hwnd