forked from zdd/RubikCube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
77 lines (64 loc) · 2.09 KB
/
Main.cpp
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
#include <time.h>
#include "RubikCube.h"
RubikCube rubikCube;
int initWindowPosX = rubikCube.GetWindowPosX();
int initWindowPosY = rubikCube.GetWindowPosY();
int InitWindowWidth = rubikCube.GetWindowWidth() ;
int InitWindowHeight = rubikCube.GetWindowHeight() ;
// Message process
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
rubikCube.HandleMessages(hwnd, message, wParam, lParam) ;
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
// Main entry point of program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
WNDCLASSEX winClass ;
winClass.lpszClassName = L"MY_WINDOWS_CLASS";
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.style = CS_HREDRAW | CS_VREDRAW;
winClass.lpfnWndProc = WndProc;
winClass.hInstance = hInstance;
winClass.hIcon = NULL;
winClass.hIconSm = NULL ;
winClass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
winClass.hbrBackground = NULL ;
winClass.lpszMenuName = NULL ;
winClass.cbClsExtra = 0;
winClass.cbWndExtra = 0;
RegisterClassEx (&winClass) ;
HWND hWnd = CreateWindowEx(NULL,
L"MY_WINDOWS_CLASS", // window class name
L"Rubik Cube", // window caption
WS_OVERLAPPEDWINDOW, // window style
initWindowPosX, // initial x position
initWindowPosY, // initial y position
InitWindowWidth, // initial x size
InitWindowHeight, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
// Initialize rubik cube
rubikCube.Initialize(hWnd);
ShowWindow(hWnd, iCmdShow) ;
UpdateWindow(hWnd) ;
//SendMessage(hWnd, WM_KEYDOWN, 'F', 0);
MSG msg ;
ZeroMemory( &msg, sizeof(msg) );
PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );
while (msg.message != WM_QUIT)
{
if( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0)
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
else // Render game scene if no message to process
{
rubikCube.Render() ;
}
}
return msg.wParam ;
}