X-Git-Url: https://gitweb.ps.run/autorec/blobdiff_plain/8d2244aefe172b5b1e15a32ad23991945d128f3a..2986e5896e745a6b49160f682569e0f9976034bf:/src/win.h diff --git a/src/win.h b/src/win.h index 65f2595..167e162 100644 --- a/src/win.h +++ b/src/win.h @@ -5,6 +5,8 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include #include +#include "../res/resource.h" + #include "layout.h" #include @@ -14,46 +16,24 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") using std::string; namespace win { -struct Length -{ - int pixel; - float percent; -}; -struct Size -{ - Length x, y, w, h; - int getX(HWND hwnd) - { - RECT rect; - GetClientRect(hwnd, &rect); - return x.percent * (rect.right - rect.left) + x.pixel; - } - int getY(HWND hwnd) - { - RECT rect; - GetClientRect(hwnd, &rect); - return y.percent * (rect.bottom - rect.top) + y.pixel; - } - int getW(HWND hwnd) - { - RECT rect; - GetClientRect(hwnd, &rect); - return w.percent * (rect.right - rect.left) + w.pixel; - } - int getH(HWND hwnd, int _w, int _h) - { - RECT rect; - GetWindowRect(hwnd, &rect); - return h.percent * (rect.bottom - rect.top) + h.pixel; - } -}; - namespace _ { using CallbackFn = std::function; std::map> handlers; std::map lIds; NOTIFYICONDATA niData = { 0 }; +void +ShowNotificationIcon() +{ + Shell_NotifyIconA(NIM_ADD, &_::niData); + Shell_NotifyIconA(NIM_SETVERSION, &_::niData); +} + +void +HideNotificationIcon() +{ + Shell_NotifyIconA(NIM_DELETE, &_::niData); +} lay_context ctx; lay_id root; @@ -72,9 +52,8 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) break; case WM_SIZE: if (wParam == SIZE_MINIMIZED) { + ShowNotificationIcon(); ShowWindow(hwnd, false); - SetForegroundWindow(hwnd); - SetActiveWindow(hwnd); } else { lay_set_size_xy(&_::ctx, _::root, LOWORD(lParam), HIWORD(lParam)); @@ -105,8 +84,12 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_NOTIFY: break; case WM_APP + 1: - if (LOWORD(lParam) == NIN_SELECT) + if (LOWORD(lParam) == NIN_SELECT) { + HideNotificationIcon(); ShowWindow(hwnd, true); + SetForegroundWindow(hwnd); + SetActiveWindow(hwnd); + } break; case WM_CTLCOLORSTATIC: return (LONG)GetStockObject(WHITE_BRUSH); @@ -123,20 +106,6 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } } -void -ShowNotificationIcon(HINSTANCE hInstance, HWND hwnd) -{ - _::niData.cbSize = sizeof(_::niData); - _::niData.uID = 12345; - _::niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; - _::niData.hIcon = LoadIconA(nullptr, IDI_WINLOGO); - _::niData.hWnd = hwnd; - _::niData.uCallbackMessage = WM_APP+1; - _::niData.uVersion = NOTIFYICON_VERSION_4; - - Shell_NotifyIconA(NIM_ADD, &_::niData); - Shell_NotifyIconA(NIM_SETVERSION, &_::niData); -} void Callback(HWND hwnd, WORD ev, std::function cb) @@ -165,9 +134,8 @@ Window(string title, string className, HINSTANCE hInstance) lay_init_context(&_::ctx); _::root = lay_item(&_::ctx); lay_set_contain(&_::ctx, _::root, LAY_COLUMN); - lay_set_margins_ltrb(&_::ctx, _::root, 5, 5, 5, 5); - return CreateWindowA(className.c_str(), + HWND result = CreateWindowA(className.c_str(), title.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, @@ -178,6 +146,16 @@ Window(string title, string className, HINSTANCE hInstance) nullptr, hInstance, nullptr); + + _::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 = result; + _::niData.uCallbackMessage = WM_APP+1; + _::niData.uVersion = NOTIFYICON_VERSION_4; + + return result; } bool @@ -288,6 +266,28 @@ void ListRemove(HWND hwnd, int index) SendMessageA(hwnd, LB_DELETESTRING, index, 0); } +HWND +ListView(HWND hwnd, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave) +{ + lay_id lId = lay_item(&_::ctx); + lay_insert(&_::ctx, parent, lId); + lay_set_size_xy(&_::ctx, lId, w, h); + lay_set_contain(&_::ctx, lId, contain); + lay_set_behave(&_::ctx, lId, behave); + + HWND result = CreateWindowExA(0, + WC_LISTVIEWA, + "", + WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL, + 0, 0, 0, 0, + hwnd, + nullptr, + nullptr, + nullptr); + _::lIds[result] = lId; + return result; +} + HWND CheckBox(HWND hwnd, string title, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave) {