Skip to content

Commit

Permalink
make Ctrl+C pressed in the about dialog copy the version string to th…
Browse files Browse the repository at this point in the history
…e clipboard
  • Loading branch information
stefankueng committed Mar 30, 2024
1 parent 3dea186 commit 8ae410b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
26 changes: 21 additions & 5 deletions src/AboutDlg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BowPad.
//
// Copyright (C) 2013, 2015-2017, 2020-2022 - Stefan Kueng
// Copyright (C) 2013, 2015-2017, 2020-2022, 2024 - Stefan Kueng
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -21,8 +21,11 @@
#include "version.h"
#include "Theme.h"
#include "ResString.h"
#include "../ext/sktoolslib/StringUtils.h"

#include <string>
#include <Commdlg.h>
#include <format>

CAboutDlg::CAboutDlg(HWND hParent)
: m_hParent(hParent)
Expand All @@ -45,13 +48,12 @@ LRESULT CAboutDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
CTheme::Instance().SetThemeForDialog(*this, CTheme::Instance().IsDarkTheme());
// initialize the controls
m_link.ConvertStaticToHyperlink(hwndDlg, IDC_WEBLINK, L"http://tools.stefankueng.com");
wchar_t verbuf[1024] = {0};
#ifdef _WIN64
swprintf_s(verbuf, _countof(verbuf), L"BowPad version %d.%d.%d.%d (64-bit)", BP_VERMAJOR, BP_VERMINOR, BP_VERMICRO, BP_VERBUILD);
m_version = std::format(L"BowPad version {}.{}.{}.{} (64-bit)", BP_VERMAJOR, BP_VERMINOR, BP_VERMICRO, BP_VERBUILD);
#else
swprintf_s(verbuf, _countof(verbuf), L"BowPad version %d.%d.%d.%d", BP_VERMAJOR, BP_VERMINOR, BP_VERMICRO, BP_VERBUILD);
m_version = std::format(L"BowPad version {}.{}.{}.{}", BP_VERMAJOR, BP_VERMINOR, BP_VERMICRO, BP_VERBUILD);
#endif
SetDlgItemText(hwndDlg, IDC_VERSIONLABEL, verbuf);
SetDlgItemText(hwndDlg, IDC_VERSIONLABEL, m_version.c_str());
SetFocus(GetDlgItem(hwndDlg, IDOK));
}
return FALSE;
Expand Down Expand Up @@ -88,3 +90,17 @@ LRESULT CAboutDlg::DoCommand(int id)
}
return 1;
}

bool CAboutDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
auto bCtrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
if (bCtrl && pMsg->wParam == 'C')
{
WriteAsciiStringToClipboard(m_version.c_str(), m_hwnd);
return true;
}
}
return false;
}
17 changes: 10 additions & 7 deletions src/AboutDlg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BowPad.
//
// Copyright (C) 2013, 2016, 2021 - Stefan Kueng
// Copyright (C) 2013, 2016, 2021, 2024 - Stefan Kueng
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -27,13 +27,16 @@ class CAboutDlg : public CDialog
CAboutDlg(HWND hParent);
~CAboutDlg();

void SetHiddenWnd(HWND hWnd) {m_hHiddenWnd = hWnd;}
void SetHiddenWnd(HWND hWnd) { m_hHiddenWnd = hWnd; }

protected:
LRESULT CALLBACK DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) override;
LRESULT DoCommand(int id);
LRESULT CALLBACK DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) override;
LRESULT DoCommand(int id);
bool PreTranslateMessage(MSG* pMsg) override;

private:
HWND m_hParent;
HWND m_hHiddenWnd;
CHyperLink m_link;
HWND m_hParent;
HWND m_hHiddenWnd;
CHyperLink m_link;
std::wstring m_version;
};
2 changes: 1 addition & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ STDMETHODIMP CMainWindow::Execute(
void CMainWindow::About() const
{
CAboutDlg dlg(*this);
dlg.DoModal(g_hRes, IDD_ABOUTBOX, *this);
dlg.DoModal(g_hRes, IDD_ABOUTBOX, *this, NULL);
}

void CMainWindow::ShowCommandPalette()
Expand Down

0 comments on commit 8ae410b

Please sign in to comment.