From 163a583fa438c644634d9b06799ad4d3493b890c Mon Sep 17 00:00:00 2001 From: Grayson Riffe Date: Wed, 30 Aug 2023 17:44:27 -0500 Subject: [PATCH] Add dialog functionality --- WinChat/WinChat.rc | Bin 4654 -> 5446 bytes WinChat/WinChat.vcxproj | 3 +- WinChat/resource.h | 13 +++++--- WinChat/src/Application.cpp | 64 +++++++++++++++++++++++++++++++++--- WinChat/src/Application.h | 2 +- 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/WinChat/WinChat.rc b/WinChat/WinChat.rc index d9cec9efb45b8f76eca4969822c992e17941f096..ba893cd19d826d3b8779e4df2096b3675e9e7962 100644 GIT binary patch delta 683 zcmaJ<-AV#M7(LOSt*bX7BHgI{T%;hbKOsc0u3HMONQ%7mc6HNW)opvMk)7 z&A7lhIz+}*wZ-Z@vHOfFc`fy=klSJ=&Yp5G)SO~(Ct678T6Dw49j^aju~8?x#2ZK> zJBDusa?D6xmo=&WQexl_h^zSz@#cM*=+dG7IBT$%tQhEx=`=EZ)8|Z0EPeIwk*b$- zc+@t!%Ay1kYL<5WVG`|=meNQO(U(Fs8d0M$HRhvO!!{4xBx6)u>apaoQXSGJ&aD~Q za!hMXR(B91E-lR#4_ZJxYjYekLD@lrJ0(5^o2#K+!t@0rVRFg%tzV>e6SuDZ@??Dz kXT0RDdog2*QdNzRt6ZdFnFW>74EI{tVs>NZ-L4p4_Bg9Vs2WiXwb$YrhX4Ahgy zkj#(@)Cp7T47AIS!I{AoXrm5;5rZiZgY-i5NKSsk6(VcMV8CDu6g2^g>Ht|F6&4J< z3|v56ev<|Hc2Ab#S%lU7=Xsi0je)w2CeIfTot(q##cal4xp^nAFC$jvlKjD&d4#N( E0o1%Q761SM diff --git a/WinChat/WinChat.vcxproj b/WinChat/WinChat.vcxproj index c10d3f6..162b604 100644 --- a/WinChat/WinChat.vcxproj +++ b/WinChat/WinChat.vcxproj @@ -80,10 +80,11 @@ true - Console + Windows true true true + mainCRTStartup PreBuild.bat diff --git a/WinChat/resource.h b/WinChat/resource.h index 11c7b92..6f8dc89 100644 --- a/WinChat/resource.h +++ b/WinChat/resource.h @@ -2,16 +2,21 @@ // Microsoft Visual C++ generated include file. // Used by WinChat.rc // -#define IDD_MAINDIALOG 101 +#define IDD_DIALOGMAIN 101 +#define IDR_MENUMAIN 104 #define IDC_STATICTITLE 1001 +#define IDC_BUTTONEXIT 1003 +#define IDC_BUTTONCONNECT 1005 +#define ID_FILE_EXIT 40001 +#define ID_HELP_ABOUT 40002 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 103 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1002 +#define _APS_NEXT_RESOURCE_VALUE 106 +#define _APS_NEXT_COMMAND_VALUE 40003 +#define _APS_NEXT_CONTROL_VALUE 1006 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/WinChat/src/Application.cpp b/WinChat/src/Application.cpp index 839c019..303be68 100644 --- a/WinChat/src/Application.cpp +++ b/WinChat/src/Application.cpp @@ -1,28 +1,82 @@ #include "Application.h" +#include +#include + #include "../resource.h" +//This pragma enables visual styles, which makes dialogs and their controls look modern. +#pragma comment(linker,"\"/manifestdependency:type='win32' \ +name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ +processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + namespace wc { Application::Application(std::string& appName, std::string& appVersion) : m_appName(appName) , m_appVersion(appVersion) { - std::printf("%s %s\n", m_appName.c_str(), m_appVersion.c_str()); + std::cout << std::format("{} {}", m_appName, m_appVersion); } void Application::run() { HINSTANCE hInst = GetModuleHandle(NULL); - DialogBox(hInst, MAKEINTRESOURCE(IDD_MAINDIALOG), nullptr, (DLGPROC)dlgProc); + DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOGMAIN), nullptr, (DLGPROC)dlgProc, reinterpret_cast(this)); } - BOOL CALLBACK Application::dlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + BOOL CALLBACK Application::dlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) { + static Application* app = nullptr; + switch (msg) { - case WM_INITDIALOG: + case WM_INITDIALOG: { + app = reinterpret_cast(lParam); + + std::wstring appName(app->m_appName.begin(), app->m_appName.end()); + SetWindowText(dlg, appName.c_str()); + + POINT pt = { }; + GetCursorPos(&pt); + HMONITOR mon = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); + MONITORINFO mi = { }; + mi.cbSize = sizeof(mi); + GetMonitorInfo(mon, &mi); + + SetWindowPos(dlg, nullptr, mi.rcMonitor.left + 100, mi.rcMonitor.top + 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + + SetDlgItemText(dlg, IDC_STATICTITLE, appName.c_str()); + + LOGFONT lFont = { }; + lFont.lfHeight = 50; + + HFONT font = CreateFontIndirect(&lFont); + SendMessage(GetDlgItem(dlg, IDC_STATICTITLE), WM_SETFONT, reinterpret_cast(font), NULL); return TRUE; + } + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_BUTTONCONNECT: + + return TRUE; + + case ID_HELP_ABOUT: { + std::wstring appName(app->m_appName.begin(), app->m_appName.end()); + 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; + } + + case IDC_BUTTONEXIT: + case ID_FILE_EXIT: + PostMessage(dlg, WM_CLOSE, NULL, NULL); + return TRUE; + } + + return FALSE; case WM_CLOSE: - EndDialog(hWnd, 0); + EndDialog(dlg, 0); return TRUE; } diff --git a/WinChat/src/Application.h b/WinChat/src/Application.h index e356928..79d34dc 100644 --- a/WinChat/src/Application.h +++ b/WinChat/src/Application.h @@ -12,7 +12,7 @@ namespace wc { ~Application(); private: - static BOOL CALLBACK dlgProc(HWND hWnd, 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::string m_appVersion;