This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompleteExample.cpp
More file actions
133 lines (111 loc) · 3.07 KB
/
CompleteExample.cpp
File metadata and controls
133 lines (111 loc) · 3.07 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
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
129
130
131
132
133
// CompleteExample.cpp
// Header required to help detect window version
#include <sdkddkver.h>
// Macro used to reduce namespace pollution
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
// Reference for various Win32 API functions and
// structure declarations.
#include <Windows.h>
// Header needed for unicode adjustment support
#include <tchar.h>
// Include required for resources
#include "resource.h"
//
//
// WndProc - Window procedure
//
//
LRESULT
CALLBACK
WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
::PostQuitMessage(0);
break;
default:
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
//
//
// WinMain - Win32 application entry point.
//
//
int
APIENTRY
_tWinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nShowCmd)
{
const size_t MAX_LOADSTRING = 100;
TCHAR className[MAX_LOADSTRING];
TCHAR title[MAX_LOADSTRING];
HCURSOR cursor;
HICON icon, iconSmall;
::LoadString(hInstance, IDS_MYAPP_CLASS, className, MAX_LOADSTRING);
::LoadString(hInstance, IDS_MYAPP_TITLE, title, MAX_LOADSTRING);
cursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_MYAPP_POINTER));
icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYAPP_ICON));
iconSmall = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYAPP_ICON_SMALL));
// Setup window class attributes.
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(wcex); // WNDCLASSEX size in bytes
wcex.style = CS_HREDRAW | CS_VREDRAW; // Window class styles
wcex.lpszClassName = className; // Window class name
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Window background brush color.
wcex.hCursor = cursor; // Window cursor
wcex.lpfnWndProc = WndProc; // Window procedure associated to this window class.
wcex.hInstance = hInstance; // The application instance.
wcex.hIcon = icon; // Application icon.
wcex.hIconSm = iconSmall; // Application small icon.
// Register window and ensure registration success.
if (!RegisterClassEx(&wcex))
return 1;
// Setup window initialization attributes.
CREATESTRUCT cs;
ZeroMemory(&cs, sizeof(cs));
cs.x = 0; // Window X position
cs.y = 0; // Window Y position
cs.cx = 640; // Window width
cs.cy = 480; // Window height
cs.hInstance = hInstance; // Window instance.
cs.lpszClass = wcex.lpszClassName; // Window class name
cs.lpszName = title; // Window title
cs.style = WS_OVERLAPPEDWINDOW; // Window style
// Create the window.
HWND hWnd = ::CreateWindowEx(
cs.dwExStyle,
cs.lpszClass,
cs.lpszName,
cs.style,
cs.x,
cs.y,
cs.cx,
cs.cy,
cs.hwndParent,
cs.hMenu,
cs.hInstance,
cs.lpCreateParams);
// Validate window.
if (!hWnd)
return 1;
// Display the window.
::ShowWindow(hWnd, SW_SHOWDEFAULT);
::UpdateWindow(hWnd);
// Main message loop.
MSG msg;
while (::GetMessage(&msg, hWnd, 0, 0) > 0)
::DispatchMessage(&msg);
// Unregister window class, freeing the memory that was
// previously allocated for this window.
::UnregisterClass(wcex.lpszClassName, hInstance);
return (int)msg.wParam;
}