From 7821233a5260afbaa5ad73936681afc02dfe7365 Mon Sep 17 00:00:00 2001 From: Grayson Riffe Date: Tue, 5 Sep 2023 14:55:51 -0500 Subject: [PATCH] Save main dialog location and rearrange --- WinChat/WinChat.rc | Bin 6816 -> 6842 bytes WinChat/src/Application.cpp | 39 +++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/WinChat/WinChat.rc b/WinChat/WinChat.rc index 953515857615692e0468923ef5a48027c9f157a7..e402b59cfb79e57d9edf284fb44f3ccf9a2032c9 100644 GIT binary patch delta 114 zcmZ2ry32G!4F|I!gTdx{j>C+MCX-KdSx>Ix@?kb(Fq?dqYbLWLgTdsx+>(=9xI>`q zVtxY#9R@=nGy&4aKy|-)wI}EBykRzBu$UapI}xn+J?}(DgUyY6*-Xp^491fKMZ`C= I3C`jK0A!ROdjJ3c delta 118 zcmdmGy1;Zp4F|IkgVE-Cj>C-1W()?C&vIE#uH*7yHfOK^vS+dyG8ixzP0r-bg|cpP z7xSAj=r9-pp$U*S2I{Hg`N;{?3+7o)=I1k(this))) { + MainDlgInput* input = new MainDlgInput{ this, -1, -1 }; + while (result = DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOGMAIN), nullptr, (DLGPROC)mainDlgProc, reinterpret_cast(input))) { + //Then create a Chat with the collected input... MainDlgOutput* output = reinterpret_cast(result); - const auto [address, screenname] = *output; + const auto [address, screenname, x, y] = *output; delete output; { Chat chat(address, screenname); chat.run(); } + + //And repeat until the user exits from the main dialog. + input = new MainDlgInput{ this, x, y }; } } @@ -46,17 +57,23 @@ namespace wc { switch (msg) { case WM_INITDIALOG: { - app = reinterpret_cast(lParam); + MainDlgInput* in = reinterpret_cast(lParam); + auto [appTemp, xPos, yPos] = *in; + app = appTemp; + delete in; SetWindowText(dlg, app->m_appName.c_str()); SendMessage(dlg, WM_SETICON, ICON_BIG, reinterpret_cast(LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICONMAIN)))); - POINT pt = { }; - GetCursorPos(&pt); - MONITORINFO mi = { }; - mi.cbSize = sizeof(mi); - GetMonitorInfo(MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST), &mi); - SetWindowPos(dlg, nullptr, mi.rcMonitor.left + 100, mi.rcMonitor.top + 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + if (xPos < 0) { + POINT pt = { }; + GetCursorPos(&pt); + MONITORINFO mi = { }; + mi.cbSize = sizeof(mi); + GetMonitorInfo(MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST), &mi); + xPos = mi.rcMonitor.left + 100, yPos = mi.rcMonitor.top + 100; + } + SetWindowPos(dlg, nullptr, xPos, yPos, 0, 0, SWP_NOSIZE | SWP_NOZORDER); SetDlgItemText(dlg, IDC_STATICTITLE, app->m_appName.c_str()); LOGFONT lFont = { }; @@ -81,7 +98,9 @@ namespace wc { screenname.resize(GetWindowTextLength(GetDlgItem(dlg, IDC_EDITSCREENNAME))); GetDlgItemText(dlg, IDC_EDITSCREENNAME, screenname.data(), static_cast(screenname.size() + 1)); - MainDlgOutput* out = new MainDlgOutput{ address, screenname }; + RECT dlgRect = { }; + GetWindowRect(dlg, &dlgRect); + MainDlgOutput* out = new MainDlgOutput{ address, screenname, dlgRect.left, dlgRect.top }; EndDialog(dlg, reinterpret_cast(out)); return TRUE; }