treesummaryrefslogcommitdiff
path: root/src/win.h
diff options
context:
space:
mode:
authorPatrick Schönberger2022-01-09 21:31:23 +0100
committerPatrick Schönberger2022-01-09 21:31:23 +0100
commite90fc8a9809127820252a09dd7bfbbbc7a6f295d (patch)
tree8927270177c1f0b467f31d5039d08ccc07958a6e /src/win.h
parent8d2244aefe172b5b1e15a32ad23991945d128f3a (diff)
downloadautorec-e90fc8a9809127820252a09dd7bfbbbc7a6f295d.tar.gz
autorec-e90fc8a9809127820252a09dd7bfbbbc7a6f295d.zip
MVP
Diffstat (limited to 'src/win.h')
-rw-r--r--src/win.h104
1 files changed, 51 insertions, 53 deletions
diff --git a/src/win.h b/src/win.h
index 65f2595..9d21f68 100644
--- a/src/win.h
+++ b/src/win.h
@@ -14,46 +14,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<void()>;
std::map<HWND, std::map<WORD, CallbackFn>> handlers;
std::map<HWND, lay_id> 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 +50,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 +82,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 +104,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<void()> cb)
@@ -165,9 +132,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 +144,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(nullptr, IDI_WINLOGO);
+ _::niData.hWnd = result;
+ _::niData.uCallbackMessage = WM_APP+1;
+ _::niData.uVersion = NOTIFYICON_VERSION_4;
+
+ return result;
}
bool
@@ -289,6 +265,28 @@ void ListRemove(HWND hwnd, int index)
}
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)
{
lay_id lId = lay_item(&_::ctx);