From d9ead46cca2243873d066c3246cb88b1a2ac3243 Mon Sep 17 00:00:00 2001 From: Sergey Svistunov Date: Fri, 3 Jan 2025 19:38:40 +0300 Subject: [PATCH] Add 'Capture last region' in screenshot dialog --- Source/Gui/Controls/HyperLinkControl.cpp | 12 ++++++++++++ Source/Gui/Controls/HyperLinkControl.h | 2 ++ Source/Gui/Dialogs/ScreenshotDlg.cpp | 22 ++++++++++++++++++++-- Source/Gui/Dialogs/ScreenshotDlg.h | 24 +++++++++++++++++++++--- Source/Gui/Dialogs/WizardDlg.cpp | 3 ++- Source/Gui/Dialogs/WizardDlg.h | 2 +- Source/Image Uploader.rc | 4 ++-- Source/resource.h | 3 ++- 8 files changed, 62 insertions(+), 10 deletions(-) diff --git a/Source/Gui/Controls/HyperLinkControl.cpp b/Source/Gui/Controls/HyperLinkControl.cpp index 3a3064e6..f25efba2 100644 --- a/Source/Gui/Controls/HyperLinkControl.cpp +++ b/Source/Gui/Controls/HyperLinkControl.cpp @@ -628,6 +628,18 @@ int CHyperLinkControl::selectedItemIndex() const { return selectedItemIndex_; } +int CHyperLinkControl::desiredHeight() const { + CClientDC dc(m_hWnd); + + int dpiY = dc.GetDeviceCaps(LOGPIXELSY); + + auto scaleY = [dpiY](int y) { + return MulDiv(y, dpiY, USER_DEFAULT_SCREEN_DPI); + }; + + return BottomY + scaleY(3); +} + BOOL CHyperLinkControl::OnSetCursor(CWindow/* wnd*/, UINT/* nHitTest*/, UINT/* message*/) { bool SubItem = false; diff --git a/Source/Gui/Controls/HyperLinkControl.h b/Source/Gui/Controls/HyperLinkControl.h index 982da902..8a34c624 100644 --- a/Source/Gui/Controls/HyperLinkControl.h +++ b/Source/Gui/Controls/HyperLinkControl.h @@ -98,6 +98,8 @@ class CHyperLinkControl : void HoverItem(int Index); HyperLinkControlItem* getItemByCommand(int command); int selectedItemIndex() const; + int desiredHeight() const; + protected: CAtlArray Items; int BottomY, SubItemRightY; diff --git a/Source/Gui/Dialogs/ScreenshotDlg.cpp b/Source/Gui/Dialogs/ScreenshotDlg.cpp index 14c62f0c..e2d0d133 100644 --- a/Source/Gui/Dialogs/ScreenshotDlg.cpp +++ b/Source/Gui/Dialogs/ScreenshotDlg.cpp @@ -24,20 +24,24 @@ #include "Func/MyUtils.h" #include "Core/ScreenCapture/MonitorEnumerator.h" #include "Core/Settings/WtlGuiSettings.h" +#include "Gui/Dialogs/WizardDlg.h" using namespace ScreenCapture; // CScreenshotDlg -CScreenshotDlg::CScreenshotDlg() : m_CaptureMode(cmFullScreen) +CScreenshotDlg::CScreenshotDlg(CWizardDlg* wizardDlg) + : m_CaptureMode(cmFullScreen), + wizardDlg_(wizardDlg) { m_WhiteBr.CreateSolidBrush(RGB(255,255,255)); } LRESULT CScreenshotDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { + DlgResize_Init(false, true, 0); // resizable dialog without "griper" auto* settings = ServiceLocator::instance()->settings(); CommandBox.SubclassWindow(GetDlgItem(IDC_COMMANDBOX)); - RECT ClientRect; + CRect ClientRect; GetClientRect(&ClientRect); CenterWindow(GetParent()); @@ -59,6 +63,10 @@ LRESULT CScreenshotDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BO CommandBox.AddString(TR("Capture Selected Window"), _T(" "), IDC_TOPWINDOWREGION, loadBigIcon(IDI_ICONWINDOWS)); CommandBox.AddString(TR("Capture Selected Object"), _T(" "), IDC_HWNDSREGION, loadBigIcon(IDI_ICONCONTROLS)); + if (wizardDlg_->hasLastScreenshotRegion()) { + CommandBox.AddString(TR("Capture Last Region"), _T(" "), IDC_LASTREGIONSCREENSHOT, loadBigIcon(IDI_ICONLASTREGION)); + } + SetWindowText(TR("Screen Capture")); TRC(IDC_DELAYLABEL, "Timeout:"); TRC(IDC_SECLABEL, "sec"); @@ -67,6 +75,11 @@ LRESULT CScreenshotDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BO SetDlgItemInt(IDC_DELAYEDIT, settings->ScreenshotSettings.Delay); SendDlgItemMessage(IDC_DELAYSPIN, UDM_SETRANGE, 0, (LPARAM) MAKELONG((short)30, (short)0) ); + CRect commandBoxRect; + CommandBox.GetClientRect(commandBoxRect); + int newHeight = ClientRect.Height() + std::max(0, CommandBox.desiredHeight() - commandBoxRect.Height()); + GuiTools::SetClientRect(m_hWnd, ClientRect.Width(), newHeight); + m_monitorCombobox.m_hWnd = GetDlgItem(IDC_MONITORSCOMBOBOX); int selectedIndex = 0; @@ -172,6 +185,11 @@ LRESULT CScreenshotDlg::OnBnClickedTopWindowRegion(WORD /*wNotifyCode*/, WORD /* return EndDialog(IDOK); } +LRESULT CScreenshotDlg::OnBnClickedLastRegion(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { + m_CaptureMode = cmLastRegion; + return EndDialog(IDOK); +} + CaptureMode CScreenshotDlg::captureMode() const { return m_CaptureMode; diff --git a/Source/Gui/Dialogs/ScreenshotDlg.h b/Source/Gui/Dialogs/ScreenshotDlg.h index a9021ec1..49e396f3 100644 --- a/Source/Gui/Dialogs/ScreenshotDlg.h +++ b/Source/Gui/Dialogs/ScreenshotDlg.h @@ -30,6 +30,7 @@ #include "Gui/Controls/hyperlinkcontrol.h" #include "Core/ScreenCapture.h" #include "Gui/Controls/DialogIndirect.h" +#include "Gui/WizardCommon.h" #define IDC_FULLSCREEN WM_USER + 219 #define IDC_VIEWSETTINGS WM_USER + 220 @@ -38,13 +39,15 @@ #define IDC_HWNDSREGION WM_USER + 223 #define IDC_TOPWINDOWREGION WM_USER + 224 +class CWizardDlg; class CScreenshotDlg : public /*aero::*/CCustomDialogIndirectImpl, - public CWinDataExchange + public CWinDataExchange, + public CDialogResize { public: - CScreenshotDlg(); + explicit CScreenshotDlg(CWizardDlg* wizardDlg); ~CScreenshotDlg() = default; ScreenCapture::CaptureMode captureMode() const; enum { IDD = IDD_SCREENSHOTDLG }; @@ -63,8 +66,21 @@ class CScreenshotDlg : COMMAND_HANDLER(IDC_FREEFORMREGION, BN_CLICKED, OnBnClickedFreeFormRegion) COMMAND_HANDLER(IDC_HWNDSREGION, BN_CLICKED, OnBnClickedWindowHandlesRegion) COMMAND_HANDLER(IDC_TOPWINDOWREGION, BN_CLICKED, OnBnClickedTopWindowRegion) + COMMAND_HANDLER(IDC_LASTREGIONSCREENSHOT, BN_CLICKED, OnBnClickedLastRegion) + CHAIN_MSG_MAP(CDialogResize) END_MSG_MAP() - + + BEGIN_DLGRESIZE_MAP(CScreenshotDlg) + DLGRESIZE_CONTROL(IDC_COMMANDBOX, DLSZ_SIZE_X | DLSZ_SIZE_Y) + DLGRESIZE_CONTROL(IDC_DELAYLABEL, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_DELAYEDIT, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_DELAYSPIN, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_GROUPBOX, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_SECLABEL, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_OPENSCREENSHOTINEDITORCHECKBOX, DLSZ_MOVE_Y) + DLGRESIZE_CONTROL(IDC_MONITORSCOMBOBOX, DLSZ_MOVE_Y) + END_DLGRESIZE_MAP() + // Handler prototypes: // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); @@ -83,11 +99,13 @@ class CScreenshotDlg : LRESULT OnClickedActiveWindowCapture(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnBnClickedRegionselect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnBnClickedTopWindowRegion(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnBnClickedLastRegion(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); CBrush m_WhiteBr; CHyperLinkControl CommandBox; ScreenCapture::CaptureMode m_CaptureMode; CComboBox m_monitorCombobox; + CWizardDlg* wizardDlg_; }; #endif // SCREENSHOTDLG_H diff --git a/Source/Gui/Dialogs/WizardDlg.cpp b/Source/Gui/Dialogs/WizardDlg.cpp index b3f9abf8..1086ed70 100644 --- a/Source/Gui/Dialogs/WizardDlg.cpp +++ b/Source/Gui/Dialogs/WizardDlg.cpp @@ -71,6 +71,7 @@ #include "Core/WinServerIconCache.h" #include "Core/FileTypeCheckTask.h" #include "Gui/Dialogs/FileFormatCheckErrorDlg.h" +#include "Gui/Dialogs/ScreenshotDlg.h" using namespace Gdiplus; namespace @@ -1688,7 +1689,7 @@ bool CWizardDlg::funcImportVideo() bool CWizardDlg::funcScreenshotDlg() { - CScreenshotDlg dlg; + CScreenshotDlg dlg(this); if(dlg.DoModal(m_hWnd) != IDOK) return false; CommonScreenshot(dlg.captureMode()); diff --git a/Source/Gui/Dialogs/WizardDlg.h b/Source/Gui/Dialogs/WizardDlg.h index eb47d352..c1154c11 100644 --- a/Source/Gui/Dialogs/WizardDlg.h +++ b/Source/Gui/Dialogs/WizardDlg.h @@ -30,7 +30,6 @@ #include "HotkeySettings.h" #include "Core/ScreenCapture.h" #include "resource.h" // main symbols -#include "ScreenshotDlg.h" #include "Gui/Dialogs/UpdateDlg.h" #include "Core/ProgramWindow.h" #include "Core/TaskDispatcher.h" @@ -41,6 +40,7 @@ #include "Gui/Controls/DialogIndirect.h" #include "Gui/Components/DragndropOverlay.h" #include "Gui/WizardCommon.h" +#include "Gui/Dialogs/RegionSelect.h" class WinToastHandler; constexpr int ID_PASTE = 9888; diff --git a/Source/Image Uploader.rc b/Source/Image Uploader.rc index aafdfda4..0756dbde 100644 --- a/Source/Image Uploader.rc +++ b/Source/Image Uploader.rc @@ -178,7 +178,7 @@ BEGIN END IDD_SCREENSHOTDLG DIALOGEX 0, 0, 195, 226 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME CAPTION "Ñêðèíøîò" FONT 8, "MS Shell Dlg", 400, 0, 0xCC BEGIN @@ -189,7 +189,7 @@ BEGIN LTEXT "#ñ",IDC_SECLABEL,114,176,26,8 CONTROL "#Open screenshot in editor",IDC_OPENSCREENSHOTINEDITORCHECKBOX, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,190,164,10 - GROUPBOX "",IDC_STATIC,-4,163,241,61 + GROUPBOX "",IDC_GROUPBOX,-4,163,241,61 COMBOBOX IDC_MONITORSCOMBOBOX,10,207,141,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP END diff --git a/Source/resource.h b/Source/resource.h index 57d7efcf..727bd65c 100644 --- a/Source/resource.h +++ b/Source/resource.h @@ -774,6 +774,7 @@ #define IDC_FILESCANNOTBEUPLOADED 1345 #define IDC_SECUREDCONNECTIONLABEL 1346 #define IDC_SECUREDCONNECTIONCOMBOBOX 1347 +#define IDC_GROUPBOX 1348 #define IDR_bottomLeftShadow 15001 #define IDR_bottomRightShadow 15002 #define IDR_bottomShadow 15003 @@ -821,7 +822,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 347 #define _APS_NEXT_COMMAND_VALUE 32821 -#define _APS_NEXT_CONTROL_VALUE 1348 +#define _APS_NEXT_CONTROL_VALUE 1349 #define _APS_NEXT_SYMED_VALUE 128 #endif #endif