My Project
lego.cpp
Go to the documentation of this file.
1 // lego.cpp: define run point
2 //
3 
4 #include "stdafx.h"
5 #include "lego.h"
6 #include "listener.h"
7 #include "application.h"
8 
9 #define MAX_LOADSTRING 100
10 
11 // Global variables:
12 HINSTANCE hInst; // current instance
13 WCHAR szTitle[MAX_LOADSTRING]; // Tittle
14 WCHAR szWindowClass[MAX_LOADSTRING]; // Classname of main window
16 
17 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
18  _In_opt_ HINSTANCE hPrevInstance,
19  _In_ LPWSTR lpCmdLine,
20  _In_ int nCmdShow)
21 {
22  srand(time(0));
23  UNREFERENCED_PARAMETER(hPrevInstance);
24  UNREFERENCED_PARAMETER(lpCmdLine);
25 
26  LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
27  LoadStringW(hInstance, IDC_LEGO, szWindowClass, MAX_LOADSTRING);
28  MyRegisterClass(hInstance);
29 
30  // Init application
31  if (!InitInstance (hInstance, nCmdShow))
32  {
33  return FALSE;
34  }
35 
36 
37  HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LEGO));
38 
39  MSG msg;
40 
41  // Main message cycle
42  while (GetMessage(&msg, nullptr, 0, 0))
43  {
44  if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
45  {
46  TranslateMessage(&msg);
47  DispatchMessage(&msg);
48  }
49  }
50 
51  return (int) msg.wParam;
52 }
53 
54 
55 
56 //
57 // FUNCTION: MyRegisterClass()
58 //
59 // PURPOSE: register window class
60 //
61 ATOM MyRegisterClass(HINSTANCE hInstance)
62 {
63  WNDCLASSEXW wcex;
64 
65  HBRUSH windowColor = CreateSolidBrush(RGB(97, 115, 177));
66 
67  wcex.cbSize = sizeof(WNDCLASSEX);
68 
69  wcex.style = CS_HREDRAW | CS_VREDRAW;
70  wcex.lpfnWndProc = WndProc;
71  wcex.cbClsExtra = 0;
72  wcex.cbWndExtra = 0;
73  wcex.hInstance = hInstance;
74  wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LEGO));
75  wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
76  wcex.hbrBackground = windowColor;
77  wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_LEGO);
78  wcex.lpszClassName = szWindowClass;
79  wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
80 
81  SetCursor(LoadCursor(nullptr, IDC_ARROW));
82 
83  return RegisterClassExW(&wcex);
84 }
85 
86 //
87 // FUNCTION: InitInstance(HINSTANCE, int)
88 //
89 // PURPOSE: saves instance processing and creates main window
90 //
91 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
92 {
93  hInst = hInstance; // Сохранить дескриптор экземпляра в глобальной переменной
94 
95  HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
96  CW_USEDEFAULT, 0, 1134, 796, nullptr, nullptr, hInstance, nullptr);
97 
98  if (!hWnd)
99  {
100  return FALSE;
101  }
102 
103 
104  ShowWindow(hWnd, nCmdShow);
105  UpdateWindow(hWnd);
106 
107  return TRUE;
108 }
#define IDC_LEGO
Definition: Resource.h:15
#define MAX_LOADSTRING
Definition: lego.cpp:9
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
Definition: listener.cpp:29
Application * application
Definition: lego.cpp:15
#define IDI_LEGO
Definition: Resource.h:13
WCHAR szTitle[MAX_LOADSTRING]
Definition: lego.cpp:13
HINSTANCE hInst
Definition: lego.cpp:12
#define IDS_APP_TITLE
Definition: Resource.h:6
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
Definition: lego.cpp:17
#define IDI_SMALL
Definition: Resource.h:14
WCHAR szWindowClass[MAX_LOADSTRING]
Definition: lego.cpp:14
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
Definition: lego.cpp:91
ATOM MyRegisterClass(HINSTANCE hInstance)
Definition: lego.cpp:61