From f6394e4fd0a52b5952d08cb7b1062d425412ccd5 Mon Sep 17 00:00:00 2001 From: makuke1234 Date: Thu, 20 Jan 2022 13:14:57 +0200 Subject: [PATCH] Use GDI wrapper --- src/mainwindow.cpp | 43 ++++++++++++++++++++++--------------------- src/mainwindow.hpp | 12 ++++++++---- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ba52bec..d9b0f7d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -101,6 +101,23 @@ pdfv::MainWindow::MainWindow() noexcept FF_DONTCARE, L"Segoe UI" ); + + this->m_defaultFontBold = ::CreateFontW( + dip(15, dpi.y), + 0, + 0, + 0, + FW_BOLD, + false, + false, + false, + DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, + FF_DONTCARE, + L"Segoe UI" + ); } pdfv::MainWindow::~MainWindow() noexcept @@ -121,27 +138,6 @@ pdfv::MainWindow::~MainWindow() noexcept ::DestroyWindow(this->m_hwnd); this->m_hwnd = nullptr; } - if (this->m_defaultFont != nullptr) - { - ::DeleteObject(this->m_defaultFont); - this->m_defaultFont = nullptr; - } - - if (this->m_redBrush != nullptr) - { - ::DeleteObject(this->m_redBrush); - this->m_redBrush = nullptr; - } - if (this->m_brightRedBrush != nullptr) - { - ::DeleteObject(this->m_brightRedBrush); - this->m_brightRedBrush = nullptr; - } - if (this->m_darkRedBrush != nullptr) - { - ::DeleteObject(this->m_darkRedBrush); - this->m_darkRedBrush = nullptr; - } } [[nodiscard]] bool pdfv::MainWindow::init(HINSTANCE hinst, int argc, wchar_t ** argv) noexcept @@ -426,6 +422,11 @@ LRESULT pdfv::MainWindow::wOnDrawItem(DRAWITEMSTRUCT * dis) noexcept (this->m_closeButtonDown ? this->m_darkRedBrush : this->m_redBrush) : this->m_brightRedBrush ); + + // Draw text on top of close button + ::SetTextColor(hdc, RGB(255, 255, 255)); + ::SelectObject(hdc, this->m_defaultFontBold); + ::DrawTextW(hdc, L"X", 1, &closeR, DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_NOCLIP); // Double-buffering action diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 0f173f2..3359d9c 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -31,14 +31,14 @@ namespace pdfv HWND m_hwnd{ nullptr }; WNDCLASSEXW m_wcex{}; std::wstring m_title; - HFONT m_defaultFont{ nullptr }; + w::GDI m_defaultFont{ nullptr }, m_defaultFontBold{ nullptr }; bool m_helpAvailable{ true }; pdfv::Tabs m_tabs; pdfv::OpenDialog m_openDialog{ 2048 }; - HBRUSH m_redBrush{ ::CreateSolidBrush(RGB(237, 28, 36)) }; - HBRUSH m_brightRedBrush{ ::CreateSolidBrush(RGB(255, 128, 128)) }; - HBRUSH m_darkRedBrush{ ::CreateSolidBrush(RGB(200, 0, 0)) }; + w::GDI m_redBrush{ ::CreateSolidBrush(RGB(237, 28, 36)) }; + w::GDI m_brightRedBrush{ ::CreateSolidBrush(RGB(255, 128, 128)) }; + w::GDI m_darkRedBrush{ ::CreateSolidBrush(RGB(200, 0, 0)) }; std::atomic m_highlighted{ false }; std::atomic m_highlightedIdx{ 0 }; HANDLE m_moveThread{ nullptr }; @@ -102,6 +102,10 @@ namespace pdfv { return this->m_defaultFont; } + [[nodiscard]] constexpr const HFONT & getDefaultFontBold() const noexcept + { + return this->m_defaultFontBold; + } // // A wrapper function to display messages with this window as the