Add dialog functionality

This commit is contained in:
Grayson Riffe 2023-08-30 17:44:27 -05:00
parent a0437093fb
commit 163a583fa4
5 changed files with 71 additions and 11 deletions

Binary file not shown.

View File

@ -80,10 +80,11 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link> </Link>
<PreBuildEvent> <PreBuildEvent>
<Command>PreBuild.bat</Command> <Command>PreBuild.bat</Command>

View File

@ -2,16 +2,21 @@
// Microsoft Visual C++ generated include file. // Microsoft Visual C++ generated include file.
// Used by WinChat.rc // Used by WinChat.rc
// //
#define IDD_MAINDIALOG 101 #define IDD_DIALOGMAIN 101
#define IDR_MENUMAIN 104
#define IDC_STATICTITLE 1001 #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 // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103 #define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1002 #define _APS_NEXT_CONTROL_VALUE 1006
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif

View File

@ -1,28 +1,82 @@
#include "Application.h" #include "Application.h"
#include <iostream>
#include <format>
#include "../resource.h" #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 { namespace wc {
Application::Application(std::string& appName, std::string& appVersion) Application::Application(std::string& appName, std::string& appVersion)
: m_appName(appName) : m_appName(appName)
, m_appVersion(appVersion) , 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() { void Application::run() {
HINSTANCE hInst = GetModuleHandle(NULL); HINSTANCE hInst = GetModuleHandle(NULL);
DialogBox(hInst, MAKEINTRESOURCE(IDD_MAINDIALOG), nullptr, (DLGPROC)dlgProc); DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOGMAIN), nullptr, (DLGPROC)dlgProc, reinterpret_cast<LPARAM>(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) { switch (msg) {
case WM_INITDIALOG: case WM_INITDIALOG: {
app = reinterpret_cast<Application*>(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<LPARAM>(font), NULL);
return TRUE; 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: case WM_CLOSE:
EndDialog(hWnd, 0); EndDialog(dlg, 0);
return TRUE; return TRUE;
} }

View File

@ -12,7 +12,7 @@ namespace wc {
~Application(); ~Application();
private: 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_appName;
const std::string m_appVersion; const std::string m_appVersion;