2 #define _USE_MATH_DEFINES
15 #define M_PI 3.14159265358979323846
23 typedef std::map<HWND, gui *> mgui_t;
24 typedef std::vector<gui *> children_t;
38 asyncReadComplete = WM_APP + 1,
40 tcpServerReadComplete,
60 bool set(
int id, HWND h)
69 std::cout <<
"App tried to show two modal windows\n";
70 SetFocus(myModalHandle);
100 SetFocus(myModalHandle);
119 : myfClickPropogate(
false), myfMouseTracking(
false)
126 draw([](PAINTSTRUCT &ps) {});
127 resize([](
int w,
int h) {});
128 scrollH([](
int c) {});
129 scrollV([](
int c) {});
133 mouseMove([](
sMouse &m) {});
134 mouseWheel([](
int dist) {});
136 timer([](
int id) {});
137 slid([](
int pos) {});
139 drop([](
const std::vector<std::string> &files) {});
141 tcpServerAccept([] {});
145 datePick([](
int id, LPNMDATETIMECHANGE date) {});
150 myClickFunctionApp();
151 return !myfClickPropogate;
155 myClickRightFunction();
163 myClickDoubleFunction();
165 void onDraw(PAINTSTRUCT &ps)
169 void onResize(
int w,
int h)
171 myResizeFunction(w, h);
173 void onScrollH(
int code)
175 myScrollHFunction(code);
177 void onScrollV(
int code)
179 myScrollVFunction(code);
181 void onMenuCommand(
int id)
183 if (0 >
id ||
id >= (
int)myVectorMenuFunction.size())
185 myVectorMenuFunction[id](myVectorMenuTitle[id]);
187 void onKeydown(
int keycode)
189 myKeydownFunction(keycode);
191 void onMouseMove(WPARAM wParam, LPARAM lParam)
194 m.x = LOWORD(lParam);
195 m.y = HIWORD(lParam);
196 m.left = (wParam == MK_LBUTTON);
198 myMouseMoveFunction(m);
202 myMouseEnterFunction();
204 void onMouseWheel(
int dist)
206 myMouseWheelFunction(dist);
210 myMouseLeaveFunction();
219 auto it = mapControlFunction().find(std::make_pair(
id, CBN_SELCHANGE));
220 if (it == mapControlFunction().end())
228 auto it = mapControlFunction().find(std::make_pair(
id, EN_CHANGE));
229 if (it == mapControlFunction().end())
234 void onSlid(
unsigned short id)
236 mySlidFunction((
int)
id);
238 void onDropStart(HDROP hDrop)
240 myDropStartFunction(hDrop);
242 void onDrop(
const std::vector<std::string> &files)
244 myDropFunction(files);
246 void onAsyncReadComplete(
int id)
248 myAsyncReadCompleteFunction(
id);
250 void onTcpServerAccept()
252 myTcpServerAcceptFunction();
254 void onTcpServerReadComplete()
256 myTcpServerReadCompleteFunction();
260 return myQuitAppFunction();
264 LPNMDATETIMECHANGE date)
266 myDatePickFunction(idFrom, date);
277 std::function<
void(
void)> f,
278 bool propogate =
false)
280 myClickFunctionApp = f;
281 myfClickPropogate = propogate;
298 myfClickPropogate = f;
301 void clickRight(std::function<
void(
void)> f)
303 myClickRightFunction = f;
306 void clickDouble(std::function<
void(
void)> f)
308 myClickDoubleFunction = f;
311 void draw(std::function<
void(PAINTSTRUCT &ps)> f)
315 void resize(std::function<
void(
int w,
int h)> f)
317 myResizeFunction = f;
319 void scrollH(std::function<
void(
int code)> f)
321 myScrollHFunction = f;
323 void scrollV(std::function<
void(
int code)> f)
325 myScrollVFunction = f;
333 std::function<
void(
const std::string &title)> f,
334 const std::string &title)
336 int id = (int)myVectorMenuFunction.size();
337 myVectorMenuFunction.push_back(f);
338 myVectorMenuTitle.push_back(title);
343 std::function<
void(
void)> f)
345 mapControlFunction().insert(
346 std::make_pair(std::make_pair(
id, CBN_SELCHANGE), f));
353 std::function<
void(
void)> f)
355 mapControlFunction().insert(
356 std::make_pair(std::make_pair(
id, EN_CHANGE), f));
361 myKeydownFunction = f;
363 void mouseEnter(std::function<
void(
void)> f)
365 myMouseEnterFunction = f;
367 void mouseMove(std::function<
void(sMouse &m)> f)
369 myMouseMoveFunction = f;
371 void mouseWheel(std::function<
void(
int dist)> f)
373 myMouseWheelFunction = f;
375 void mouseUp(std::function<
void(
void)> f)
377 myMouseUpFunction = f;
379 void mouseLeave(std::function<
void(
void)> f)
381 myMouseLeaveFunction = f;
383 void timer(std::function<
void(
int id)> f)
387 void slid(std::function<
void(
int pos)> f)
394 myDropStartFunction = f;
397 void drop(std::function<
void(
const std::vector<std::string> &files)> f)
406 myAsyncReadCompleteFunction = f;
408 void tcpServerAccept(std::function<
void(
void)> f)
410 myTcpServerAcceptFunction = f;
415 myTcpServerReadCompleteFunction = f;
422 myQuitAppFunction = f;
450 void datePick(std::function<
void(
int, LPNMDATETIMECHANGE)> f)
452 myDatePickFunction = f;
456 bool myfClickPropogate;
457 bool myfMouseTracking;
460 std::function<void(
void)> myClickFunctionApp;
461 std::function<void(
void)> myClickRightFunction;
462 std::function<void(
void)> myClickDoubleFunction;
463 std::function<void(PAINTSTRUCT &ps)> myDrawFunction;
464 std::function<void(
int w,
int h)> myResizeFunction;
465 std::function<void(
int code)> myScrollHFunction;
466 std::function<void(
int code)> myScrollVFunction;
467 std::vector<std::function<void(
const std::string &title)>> myVectorMenuFunction;
468 std::vector<std::string> myVectorMenuTitle;
469 std::function<void(
int keycode)> myKeydownFunction;
470 std::function<void(
sMouse &m)> myMouseMoveFunction;
471 std::function<void(
void)> myMouseEnterFunction;
472 std::function<void(
int dist)> myMouseWheelFunction;
473 std::function<void(
int id)> myTimerFunction;
474 std::function<void(
void)> myMouseUpFunction;
475 std::function<void(
void)> myMouseLeaveFunction;
476 std::function<void(
int pos)> mySlidFunction;
477 std::function<void(HDROP hDrop)> myDropStartFunction;
478 std::function<void(
const std::vector<std::string> &files)> myDropFunction;
479 std::function<void(
int id)> myAsyncReadCompleteFunction;
480 std::function<void(
void)> myTcpServerAcceptFunction;
481 std::function<void(
void)> myTcpServerReadCompleteFunction;
482 std::function<bool(
void)> myQuitAppFunction;
483 std::function<void(
int, LPNMDATETIMECHANGE)> myDatePickFunction;
486 std::function<void(
void)> myClickFunWex;
490 std::map<std::pair<int, unsigned short>, std::function<void(
void)>> &
493 static std::map<std::pair<int, unsigned short>, std::function<void(
void)>>
494 myMapControlFunction;
495 return myMapControlFunction;
531 : myHDC(ps.hdc), myPenThick(1), myFill(false)
537 hPenOld = SelectObject(myHDC, hPen);
541 ZeroMemory(&myLogfont,
sizeof(LOGFONT));
542 myLogfont.lfWeight = FW_NORMAL;
543 strcpy(myLogfont.lfFaceName,
"Tahoma");
544 myLogfont.lfHeight = 20;
545 hFont = CreateFontIndirect(&myLogfont);
546 hFont = (HFONT)SelectObject(myHDC, hFont);
551 HGDIOBJ pen = SelectObject(myHDC, hPenOld);
570 HGDIOBJ old = SelectObject(myHDC, hPen);
572 SetTextColor(myHDC, c);
573 HBRUSH brush = CreateSolidBrush(c);
574 old = SelectObject(myHDC, brush);
584 void bgcolor(
int r,
int g,
int b)
611 SetPixel(myHDC, x, y, myColor);
616 void line(
const std::vector<int> &v)
629 void polyLine(POINT *pp,
int n)
670 v[0], v[1], v[0] + v[2], v[1] + v[3]);
680 Polygon(myHDC, (
const POINT *)&(v[0]), v.size() / 2);
694 int x,
int y,
double r,
695 double sa,
double ea)
697 int xl = round(x - r);
698 int yt = round(y - r);
699 int xr = round(x + r);
700 int yb = round(y + r);
701 int xs = round(x + r * cos(sa * M_PI / 180));
702 int ys = round(y - r * sin(sa * M_PI / 180));
703 int xe = round(x + r * cos(ea * M_PI / 180));
704 int ye = round(y - r * sin(ea * M_PI / 180));
707 xl, yt, xr, yb, xs, ys, xe, ye);
728 const std::string &t,
729 const std::vector<int> &v)
732 switch ((
int)v.size())
745 rect.right = v[0] + v[2];
746 rect.bottom = v[1] + v[3];
759 const std::string &t,
760 const std::vector<int> &v)
762 int ws = textWidthPixels(t);
763 int pad = (v[2] - ws) / 2;
766 std::vector<int> vc = v;
774 myLogfont.lfEscapement = 2700;
776 myLogfont.lfEscapement = 0;
777 myLogfont.lfOrientation = myLogfont.lfEscapement;
778 HANDLE hFont = CreateFontIndirect(&myLogfont);
779 hFont = (HFONT)SelectObject(myHDC, hFont);
788 myLogfont.lfHeight = h;
789 HANDLE hFont = CreateFontIndirect(&myLogfont);
790 hFont = (HFONT)SelectObject(myHDC, hFont);
796 strcpy(myLogfont.lfFaceName, fn.c_str());
797 HANDLE hFont = CreateFontIndirect(&myLogfont);
798 hFont = (HFONT)SelectObject(myHDC, hFont);
801 int textWidthPixels(
const std::string &t)
804 GetTextExtentPoint32A(
832 : myParent(NULL), myBGColor(0xC8C8C8), myBGBrush(CreateSolidBrush(myBGColor)), myTextColor(0),
839 WS_OVERLAPPEDWINDOW, WS_EX_CONTROLPARENT,
847 events().resize([
this](
int w,
int h)
857 GetStockObject(DEFAULT_GUI_FONT),
858 sizeof(myLogFont), &myLogFont);
861 myLogFont.lfHeight = 18;
863 myFont = CreateFontIndirectA(&myLogFont);
873 const char *window_class =
"windex",
874 unsigned long style = WS_CHILD,
875 unsigned long exstyle = WS_EX_CONTROLPARENT) : myParent(parent),
879 myCursorID(IDC_ARROW)
885 Create(parent->
handle(), window_class, style, exstyle, myID);
891 text(
"???" + std::to_string(myID));
897 parent->
font(myLogFont, myFont);
909 DestroyWindow(myHandle);
911 myDeleteList->push_back(myHandle);
952 DeleteObject(myBGBrush);
953 myBGBrush = CreateSolidBrush(color);
969 bool isEnabled()
const
977 myLogFont.lfHeight = h;
981 void fontName(
const std::string &name)
983 strcpy(myLogFont.lfFaceName, name.c_str());
993 void icon(
const std::string &iconfilename)
995 HICON hIcon = ExtractIconA(
997 iconfilename.c_str(),
1004 SendMessage(myHandle, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
1005 SendMessage(myHandle, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
1006 SendMessage(GetWindow(myHandle, GW_OWNER), WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
1007 SendMessage(GetWindow(myHandle, GW_OWNER), WM_SETICON, ICON_BIG, (LPARAM)hIcon);
1009 void cursor(
char *cursorID)
1011 myCursorID = cursorID;
1029 void text(
const std::string &text)
1032 SetWindowText(myHandle, myText.c_str());
1035 std::string text()
const
1046 myfScrollHoriz = fHoriz;
1051 extra = WS_HSCROLL | WS_VSCROLL;
1057 GetWindowLongPtr(myHandle, GWL_STYLE) | extra);
1063 events().scrollH([
this](
int code)
1066 si.cbSize =
sizeof(si);
1067 si.fMask = SIF_POS | SIF_TRACKPOS | SIF_PAGE;
1068 if (!GetScrollInfo(myHandle, SB_HORZ, &si))
1071 int oldPos = scrollMove(si, code);
1074 SetScrollInfo(myHandle, SB_HORZ, &si, TRUE);
1075 GetScrollInfo(myHandle, SB_CTL, &si);
1078 GetClientRect(myHandle, &rect);
1079 int xs = oldPos - si.nPos;
1085 UpdateWindow( myHandle );
1091 events().scrollV([
this](
int code)
1094 si.cbSize =
sizeof(si);
1095 si.fMask = SIF_POS | SIF_TRACKPOS | SIF_PAGE;
1096 if (!GetScrollInfo(myHandle, SB_VERT, &si))
1099 int oldPos = scrollMove(si, code);
1102 SetScrollInfo(myHandle, SB_VERT, &si, TRUE);
1103 GetScrollInfo(myHandle, SB_VERT, &si);
1105 GetClientRect(myHandle, &rect);
1106 int ys = oldPos - si.nPos;
1146 GetClientRect(myHandle, &r);
1147 int xmax = width - r.right;
1150 int ymax = height - (r.bottom - r.top) + 60;
1154 si.cbSize =
sizeof(si);
1155 si.fMask = SIF_RANGE | SIF_PAGE;
1158 si.nPage = ymax / 10;
1159 SetScrollInfo(myHandle, SB_VERT, &si, TRUE);
1163 si.nPage = xmax / 10;
1164 SetScrollInfo(myHandle, SB_HORZ, &si, TRUE);
1176 if (!ScreenToClient(myHandle, &p))
1183 m.left = (GetKeyState(VK_LBUTTON) < 0);
1184 m.right = (GetKeyState(VK_RBUTTON) < 0);
1185 m.shift = (GetKeyState(VK_SHIFT) < 0);
1201 while (GetMessage(&msg, NULL, 0, 0))
1210 if (!IsDialogMessage(myHandle, &msg))
1212 TranslateMessage(&msg);
1213 DispatchMessage(&msg);
1222 void tooltip(
const std::string &text,
int width = 0)
1224 TOOLINFO toolInfo = {0};
1225 toolInfo.cbSize =
sizeof(toolInfo);
1226 toolInfo.hwnd = myHandle;
1227 toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
1228 toolInfo.uId = (UINT_PTR)myHandle;
1229 toolInfo.lpszText = (
char *)text.c_str();
1235 myToolTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
1236 WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
1237 CW_USEDEFAULT, CW_USEDEFAULT,
1238 CW_USEDEFAULT, CW_USEDEFAULT,
1239 myHandle, NULL, NULL, NULL);
1240 SendMessage(myToolTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
1246 SendMessage(myToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)&toolInfo);
1251 SendMessage(myToolTip, TTM_SETMAXTIPWIDTH, 0, width);
1254 virtual LRESULT WindowMessageHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1258 if (hwnd == myHandle)
1274 if (!myEvents.onQuitApp())
1280 DestroyWindow(myHandle);
1310 GetWindowRect(hwnd, &rc);
1311 FillRect((HDC)wParam, &rc, myBGBrush);
1318 BeginPaint(myHandle, &ps);
1320 FillRect(ps.hdc, &ps.rcPaint, myBGBrush);
1323 EndPaint(myHandle, &ps);
1327 case WM_CTLCOLORSTATIC:
1332 GetBoundsRect(GetDC(myHandle), &r, 0);
1333 FillRect(GetDC(myHandle), &r, myBGBrush);
1334 SetBkMode((HDC)wParam, TRANSPARENT);
1336 return (INT_PTR)GetStockObject(NULL_BRUSH);
1341 NMHDR *pnmhdr =
reinterpret_cast<NMHDR *
>(lParam);
1342 if (pnmhdr->code == DTN_DATETIMECHANGE)
1344 myEvents.onDatePicked(
1346 (LPNMDATETIMECHANGE)(lParam));
1351 case WM_LBUTTONDOWN:
1355 if (myEvents.onLeftdown())
1360 if (myParent->WindowMessageHandler(
1362 uMsg, wParam, lParam))
1367 case WM_RBUTTONDOWN:
1368 myEvents.onRightDown();
1373 myEvents.onMouseUp();
1376 case WM_LBUTTONDBLCLK:
1377 std::cout <<
"WM_LBUTTONDBLCLK\n";
1378 myEvents.onDoubleClick();
1382 myEvents.onMouseMove(wParam, lParam);
1387 int d = HIWORD(wParam);
1390 myEvents.onMouseWheel(d);
1395 myEvents.onMouseLeave();
1399 myEvents.onResize(LOWORD(lParam), HIWORD(lParam));
1404 trackbarMessageHandler((HWND)lParam);
1406 myEvents.onScrollH(LOWORD(wParam));
1410 std::cout <<
"VSCROLL\n";
1412 trackbarMessageHandler((HWND)lParam);
1414 myEvents.onScrollV(LOWORD(wParam));
1421 auto wp_hi = HIWORD(wParam);
1424 events().onMenuCommand(wParam);
1428 if (wp_hi == CBN_SELCHANGE || wp_hi == LBN_SELCHANGE)
1430 return events().onSelect(LOWORD(wParam));
1433 if (wp_hi == EN_CHANGE)
1435 return events().onChange(LOWORD(wParam));
1441 events().onTimer((
int)wParam);
1445 events().onDropStart((HDROP)wParam);
1449 events().onKeydown((
int)wParam);
1450 return DLGC_WANTARROWS;
1453 events().onKeydown((
int)wParam);
1459 SetCursor(LoadCursor(NULL, (LPCSTR)myCursorID));
1464 case eventMsgID::asyncReadComplete:
1465 events().onAsyncReadComplete(wParam);
1468 case eventMsgID::tcpServerAccept:
1469 events().onTcpServerAccept();
1472 case eventMsgID::tcpServerReadComplete:
1473 events().onTcpServerReadComplete();
1481 if (w->WindowMessageHandler(hwnd, uMsg, wParam, lParam))
1492 int cmd = SW_SHOWDEFAULT;
1496 ShowWindow(myHandle, cmd);
1515 appWindow.
enable(
false );
1523 while (GetMessage(&msg, NULL, 0, 0))
1525 if (!IsDialogMessage(myHandle, &msg))
1527 TranslateMessage(&msg);
1528 DispatchMessage(&msg);
1532 switch (msg.message)
1535 std::cout << myText <<
" WM_CLOSE";
1539 std::cout << myText <<
" WM_DESTROY";
1552 appWindow.
enable(
true );
1562 DestroyWindow(myHandle);
1564 myDeleteList->push_back(myHandle);
1577 InvalidateRect(myHandle, NULL,
true);
1578 UpdateWindow(myHandle);
1587 void move(
const std::vector<int> &r)
1591 MoveWindow(myHandle,
1592 r[0], r[1], r[2], r[3],
false);
1601 GetWindowRect(myHandle, &rect);
1602 MoveWindow(myHandle,
1603 rect.left, rect.top, w, h,
1613 GetClientRect(myHandle, &rect);
1614 MoveWindow(myHandle,
1615 x, y, rect.right - rect.left, rect.bottom - rect.top,
1618 void move(
int x,
int y,
int w,
int h)
1620 MoveWindow(myHandle,
1629 GetClientRect(myHandle, &r);
1630 std::vector<int> ret{
1631 r.right - r.left, r.bottom - r.top};
1634 std::vector<int> lefttop()
1637 GetWindowRect(myParent->
handle(), &rp);
1639 GetWindowRect(myHandle, &r);
1642 static std::vector<int> ret(2);
1643 ret[0] = r.left - rp.left;
1644 ret[1] = r.top - rp.top;
1663 myDeleteList =
list;
1669 myLogFont = logfont;
1677 w->setfont(myLogFont, myFont);
1679 void setAsyncReadCompleteMsgID(
int id)
1687 eventhandler myEvents;
1693 std::vector<HWND> *myDeleteList;
1703 bool myfScrollHoriz;
1714 const char *window_class,
1715 DWORD style, DWORD exstyle = 0,
1718 myHandle = CreateWindowEx(
1725 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1728 reinterpret_cast<HMENU
>(
id),
1734 throw std::runtime_error(
1735 "Create Window failed");
1747 logfont = myLogFont;
1754 DeleteObject(myFont);
1755 myFont = CreateFontIndirectA(&myLogFont);
1758 virtual void draw(PAINTSTRUCT &ps)
1763 int color = 0x000000;
1771 SelectObject(ps.hdc, myFont);
1774 auto hbrBkgnd = CreateSolidBrush(myBGColor);
1779 DeleteObject(hbrBkgnd);
1789 myEvents.onDraw(ps);
1799 static int lastID = 0;
1803 int scrollMove(SCROLLINFO &si,
int code)
1805 int oldPos = si.nPos;
1820 si.nPos -= si.nPage;
1825 si.nPos += si.nPage;
1830 si.nPos = si.nTrackPos;
1837 void trackbarMessageHandler(HWND hwnd)
1839 std::cout <<
"trackbarMessageHandler\n";
1845 if (c->handle() == hwnd)
1851 (WPARAM)0, (LPARAM)0));
1906 DragAcceptFiles(myHandle,
true);
1909 myEvents.dropStart([
this](HDROP hDrop)
1911 int count = DragQueryFileA(hDrop, 0xFFFFFFFF, NULL, 0);
1915 std::vector<std::string> files;
1916 char fname[MAX_PATH];
1917 for (
int k = 0; k < count; k++)
1919 DragQueryFileA(hDrop, k, fname, MAX_PATH);
1920 files.push_back(fname);
1923 myEvents.onDrop(files);
1925 DragFinish(hDrop); });
1940 void move(
const std::vector<int> &r)
1948 myRect.right = r[0] + r[2];
1949 myRect.bottom = r[1] + r[3];
1952 MoveWindow(myHandle,
1953 r[0] + 5, r[1] + 2, 60, 25,
false);
1955 virtual void draw(PAINTSTRUCT &ps)
1958 HDC hdc = GetDC(myParent->handle());
1964 ReleaseDC(myParent->handle(), hdc);
1970 SelectObject(ps.hdc, myFont);
1988 :
panel(parent), myColCount(2), myfWidthsSpecified(
false), myfColFirst(
false)
2012 myfWidthsSpecified =
true;
2037 void draw(PAINTSTRUCT &ps)
2042 GetClientRect(myHandle, &r);
2043 if (!myfWidthsSpecified)
2046 int colwidth = (r.right - r.left) / myColCount;
2048 for (
int k = 0; k < myColCount; k++)
2050 myWidths.push_back(colwidth);
2057 int rowCount = (
myChild.size() + 1) / myColCount;
2060 rowheight = (r.bottom - r.top) / rowCount;
2074 w->move(x, rowcount * rowheight);
2077 x += myWidths[colcount];
2079 if (colcount >= myColCount)
2091 w->move(x, rowcount * rowheight);
2094 if (rowcount >= (
int)
myChild.size() / myColCount)
2097 x += myWidths[colcount];
2106 std::vector<int> myWidths;
2107 bool myfWidthsSpecified;
2116 :
gui(parent), myBitmap(NULL)
2118 myBGColor = 0xC8C8C8;
2126 myBitmap = (HBITMAP)LoadImage(
2127 NULL, name.c_str(), IMAGE_BITMAP,
2128 0, 0, LR_LOADFROMFILE);
2150 auto h = GetModuleHandleA(NULL);
2153 myBitmap = LoadBitmap(
2172 int color = 0x000000;
2182 SelectObject(ps.hdc, myFont);
2185 auto hbrBkgnd = CreateSolidBrush(myBGColor);
2190 DeleteObject(hbrBkgnd);
2199 DT_SINGLELINE | DT_CENTER | DT_VCENTER);
2211 HDC hLocalDC = CreateCompatibleDC(ps.hdc);
2213 GetObject(
reinterpret_cast<HGDIOBJ
>(myBitmap),
sizeof(BITMAP),
2214 reinterpret_cast<LPVOID
>(&qBitmap));
2215 HBITMAP hOldBmp = (HBITMAP)SelectObject(hLocalDC, myBitmap);
2217 ps.hdc, 0, 0, qBitmap.bmWidth, qBitmap.bmHeight,
2218 hLocalDC, 0, 0, SRCCOPY);
2219 SelectObject(hLocalDC, hOldBmp);
2297 :
gui(parent), myValue(
false)
2300 group().back().push_back(
this);
2301 myGroup = group().size() - 1;
2309 for (
auto b : group()[myGroup])
2331 auto this_it = std::find(
2332 group()[myGroup].begin(),
2333 group()[myGroup].end(),
2336 if (this_it == group()[myGroup].end())
2337 throw std::runtime_error(
"wex::radiobutton::first error in group");
2340 if (this_it == group()[myGroup].begin())
2344 std::vector<radiobutton *> g;
2345 group().push_back(g);
2350 it != group()[myGroup].end();
2353 group().back().push_back(*it);
2357 group()[myGroup].erase(
2359 group()[myGroup].end());
2362 for (
auto b : group().back())
2363 b->myGroup = group().size() - 1;
2386 for (
auto b : group()[myGroup])
2392 if (off < (
int)group()[myGroup].
size())
2403 for (
auto b : group()[myGroup])
2413 virtual void draw(PAINTSTRUCT &ps)
2415 SelectObject(ps.hdc, myFont);
2416 int color = 0x000000;
2437 S.circle(10, 10, 5);
2441 SelectObject(ps.hdc, GetStockObject(BLACK_BRUSH));
2442 Ellipse(ps.hdc, 5, 5, 15, 15);
2451 std::vector<std::vector<radiobutton *>> &group()
2453 static std::vector<std::vector<radiobutton *>> theGroups;
2454 static bool fGroupInit =
false;
2459 std::vector<radiobutton *> g;
2460 theGroups.push_back(g);
2482 :
gui(parent), myType(eType::check), myValue(
false)
2496 myType = eType::plus;
2498 myType = eType::check;
2500 void check(
bool f =
true)
2508 virtual void draw(PAINTSTRUCT &ps)
2514 int cbg = r.bottom - r.top - 10;
2519 S.textHeight(myLogFont.lfHeight);
2520 S.textFontName(myLogFont.lfFaceName);
2521 S.text(myText, {r.left, r.top, r.right, r.bottom});
2522 S.rectangle({0, 0, cbg, cbg});
2531 S.line({2, cbg / 2, cbg / 2 - 1, cbg - 2});
2532 S.line({cbg / 2, cbg - 3, cbg - 4, 3});
2536 S.line({2, cbg / 2, cbg - 2, cbg / 2});
2538 S.line({1 + cbg / 2, 2, 1 + cbg / 2, cbg - 2});
2543 void clickFunction(std::function<
void(
void)> f)
2545 myClickFunction = f;
2550 std::function<void(
void)> myClickFunction;
2559 const std::string &msg)
2569 const std::string &msg,
2570 const std::string &title,
2638 :
gui(parent,
"Edit",
2639 WS_CHILD | ES_LEFT | WS_BORDER | WS_VISIBLE,
2646 std::cout <<
"editbox notification " << ntf <<
"\n";
2647 if (ntf == EN_KILLFOCUS)
2649 std::cout <<
"done\n";
2652 void text(
const std::string &t)
2668 return std::string(buf);
2676 (WPARAM)f, (LPARAM)0);
2685 :
gui(parent,
"Edit",
2686 WS_CHILD | ES_LEFT | WS_BORDER | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN,
2710 return std::string(buf);
2718 :
gui(parent,
"Combobox",
2719 CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE)
2723 void move(
int x,
int y,
int w,
int h)
2735 (WPARAM)0, (LPARAM)20);
2746 void add(
const std::string &s)
2760 (WPARAM)0, (LPARAM)0);
2770 (WPARAM)i, (LPARAM)0);
2780 (WPARAM)-1, (LPARAM)s.c_str());
2788 (WPARAM)0, (LPARAM)0);
2795 return std::string(
"");
2807 return std::string(buf);
2815 (WPARAM)0, (LPARAM)0);
2835 :
gui(parent,
"listbox",
2836 LBS_NOTIFY | WS_VSCROLL | WS_BORDER |
2837 WS_CHILD | WS_OVERLAPPED | WS_VISIBLE)
2841 void move(
int x,
int y,
int w,
int h)
2846 (UINT)LB_SETCOLUMNWIDTH,
2851 void add(
const std::string &s)
2865 (WPARAM)0, (LPARAM)0);
2875 (WPARAM)i, (LPARAM)0);
2885 (WPARAM)i, (LPARAM)0);
2895 (WPARAM)-1, (LPARAM)s.c_str());
2905 (WPARAM)0, (LPARAM)0);
2913 return std::string(
"");
2920 return std::string(buf);
2928 (WPARAM)0, (LPARAM)0);
2952 static windex theInstance;
2961 static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2966 if (uMsg == WM_GETDLGCODE)
2967 return w->second->WindowMessageHandler(hwnd, uMsg, wParam, lParam);
2969 if (w->second->WindowMessageHandler(hwnd, uMsg, wParam, lParam))
2974 return DefWindowProc(hwnd, uMsg, wParam, lParam);
2996 std::vector<HWND> myDeleteList;
3003 wc.lpfnWndProc = &windex::WindowProc;
3004 wc.hInstance = NULL;
3005 wc.lpszClassName =
"windex";
3006 wc.hbrBackground = CreateSolidBrush(0xc8c8c8);
3007 wc.style = CS_DBLCLKS;
3015 for (
auto h : myDeleteList)
3017 auto i =
myGui.find(h);
3018 if (i !=
myGui.end())
3021 myDeleteList.clear();
3060 : myM(CreatePopupMenu()), myParent(parent)
3078 const std::string &title,
3079 const std::function<
void(
const std::string &)> &f = [](
const std::string &title) {})
3084 myParent.events().menuCommand(f, title),
3093 const std::string &title,
3099 (UINT_PTR)submenu.handle(),
3129 unsigned int uCheck;
3131 uCheck = MF_BYPOSITION | MF_CHECKED;
3133 uCheck = MF_BYPOSITION | MF_UNCHECKED;
3134 return MF_CHECKED == CheckMenuItem(
3142 return GetMenuItemCount(myM);
3155 : myParent(parent), myM(CreateMenu())
3158 SetMenu(parent.
handle(), myM);
3165 const std::string &title,
3171 (UINT_PTR)m.handle(),
3173 DrawMenuBar(myParent.handle());
3204 : myGUI(g), myID(id)
3225 #include "widgets.h"
3243 template <
class W,
class P>
3303 :
panel(parent), myTabWidth(50)
3315 const std::string &tabname,
3320 GetClientRect(myHandle, &rect);
3321 panel.
move(0, 31, rect.right - rect.left, rect.bottom - rect.top - 30);
3323 button &btn = maker::make<button>(*
this);
3325 btn.
move(myButton.size() * myTabWidth,
3327 myButton.push_back(&btn);
3328 myPanel.push_back(&
panel);
3329 int tabIndex = myButton.size() - 1;
3333 myTabChangingFn(tabIndex);
3335 myTabChangeFn(tabIndex); });
3340 std::cout <<
"select " << i <<
"\n";
3342 if (0 > i || i >= (
int)myButton.size())
3345 for (
auto b : myButton)
3347 b->bgcolor(0xC8C8C8);
3350 for (
auto p : myPanel)
3353 myButton[i]->bgcolor(0xFFFFFF);
3374 myTabChangingFn = f;
3386 std::vector<button *> myButton;
3387 std::vector<gui *> myPanel;
3390 std::function<void(
int tabIndex)> myTabChangingFn;
3391 std::function<void(
int tabIndex)> myTabChangeFn;
3428 :
layout(parent), myFirst(
true)
3488 memset(&pdlg, 0,
sizeof(PRINTDLG));
3489 pdlg.lStructSize =
sizeof(PRINTDLG);
3491 pdlg.Flags = PD_RETURNDC;
3502 memset(&di, 0,
sizeof(DOCINFO));
3504 di.cbSize =
sizeof(DOCINFO);
3505 di.lpszDocName = title.c_str();
3536 const std::string &s)
3541 s.c_str(), s.length());
3556 const std::string &command,
3560 PROCESS_INFORMATION pi;
3562 ZeroMemory(&si,
sizeof(si));
3564 ZeroMemory(&pi,
sizeof(pi));
3567 si.wShowWindow = SW_SHOWNOACTIVATE | SW_MINIMIZE;
3568 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USEPOSITION;
3572 if (!CreateProcessA(
3574 (LPSTR)command.c_str(),
3585 int syserrno = GetLastError();
3588 error =
"Cannot find executable file";
3593 FORMAT_MESSAGE_ALLOCATE_BUFFER |
3594 FORMAT_MESSAGE_FROM_SYSTEM |
3595 FORMAT_MESSAGE_IGNORE_INSERTS,
3598 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
3602 LocalFree(lpMsgBuf);
3607 CloseHandle(pi.hProcess);
3608 CloseHandle(pi.hThread);
A widget that user can click to toggle a true/false value.
Definition: wex.h:2473
void plus(bool f=true)
set type to plus, useful to indicate expanded or collapsed property categories
Definition: wex.h:2493
A widget where user can choose from a dropdown list of strings.
Definition: wex.h:2715
void clear()
Clear all options.
Definition: wex.h:2755
std::string text(int i)
get text by index
Definition: wex.h:2799
int selectedIndex()
get index of selected item
Definition: wex.h:2783
void itemHeight(int h)
set item height in drop doown list
Definition: wex.h:2730
void add(const std::string &s)
Add an option.
Definition: wex.h:2746
void select(const std::string &s)
Select by string.
Definition: wex.h:2775
void select(int i)
Select by index.
Definition: wex.h:2765
void move(int x, int y, int w, int h)
Override move to ensure height is sufficient to allow dropdown to apprear.
Definition: wex.h:2723
int count()
get count of items
Definition: wex.h:2810
std::string selectedText()
get text of selected item
Definition: wex.h:2791
A widget where users can drop files dragged from windows explorer.
Definition: wex.h:1898
A widget where user can enter a single line string.
Definition: wex.h:2635
void readonly(bool f=true)
disable ( or enable ) user editing
Definition: wex.h:2671
void notification(WORD ntf)
editbox generated a notification - nop
Definition: wex.h:2644
std::string text()
get text in textbox
Definition: wex.h:2660
A class where application code can register functions to be called when an event occurs.
Definition: wex.h:116
void drop(std::function< void(const std::vector< std::string > &files)> f)
register function to call when files dropped by user have been extracted. App code use this!
Definition: wex.h:397
void clickWex(std::function< void(void)> f)
register a function to do some housekeeping when clicked, before calling handler registered by applic...
Definition: wex.h:291
void datePick(std::function< void(int, LPNMDATETIMECHANGE)> f)
Register function to call when a date is picked.
Definition: wex.h:450
void quitApp(std::function< bool(void)> f)
register function to call when application is about to quit The function should return true to allow ...
Definition: wex.h:420
void asyncReadComplete(std::function< void(int id)> f)
register function to call when an asynchronous read completes.
Definition: wex.h:404
void keydown(std::function< void(int keydown)> f)
register function to call when key pressed. Function is passed key code.
Definition: wex.h:359
void clickPropogate(bool f=true)
specify that click event should propogate to parent window after currently registered click event han...
Definition: wex.h:296
void dropStart(std::function< void(HDROP hDrop)> f)
register function to call when user drops files. App code should NOT call this!
Definition: wex.h:392
int menuCommand(std::function< void(const std::string &title)> f, const std::string &title)
Register function to run when menu item clicked.
Definition: wex.h:332
void tcpRead(std::function< void(void)> f)
register function to call when tcp read accurs
Definition: wex.h:413
void change(int id, std::function< void(void)> f)
register function to call when control changes
Definition: wex.h:351
void click(std::function< void(void)> f, bool propogate=false)
register click event handler
Definition: wex.h:276
Displaying a title and a box.
Definition: wex.h:1931
void move(const std::vector< int > &r)
Set size and location of group box.
Definition: wex.h:1940
The base class for all windex gui elements.
Definition: wex.h:824
void update()
force widget to redraw completely
Definition: wex.h:1575
void child(gui *w)
register child on this window
Definition: wex.h:915
unsigned int myAsyncReadCompleteMsgID
handle to tooltip control for this gui element
Definition: wex.h:1701
std::vector< int > size()
Size of window client area.
Definition: wex.h:1626
void tooltip(const std::string &text, int width=0)
Add tooltip that pops up helpfully when mouse cursor hovers over widget.
Definition: wex.h:1222
void showModal(gui &appWindow)
Show this window and suspend all other windows interactions until this is closed.
Definition: wex.h:1505
void scrollRange(int width, int height)
Set the scrolling range.
Definition: wex.h:1135
void Create(HWND parent, const char *window_class, DWORD style, DWORD exstyle=0, int id=0)
Create the managed window.
Definition: wex.h:1712
void endModal()
Stop modal interaction and close window.
Definition: wex.h:1558
eventhandler & events()
Get event handler.
Definition: wex.h:1649
void delete_list(std::vector< HWND > *list)
set delete list for when gui is detroyed
Definition: wex.h:1661
void move(const std::vector< int > &r)
Move the window.
Definition: wex.h:1587
void setfont(LOGFONT &logfont, HFONT &font)
change font for this and all child windows
Definition: wex.h:1667
void size(int w, int h)
Change size without moving top left corner.
Definition: wex.h:1598
void icon(const std::string &iconfilename)
Change icon.
Definition: wex.h:993
void fontHeight(int h)
Change font height for this and all child windows.
Definition: wex.h:975
gui * find(int id)
find child window with specified id
Definition: wex.h:932
bool myfEnabled
true if not disabled
Definition: wex.h:1698
void createNewFont()
Replace font used by this and child windows from logfont.
Definition: wex.h:1752
gui(gui *parent, const char *window_class="windex", unsigned long style=WS_CHILD, unsigned long exstyle=WS_EX_CONTROLPARENT)
Construct child of a parent.
Definition: wex.h:871
std::vector< gui * > myChild
gui elements to be displayed in this window
Definition: wex.h:1696
HWND handle()
get window handle
Definition: wex.h:1655
void textColor(int c)
Set text color.
Definition: wex.h:1025
children_t & children()
get vector of children
Definition: wex.h:921
void enable(bool f=true)
Enable/Disable, default enable.
Definition: wex.h:963
bool myfModal
true if element is being shown as modal
Definition: wex.h:1697
void move(int x, int y)
Change position without changing size.
Definition: wex.h:1610
sMouse getMouseStatus()
Get mouse status.
Definition: wex.h:1171
void bgcolor(int color)
Change background color.
Definition: wex.h:949
virtual void show(bool f=true)
Show window and all children.
Definition: wex.h:1490
int NewID()
Create new, unique ID for gui element.
Definition: wex.h:1797
void run()
Run the windows message loop.
Definition: wex.h:1198
gui()
Construct top level window with no parent.
Definition: wex.h:831
void scroll(bool fHoriz=true)
Add scrollbars.
Definition: wex.h:1044
void font(LOGFONT &logfont, HFONT &font)
get font details
Definition: wex.h:1745
A widget that displays a string.
Definition: wex.h:2583
A panel which arranges the widgets it contains in a grid.
Definition: wex.h:1985
void grid(int cols)
Specify number of cols to use for layout.
Definition: wex.h:2002
void colWidths(const std::vector< int > &vw)
Specify column widths.
Definition: wex.h:2009
void colfirst(bool f=true)
Specify that widgets should be added to fill columns first.
Definition: wex.h:2033
A widget where user can choose from a list of strings.
Definition: wex.h:2832
std::string selectedText()
get text of selected item
Definition: wex.h:2909
void clear()
Clear all options.
Definition: wex.h:2860
void deleteItem(int i)
Delete by index.
Definition: wex.h:2880
void move(int x, int y, int w, int h)
Override move to ensure column width is sufficient.
Definition: wex.h:2841
int selectedIndex()
get index of selected item
Definition: wex.h:2900
void select(int i)
Select by index.
Definition: wex.h:2870
void add(const std::string &s)
Add an option.
Definition: wex.h:2851
void select(const std::string &s)
Select by string.
Definition: wex.h:2890
int count()
get count of items
Definition: wex.h:2923
A class for making windex objects.
Definition: wex.h:3237
static W & make(P &parent)
Construct widget.
Definition: wex.h:3244
static gui & make()
Construct a top level window ( first call constructs application window )
Definition: wex.h:3252
bool set(int id, HWND h)
Set modal running.
Definition: wex.h:60
bool canClose(int id)
Can a window be closed.
Definition: wex.h:86
static modalMgr & get()
get reference to singleton modal manager
Definition: wex.h:47
A popup with a message.
Definition: wex.h:2555
msgbox(const std::string &msg)
CTOR for simple message box with OK button.
Definition: wex.h:2558
int myReturn
Button id clicked by user.
Definition: wex.h:2578
msgbox(gui &parent, const std::string &msg, const std::string &title, unsigned int type)
CTOR for message box with title and configurable buttons.
Definition: wex.h:2567
A mutiline editbox.
Definition: wex.h:2682
std::string text()
get text in textbox
Definition: wex.h:2702
void text(const std::string &t)
Set text.
Definition: wex.h:2694
A child window that can contain widgets.
Definition: wex.h:1859
Print a text document.
Definition: wex.h:3477
~printDoc()
Finalize and send to printer.
Definition: wex.h:3510
printDoc(const std::string &title="printDoc")
CTOR.
Definition: wex.h:3482
void text(int x, int y, const std::string &s)
Add some text.
Definition: wex.h:3534
bool isOpen()
True if CTOR was successful.
Definition: wex.h:3516
A class that offers application code methods to draw on a window.
Definition: wex.h:525
void penThick(int t)
Set pen thickness in pixels.
Definition: wex.h:597
void textFontName(const std::string &fn)
set text font name
Definition: wex.h:794
void arc(int x, int y, double r, double sa, double ea)
Draw Arc of circle.
Definition: wex.h:693
void textHeight(int h)
Set text height.
Definition: wex.h:786
void text(const std::string &t, const std::vector< int > &v)
Draw text.
Definition: wex.h:727
void textVertical(bool f=true)
Enable / disable drawing text in vertical orientation.
Definition: wex.h:771
void bgcolor(int c)
set background color
Definition: wex.h:578
void transparent(bool f=true)
enable/disable transparent background
Definition: wex.h:589
void line(const std::vector< int > &v)
Draw line between two points.
Definition: wex.h:616
void polygon(const std::vector< int > &v)
Draw Polygon.
Definition: wex.h:678
void circle(int x0, int y0, double r)
Draw circle.
Definition: wex.h:714
void fill(bool f=true)
Set filling option.
Definition: wex.h:604
shapes(PAINTSTRUCT &ps)
Constructor.
Definition: wex.h:530
void rectangle(const std::vector< int > &v)
Draw rectangle.
Definition: wex.h:639
void pixel(int x, int y)
Color a pixel.
Definition: wex.h:609
void color(int r, int g, int b)
Set color for drawings.
Definition: wex.h:559
A widget where user can select which panel to display by clicking a tab button.
Definition: wex.h:3300
void select(int i)
select panel to displayed
Definition: wex.h:3338
void tabChanging(std::function< void(int tabIndex)> f)
register function to call when tab is about to change This is only called when user changes the tab,...
Definition: wex.h:3372
void add(const std::string &tabname, gui &panel)
add panel that can be displayed
Definition: wex.h:3314
int select() const
zero-based index of panel currently selected
Definition: wex.h:3359
void tabChanged(std::function< void(int tabIndex)> f)
register function to call when tab has changed This is only called when user changes the tab,...
Definition: wex.h:3380
void tabWidth(int w)
set width of tab buttons
Definition: wex.h:3364
Generate events at regularly timed intervals.
Definition: wex.h:3191
timer(gui &g, int intervalmsecs, int id=1)
CTOR.
Definition: wex.h:3203
A class containing a database of the current gui elements.
Definition: wex.h:2940
gui * Add(gui *g)
Add new gui element.
Definition: wex.h:2978
static windex & get()
get reference to windex gui framework ( singleton )
Definition: wex.h:2950
mgui_t myGui
map of existing gui elements
Definition: wex.h:2994
static int startProcess(const std::string &command, std::string &error)
Start a command in its own process.
Definition: wex.h:3555
A structure containing the mouse status for event handlers.
Definition: wex.h:28