Skip to content

Commit

Permalink
Add 'Capture last region' in screenshot dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Jan 3, 2025
1 parent 182becc commit d9ead46
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Source/Gui/Controls/HyperLinkControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Source/Gui/Controls/HyperLinkControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class CHyperLinkControl :
void HoverItem(int Index);
HyperLinkControlItem* getItemByCommand(int command);
int selectedItemIndex() const;
int desiredHeight() const;

protected:
CAtlArray<HyperLinkControlItem> Items;
int BottomY, SubItemRightY;
Expand Down
22 changes: 20 additions & 2 deletions Source/Gui/Dialogs/ScreenshotDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<WtlGuiSettings>();
CommandBox.SubclassWindow(GetDlgItem(IDC_COMMANDBOX));
RECT ClientRect;
CRect ClientRect;
GetClientRect(&ClientRect);
CenterWindow(GetParent());

Expand All @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 21 additions & 3 deletions Source/Gui/Dialogs/ScreenshotDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,13 +39,15 @@
#define IDC_HWNDSREGION WM_USER + 223
#define IDC_TOPWINDOWREGION WM_USER + 224

class CWizardDlg;

class CScreenshotDlg :
public /*aero::*/CCustomDialogIndirectImpl<CScreenshotDlg>,
public CWinDataExchange<CScreenshotDlg>
public CWinDataExchange<CScreenshotDlg>,
public CDialogResize<CScreenshotDlg>
{
public:
CScreenshotDlg();
explicit CScreenshotDlg(CWizardDlg* wizardDlg);
~CScreenshotDlg() = default;
ScreenCapture::CaptureMode captureMode() const;
enum { IDD = IDD_SCREENSHOTDLG };
Expand All @@ -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<CScreenshotDlg>)
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);
Expand All @@ -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
3 changes: 2 additions & 1 deletion Source/Gui/Dialogs/WizardDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion Source/Gui/Dialogs/WizardDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Source/Image Uploader.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion Source/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit d9ead46

Please sign in to comment.