Add address box and cleanup

This commit is contained in:
Grayson Riffe 2023-08-31 15:14:41 -05:00
parent 163a583fa4
commit 032cd334ae
4 changed files with 22 additions and 22 deletions

Binary file not shown.

View File

@ -7,6 +7,7 @@
#define IDC_STATICTITLE 1001 #define IDC_STATICTITLE 1001
#define IDC_BUTTONEXIT 1003 #define IDC_BUTTONEXIT 1003
#define IDC_BUTTONCONNECT 1005 #define IDC_BUTTONCONNECT 1005
#define IDC_EDITADDRESS 1006
#define ID_FILE_EXIT 40001 #define ID_FILE_EXIT 40001
#define ID_HELP_ABOUT 40002 #define ID_HELP_ABOUT 40002
@ -16,7 +17,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 106 #define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40003 #define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1006 #define _APS_NEXT_CONTROL_VALUE 1007
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif

View File

@ -3,6 +3,8 @@
#include <iostream> #include <iostream>
#include <format> #include <format>
#include <CommCtrl.h>
#include "../resource.h" #include "../resource.h"
//This pragma enables visual styles, which makes dialogs and their controls look modern. //This pragma enables visual styles, which makes dialogs and their controls look modern.
@ -12,15 +14,14 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
namespace wc { namespace wc {
Application::Application(std::string& appName, std::string& appVersion) Application::Application(std::string& appName, std::string& appVersion)
: m_appName(appName) : m_appName(appName.begin(), appName.end())
, m_appVersion(appVersion) , m_appVersion(appVersion.begin(), appVersion.end())
{ {
std::cout << std::format("{} {}", m_appName, m_appVersion); std::wcout << std::format(L"{} {}", m_appName, m_appVersion);
} }
void Application::run() { void Application::run() {
HINSTANCE hInst = GetModuleHandle(NULL); DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOGMAIN), nullptr, (DLGPROC)dlgProc, reinterpret_cast<LPARAM>(this));
DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOGMAIN), nullptr, (DLGPROC)dlgProc, reinterpret_cast<LPARAM>(this));
} }
BOOL CALLBACK Application::dlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK Application::dlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) {
@ -30,40 +31,37 @@ namespace wc {
case WM_INITDIALOG: { case WM_INITDIALOG: {
app = reinterpret_cast<Application*>(lParam); app = reinterpret_cast<Application*>(lParam);
std::wstring appName(app->m_appName.begin(), app->m_appName.end()); SetWindowText(dlg, app->m_appName.c_str());
SetWindowText(dlg, appName.c_str());
POINT pt = { }; POINT pt = { };
GetCursorPos(&pt); GetCursorPos(&pt);
HMONITOR mon = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi = { }; MONITORINFO mi = { };
mi.cbSize = sizeof(mi); mi.cbSize = sizeof(mi);
GetMonitorInfo(mon, &mi); GetMonitorInfo(MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST), &mi);
SetWindowPos(dlg, nullptr, mi.rcMonitor.left + 100, mi.rcMonitor.top + 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER); SetWindowPos(dlg, nullptr, mi.rcMonitor.left + 100, mi.rcMonitor.top + 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
SetDlgItemText(dlg, IDC_STATICTITLE, appName.c_str()); SetDlgItemText(dlg, IDC_STATICTITLE, app->m_appName.c_str());
LOGFONT lFont = { }; LOGFONT lFont = { };
lFont.lfHeight = 50; lFont.lfHeight = 50;
HFONT font = CreateFontIndirect(&lFont); HFONT font = CreateFontIndirect(&lFont);
SendMessage(GetDlgItem(dlg, IDC_STATICTITLE), WM_SETFONT, reinterpret_cast<LPARAM>(font), NULL); SendMessage(GetDlgItem(dlg, IDC_STATICTITLE), WM_SETFONT, reinterpret_cast<LPARAM>(font), NULL);
SendDlgItemMessage(dlg, IDC_EDITADDRESS, EM_SETCUEBANNER, TRUE, reinterpret_cast<LPARAM>(L"Address"));
return TRUE; return TRUE;
} }
case WM_COMMAND: case WM_COMMAND:
switch (LOWORD(wParam)) { switch (LOWORD(wParam)) {
case IDC_BUTTONCONNECT: case IDC_BUTTONCONNECT: {
std::wstring address;
address.resize(GetWindowTextLength(GetDlgItem(dlg, IDC_EDITADDRESS)) + 1);
GetDlgItemText(dlg, IDC_EDITADDRESS, address.data(), static_cast<int>(address.size()));
MessageBox(dlg, std::format(L"Address: {}", address).c_str(), L"Alert", MB_OK);
return TRUE; return TRUE;
}
case ID_HELP_ABOUT: { case ID_HELP_ABOUT: {
std::wstring appName(app->m_appName.begin(), app->m_appName.end()); MessageBox(dlg, std::format(L"{} {}\nGrayson Riffe 2023", app->m_appName, app->m_appVersion).c_str(), L"About", MB_OK);
std::wstring appVer(app->m_appVersion.begin(), app->m_appVersion.end());
std::wstring aboutStr = std::format(L"{} {}\nGrayson Riffe 2023", appName, appVer);
MessageBox(dlg, aboutStr.c_str(), L"About", MB_OK);
return TRUE; return TRUE;
} }

View File

@ -12,9 +12,10 @@ namespace wc {
~Application(); ~Application();
private: private:
static BOOL CALLBACK dlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK dlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam);
const std::string m_appName; const std::wstring m_appName;
const std::string m_appVersion; const std::wstring m_appVersion;
}; };
} }