From 5fb764e4b5cd603c63e638f912a4c39772db8480 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sun, 28 Oct 2018 14:13:39 -0700 Subject: Basic working UI --- Source/Main.cpp | 225 ++++++++++++++++++++++++++------------------------------ 1 file changed, 105 insertions(+), 120 deletions(-) (limited to 'Source/Main.cpp') diff --git a/Source/Main.cpp b/Source/Main.cpp index 4748b73..5c7cefa 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -2,177 +2,162 @@ // #include "stdafx.h" -#include "Main.h" +#include "resource.h" +#include "tchar.h" +#include "Randomizer.h" +#include +#include +#include +#include #define MAX_LOADSTRING 100 +#define IDC_RANDOMIZE 0x464 -// Global Variables: -HINSTANCE hInst; // current instance -WCHAR szTitle[MAX_LOADSTRING]; // The title bar text -WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name +HINSTANCE hInst; +WCHAR szWindowClass[MAX_LOADSTRING]; +HWND hwndSeed; +std::shared_ptr randomizer; -// Forward declarations of functions included in this code module: +// Forward declares ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); -int APIENTRY wWinMain(_In_ HINSTANCE hInstance, - _In_opt_ HINSTANCE hPrevInstance, - _In_ LPWSTR lpCmdLine, - _In_ int nCmdShow) +int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); - - // TODO: Place code here. - - // Initialize global strings - LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); + LoadStringW(hInstance, IDC_SOURCE, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); - - // Perform application initialization: - if (!InitInstance (hInstance, nCmdShow)) - { + if (!InitInstance(hInstance, nCmdShow)) { return FALSE; } - - HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SOURCE)); + randomizer = std::make_shared(); + if (randomizer == nullptr) { + return FALSE; + } MSG msg; - - // Main message loop: - while (GetMessage(&msg, nullptr, 0, 0)) + while (!GetMessage(&msg, nullptr, 0, 0) == 0) { - if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + TranslateMessage(&msg); + DispatchMessage(&msg); } return (int) msg.wParam; } - - -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// ATOM MyRegisterClass(HINSTANCE hInstance) { - WNDCLASSEXW wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SOURCE)); - wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_SOURCE); - wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + WNDCLASSEXW wcex = { + sizeof(WNDCLASSEX), + CS_HREDRAW | CS_VREDRAW, + WndProc, + 0, + 0, + hInstance, + LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SOURCE)), + LoadCursor(nullptr, IDC_ARROW), + (HBRUSH)(COLOR_WINDOW+1), + MAKEINTRESOURCEW(IDC_SOURCE), + szWindowClass, + LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)), + }; return RegisterClassExW(&wcex); } -// -// FUNCTION: InitInstance(HINSTANCE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { - hInst = hInstance; // Store instance handle in our global variable + hInst = hInstance; // Store instance handle in our global variable - HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, + WCHAR szTitle[MAX_LOADSTRING]; + LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); - if (!hWnd) - { - return FALSE; - } - - ShowWindow(hWnd, nCmdShow); - UpdateWindow(hWnd); - - return TRUE; + if (!hWnd) + { + return FALSE; + } + + LoadLibrary(L"Msftedit.dll"); + HWND label = CreateWindow(L"BUTTON", L"Enter a seed:", + WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, + 10, 10, 100, 26, hWnd, NULL, hInst, NULL); + + hwndSeed = CreateWindowEx(0, MSFTEDIT_CLASS, L"", + ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP, + 120, 10, 50, 26, hWnd, NULL, hInst, NULL); + + HWND hwndRandomize = CreateWindow(L"BUTTON", L"Randomize", + WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, + 180, 10, 100, 26, hWnd, (HMENU)IDC_RANDOMIZE, hInst, NULL); + + HDC hdc = GetDC(hWnd); + RECT rect; + GetClientRect(hWnd, &rect); + LPCWSTR text = L"this Window cannot be used"; + DrawText(hdc, text, static_cast(wcslen(text)), &rect, DT_CENTER | DT_VCENTER); + ReleaseDC(hWnd, hdc); + + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + return TRUE; } -// -// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) -// -// PURPOSE: Processes messages for the main window. -// -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return -// -// LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) - { - case WM_COMMAND: - { - int wmId = LOWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDM_ABOUT: - DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); - break; - case IDM_EXIT: - DestroyWindow(hWnd); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - } - break; - case WM_PAINT: + if (WM_COMMAND == WM_DESTROY) { + PostQuitMessage(0); + } else { + int wmId = LOWORD(wParam); + // Parse the menu selections: + switch (wmId) { - PAINTSTRUCT ps; - HDC hdc = BeginPaint(hWnd, &ps); - // TODO: Add any drawing code that uses hdc here... - EndPaint(hWnd, &ps); + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + case IDC_RANDOMIZE: + { + std::wstring text(100, '\0'); + GetWindowText(hwndSeed, &text[0], 100); + int seed = 0; + if (wcslen(text.c_str()) == 0) { + srand(static_cast(time(nullptr))); // Seed from the time in milliseconds + rand(); + seed = rand() % 100000; + std::wstring seedString = std::to_wstring(seed); + SetWindowText(hwndSeed, seedString.c_str()); + } else { + seed = _wtoi(text.c_str()); + } + randomizer->Randomize(seed); + + break; + } + case IDM_EXIT: + DestroyWindow(hWnd); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); } - break; - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; + } + return DefWindowProc(hWnd, message, wParam, lParam); } -// Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: - return (INT_PTR)TRUE; + return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); - return (INT_PTR)TRUE; + return TRUE; } break; } -- cgit 1.4.1