Refactor HWND management and modularize initialization

Centralized HWND handling into a dedicated `hwnd_module` for improved clarity and modularity. Updated `toolboxWindow` and `optionWindow` to use the new module abstraction. Adjusted related initialization code for better structure and maintainability.
This commit is contained in:
2025-01-19 19:17:35 +01:00
parent c93758f732
commit 9e3c9f4d0e
9 changed files with 52 additions and 26 deletions
+11 -2
View File
@@ -3,13 +3,21 @@
#include <windows.h>
optionWindow::optionWindow(std::shared_ptr<saucer::application>& app)
: m_app(app), m_webview({.application = app}) {}
: m_app(app), m_webview({.application = app}), m_hwnd()
{
}
void optionWindow::initialize() {
// Modul hinzufügen
configureWindow();
loadResources();
}
void optionWindow::setHWND(HWND hwnd)
{
m_hwnd = hwnd;
}
void optionWindow::configureWindow() {
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
@@ -23,7 +31,8 @@ void optionWindow::configureWindow() {
int xPos = screenWidth - windowWidth;
int yPos = screenHeight - 42 - windowHeight;
if (HWND hwnd = m_webview.module<hwnd_module>().get_hwnd()) {
// HWND über das Modul abrufen
if (HWND hwnd = m_hwnd) {
SetWindowPos(hwnd, nullptr, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
}
+8 -5
View File
@@ -1,14 +1,17 @@
#include "toolboxWindow.h"
#include "optionWindow.h"
#include <iostream>
#include <windows.h>
#include <nlohmann/json.hpp>
#include <cppcodec/base64_rfc4648.hpp>
ToolboxWindow::ToolboxWindow(std::shared_ptr<saucer::application>& app)
: m_webview({.application = app}), m_app(app) {}
: m_webview({.application = app}), m_hwnd_module(&m_webview.add_module<hwnd_module>()), m_app(app)
{
}
void ToolboxWindow::initialize() {
m_hwnd_module = &m_webview.add_module<hwnd_module>();
m_hwnd = m_hwnd_module->get_hwnd();
ensureToolboxInUserPath();
fillToolboxMenu();
configureWindow();
@@ -62,13 +65,13 @@ void ToolboxWindow::configureWindow() {
const int xPos = screenWidth - windowWidth;
const int yPos = screenHeight - 42 - windowHeight;
if (const HWND hwnd = m_webview.module<hwnd_module>().get_hwnd()) {
if (const HWND hwnd = m_hwnd) {
SetWindowPos(hwnd, nullptr, xPos, yPos, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
}
void ToolboxWindow::moveWindowTo(int x, int y) {
if (const HWND hwnd = m_webview.module<hwnd_module>().get_hwnd()) {
if (const HWND hwnd = m_hwnd) {
SetWindowPos(hwnd, nullptr, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
}
@@ -384,7 +387,7 @@ void ToolboxWindow::centerWindow() {
int windowWidth = 0;
int windowHeight = 0;
if (const HWND hwnd = m_webview.module<hwnd_module>().get_hwnd()) {
if (const HWND hwnd = m_hwnd) {
RECT rect;
if (GetWindowRect(hwnd, &rect)) {
windowWidth = rect.right - rect.left;