1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/**************/
/* System.h */
/**************/
#pragma once
#include <Windows.h>
class System
{
public:
System(HINSTANCE);
~System(void);
bool InitilizeWindow(bool); //Initialize , register, show, and update the class
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); //Message Processing
WPARAM Run(); //Windows Application Loop
public:
HINSTANCE hInstance;
HWND hwnd;
MSG msg;
WNDCLASSEX wcex;
LPCSTR className;
RECT rc;
};
/**************/
/* System.cpp */
/**************/
#include "System.h"
#include <Windows.h>
System::System(HINSTANCE instance)
{
hwnd = 0;
hInstance = instance;
LPCSTR className = "D3D Application";
}
bool System::InitilizeWindow(bool b3dApplication) {
//Set Class
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wcex.hCursor = LoadCursor(hInstance, IDC_ARROW);
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wcex.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
wcex.hInstance = hInstance;
wcex.lpfnWndProc = WndProc;
wcex.lpszClassName = className;
wcex.style = CS_HREDRAW | CS_VREDRAW;
//Register Windows Class
//Error Unhandled Execption at 0x763AD298 (user32.dll) in Project1.exe: 0xC0000005: Access violation reading location 0xCCCCCCC.
if(!RegisterClassEx(&wcex)) { return false; }
//Create Window
hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, className, "D3DApplication", WS_BORDER, CW_USEDEFAULT, CW_USEDEFAULT,
640, 480,
NULL, NULL, hInstance, 0);
if(!hwnd) { return false; }
//Show Window and Update Window
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return true;
}
LRESULT CALLBACK System::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg){
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
WPARAM System::Run(){
while(GetMessage(&msg, hwnd, 0, 0 ) != 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
System::~System(void)
{
}
/**************/
/* Main.cpp */
/**************/
#include <Windows.h>
#include "System.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
System EngineWindow(hInstance);
if(!EngineWindow.InitilizeWindow(false)) { return -1; }
return static_cast<int> (EngineWindow.Run()); //static_cast<int>( msg.wParam );
}
|