From a94eb4d44b2e34e7aacd271f0eced98bd23f3795 Mon Sep 17 00:00:00 2001 From: luiscuenca <luiscuenca@outboxcode.com> Date: Fri, 5 Jul 2019 11:09:36 -0700 Subject: [PATCH] Allow the launcher window to be moved --- launchers/win32/LauncherDlg.cpp | 42 +++++++++++++++++++++++++++++---- launchers/win32/LauncherDlg.h | 16 +++++++++---- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/launchers/win32/LauncherDlg.cpp b/launchers/win32/LauncherDlg.cpp index c308efe3cc..a8fdf8912b 100644 --- a/launchers/win32/LauncherDlg.cpp +++ b/launchers/win32/LauncherDlg.cpp @@ -119,15 +119,22 @@ BOOL CLauncherDlg::OnInitDialog() { return TRUE; } +POINT CLauncherDlg::getMouseCoords(MSG* pMsg) { + POINT pos; + pos.x = (int)(short)LOWORD(pMsg->lParam); + pos.y = (int)(short)HIWORD(pMsg->lParam); + return pos; +} + BOOL CLauncherDlg::PreTranslateMessage(MSG* pMsg) { - if ((pMsg->message == WM_KEYDOWN)) - { + switch (pMsg->message) { + case WM_KEYDOWN: if (pMsg->wParam == 'A' && GetKeyState(VK_CONTROL) < 0) { CWnd* wnd = GetFocus(); CWnd* myWnd = this->GetDlgItem(IDC_ORGNAME); if (wnd && (wnd == this->GetDlgItem(IDC_ORGNAME) || - wnd == this->GetDlgItem(IDC_USERNAME) || - wnd == this->GetDlgItem(IDC_PASSWORD))) { + wnd == this->GetDlgItem(IDC_USERNAME) || + wnd == this->GetDlgItem(IDC_PASSWORD))) { ((CEdit*)wnd)->SetSel(0, -1); } return TRUE; @@ -135,6 +142,33 @@ BOOL CLauncherDlg::PreTranslateMessage(MSG* pMsg) { OnNextClicked(); return TRUE; } + break; + case WM_LBUTTONDOWN: + if (pMsg->hwnd == GetSafeHwnd()) { + _draggingWindow = true; + _dragOffset = getMouseCoords(pMsg); + SetCapture(); + } + break; + case WM_LBUTTONUP: + if (_draggingWindow) { + ReleaseCapture(); + _draggingWindow = false; + } + break; + case WM_MOUSEMOVE: + if (_draggingWindow) { + POINT pos = getMouseCoords(pMsg); + RECT windowRect; + GetWindowRect(&windowRect); + int width = windowRect.right - windowRect.left; + int height = windowRect.bottom - windowRect.top; + ClientToScreen(&pos); + MoveWindow(pos.x - _dragOffset.x, pos.y - _dragOffset.y, width, height, FALSE); + } + break; + default: + break; } return CDialog::PreTranslateMessage(pMsg); } diff --git a/launchers/win32/LauncherDlg.h b/launchers/win32/LauncherDlg.h index 9d34fe5503..4d830c2e21 100644 --- a/launchers/win32/LauncherDlg.h +++ b/launchers/win32/LauncherDlg.h @@ -60,12 +60,18 @@ protected: DrawStep _drawStep { DrawStep::DrawLogo }; BOOL getTextFormat(int ResID, TextFormat& formatOut); void showWindows(std::vector<CStatic*> windows, bool show); + POINT getMouseCoords(MSG* pMsg); - bool _isConsoleRunning{ false }; - bool _isInstalling{ false }; - bool _isFirstDraw{ false }; - bool _showSplash{ true }; - int _splashStep{ 0 }; + + bool _isConsoleRunning { false }; + bool _isInstalling { false }; + bool _isFirstDraw { false }; + bool _showSplash { true }; + + bool _draggingWindow { false }; + POINT _dragOffset; + + int _splashStep { 0 }; float _logoRotation { 0.0f }; HICON m_hIcon;