forked from mhilliker/cse360project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (65 loc) · 3.31 KB
/
main.cpp
File metadata and controls
86 lines (65 loc) · 3.31 KB
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
#include <Windows.h>
#include <d2d1.h>
#include "Graphics.h"
//READ THIS BEFORE YOU RUN THIS EXAMPLE:
/* Direct2D libraries are in d2d1_1.h. The _1 is used for Windows 8
development, so if you get an error, change the header to <d2d1.h>.
Also, you may need to add d2d1.lib to your project dependencies */
Graphics* graphics; //graphics object that we made in Graphics.h
//An application-defined function that processes messages sent to a window.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_DESTROY){ PostQuitMessage(0); return 0; }
if (uMsg == WM_PAINT)
{
graphics->BeginDraw();
/************** Begin Drawing Here ***************/
//draws light brown background
graphics->ClearScreen(255.0f/256, 241.0f/256, 153.0f/256);
graphics->DrawUI(); //draws the grid
graphics->DrawString("Sudoku",135,30,500,30);
/*************** End Drawing Here ****************/
graphics->EndDraw();
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
//wWinMain is similar to main method. This is where the program begins executing.
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmd, int nCmdShow)
{
//creates windowclass and sets some properties
WNDCLASSEX windowclass;
ZeroMemory(&windowclass, sizeof(WNDCLASSEX));
windowclass.cbSize = sizeof(WNDCLASSEX);
windowclass.hbrBackground = (HBRUSH)COLOR_WINDOW; //default background color
windowclass.hInstance = hInstance;
windowclass.lpfnWndProc = WindowProc;
windowclass.lpszClassName = "MainWindow";
windowclass.style = CS_HREDRAW | CS_VREDRAW; //allows the user to adjust the window
RegisterClassEx(&windowclass); //Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.
//makes window with these dimms
RECT rect = { 0, 0, 800, 800 };
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, false, WS_EX_OVERLAPPEDWINDOW);
//defines the window handler to be a new window with the title being "Group Project" and with the initial position on the screen at (100,100)
HWND windowhandle = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "MainWindow", "Group Project", WS_OVERLAPPEDWINDOW, 100, 100, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, 0);
if (!windowhandle) return -1; //error handling
graphics = new Graphics(); //initializes graphics object made in Graphics.h
if (!graphics->Init(windowhandle)) //error handling
{
delete graphics;
return -1;
}
ShowWindow(windowhandle, nCmdShow); //displays window to screen
MSG message;
/*The system passes input to a window procedure in the form of a message. Messages are generated by both the system and applications.
The system generates a message at each input event?for example, when the user types, moves the mouse, or clicks a control such as a scroll bar.
The system also generates messages in response to changes in the system brought about by an application, such as when an application changes the
pool of system font resources or resizes one of its windows. An application can generate messages to direct its own windows to perform tasks or
to communicate with windows in other applications.*/
//handles the message requests
while (GetMessage(&message, NULL, 0, 0))
{
DispatchMessage(&message);
}
delete graphics; //gets rid of our graphics object for memory handling
return 0;
}