#include <windows.h>\r
#include <CommCtrl.h>\r
\r
+#include "../res/resource.h"\r
+\r
#include "layout.h"\r
\r
#include <functional>\r
using std::string;\r
\r
namespace win {\r
-struct Length\r
-{\r
- int pixel;\r
- float percent;\r
-};\r
-struct Size\r
-{\r
- Length x, y, w, h;\r
- int getX(HWND hwnd)\r
- {\r
- RECT rect;\r
- GetClientRect(hwnd, &rect);\r
- return x.percent * (rect.right - rect.left) + x.pixel;\r
- }\r
- int getY(HWND hwnd)\r
- {\r
- RECT rect;\r
- GetClientRect(hwnd, &rect);\r
- return y.percent * (rect.bottom - rect.top) + y.pixel;\r
- }\r
- int getW(HWND hwnd)\r
- {\r
- RECT rect;\r
- GetClientRect(hwnd, &rect);\r
- return w.percent * (rect.right - rect.left) + w.pixel;\r
- }\r
- int getH(HWND hwnd, int _w, int _h)\r
- {\r
- RECT rect;\r
- GetWindowRect(hwnd, &rect);\r
- return h.percent * (rect.bottom - rect.top) + h.pixel;\r
- }\r
-};\r
-\r
namespace _ {\r
using CallbackFn = std::function<void()>;\r
std::map<HWND, std::map<WORD, CallbackFn>> handlers;\r
std::map<HWND, lay_id> lIds;\r
\r
NOTIFYICONDATA niData = { 0 };\r
+void\r
+ShowNotificationIcon()\r
+{\r
+ Shell_NotifyIconA(NIM_ADD, &_::niData);\r
+ Shell_NotifyIconA(NIM_SETVERSION, &_::niData);\r
+}\r
+\r
+void\r
+HideNotificationIcon()\r
+{\r
+ Shell_NotifyIconA(NIM_DELETE, &_::niData);\r
+}\r
\r
lay_context ctx;\r
lay_id root;\r
break;\r
case WM_SIZE:\r
if (wParam == SIZE_MINIMIZED) {\r
+ ShowNotificationIcon();\r
ShowWindow(hwnd, false);\r
- SetForegroundWindow(hwnd);\r
- SetActiveWindow(hwnd);\r
}\r
else {\r
lay_set_size_xy(&_::ctx, _::root, LOWORD(lParam), HIWORD(lParam));\r
case WM_NOTIFY:\r
break;\r
case WM_APP + 1:\r
- if (LOWORD(lParam) == NIN_SELECT)\r
+ if (LOWORD(lParam) == NIN_SELECT) {\r
+ HideNotificationIcon();\r
ShowWindow(hwnd, true);\r
+ SetForegroundWindow(hwnd);\r
+ SetActiveWindow(hwnd);\r
+ }\r
break;\r
case WM_CTLCOLORSTATIC:\r
return (LONG)GetStockObject(WHITE_BRUSH);\r
}\r
}\r
\r
-void\r
-ShowNotificationIcon(HINSTANCE hInstance, HWND hwnd)\r
-{\r
- _::niData.cbSize = sizeof(_::niData);\r
- _::niData.uID = 12345;\r
- _::niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;\r
- _::niData.hIcon = LoadIconA(nullptr, IDI_WINLOGO);\r
- _::niData.hWnd = hwnd;\r
- _::niData.uCallbackMessage = WM_APP+1;\r
- _::niData.uVersion = NOTIFYICON_VERSION_4;\r
-\r
- Shell_NotifyIconA(NIM_ADD, &_::niData);\r
- Shell_NotifyIconA(NIM_SETVERSION, &_::niData);\r
-}\r
\r
void\r
Callback(HWND hwnd, WORD ev, std::function<void()> cb)\r
lay_init_context(&_::ctx);\r
_::root = lay_item(&_::ctx);\r
lay_set_contain(&_::ctx, _::root, LAY_COLUMN);\r
- lay_set_margins_ltrb(&_::ctx, _::root, 5, 5, 5, 5);\r
\r
- return CreateWindowA(className.c_str(),\r
+ HWND result = CreateWindowA(className.c_str(),\r
title.c_str(),\r
WS_OVERLAPPEDWINDOW,\r
CW_USEDEFAULT,\r
nullptr,\r
hInstance,\r
nullptr);\r
+ \r
+ _::niData.cbSize = sizeof(_::niData);\r
+ _::niData.uID = 12345;\r
+ _::niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;\r
+ _::niData.hIcon = LoadIconA(hInstance, MAKEINTRESOURCEA(IDI_MY_ICON));\r
+ _::niData.hWnd = result;\r
+ _::niData.uCallbackMessage = WM_APP+1;\r
+ _::niData.uVersion = NOTIFYICON_VERSION_4;\r
+\r
+ return result;\r
}\r
\r
bool\r
SendMessageA(hwnd, LB_DELETESTRING, index, 0);\r
}\r
\r
+HWND\r
+ListView(HWND hwnd, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave)\r
+{\r
+ lay_id lId = lay_item(&_::ctx);\r
+ lay_insert(&_::ctx, parent, lId);\r
+ lay_set_size_xy(&_::ctx, lId, w, h);\r
+ lay_set_contain(&_::ctx, lId, contain);\r
+ lay_set_behave(&_::ctx, lId, behave);\r
+\r
+ HWND result = CreateWindowExA(0,\r
+ WC_LISTVIEWA,\r
+ "",\r
+ WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL,\r
+ 0, 0, 0, 0,\r
+ hwnd,\r
+ nullptr,\r
+ nullptr,\r
+ nullptr);\r
+ _::lIds[result] = lId;\r
+ return result;\r
+}\r
+\r
HWND\r
CheckBox(HWND hwnd, string title, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave)\r
{\r