Skip to content

Commit 6eb0bb5

Browse files
authored
Merge pull request #3651 from MicrosoftDocs/FromPublicMasterBranch
Confirm merge from FromPublicMasterBranch to master to sync with https://github.com/MicrosoftDocs/cpp-docs (branch master)
2 parents 57e7d36 + 769b186 commit 6eb0bb5

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

docs/windows/walkthrough-creating-windows-desktop-applications-cpp.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Next, you'll learn how to create the code for a Windows desktop application in V
121121
1. Just as every C application and C++ application must have a `main` function as its starting point, every Windows desktop application must have a `WinMain` function. `WinMain` has the following syntax.
122122

123123
```cpp
124-
int CALLBACK WinMain(
124+
int WINAPI WinMain(
125125
_In_ HINSTANCE hInstance,
126126
_In_opt_ HINSTANCE hPrevInstance,
127127
_In_ LPSTR lpCmdLine,
@@ -132,7 +132,7 @@ Next, you'll learn how to create the code for a Windows desktop application in V
132132
For information about the parameters and return value of this function, see [WinMain entry point](/windows/win32/api/winbase/nf-winbase-winmain).
133133
134134
> [!NOTE]
135-
> What are all those extra words, such as `CALLBACK`, or `HINSTANCE`, or `_In_`? The traditional Windows API uses typedefs and preprocessor macros extensively to abstract away some of the details of types and platform-specific code, such as calling conventions, **`__declspec`** declarations, and compiler pragmas. In Visual Studio, you can use the IntelliSense [Quick Info](/visualstudio/ide/using-intellisense#quick-info) feature to see what these typedefs and macros define. Hover your mouse over the word of interest, or select it and press **Ctrl**+**K**, **Ctrl**+**I** for a small pop-up window that contains the definition. For more information, see [Using IntelliSense](/visualstudio/ide/using-intellisense). Parameters and return types often use *SAL Annotations* to help you catch programming errors. For more information, see [Using SAL Annotations to Reduce C/C++ Code Defects](../code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.md).
135+
> What are all those extra words, such as `WINAPI`, or `CALLBACK`, or `HINSTANCE`, or `_In_`? The traditional Windows API uses typedefs and preprocessor macros extensively to abstract away some of the details of types and platform-specific code, such as calling conventions, **`__declspec`** declarations, and compiler pragmas. In Visual Studio, you can use the IntelliSense [Quick Info](/visualstudio/ide/using-intellisense#quick-info) feature to see what these typedefs and macros define. Hover your mouse over the word of interest, or select it and press **Ctrl**+**K**, **Ctrl**+**I** for a small pop-up window that contains the definition. For more information, see [Using IntelliSense](/visualstudio/ide/using-intellisense). Parameters and return types often use *SAL Annotations* to help you catch programming errors. For more information, see [Using SAL Annotations to Reduce C/C++ Code Defects](../code-quality/using-sal-annotations-to-reduce-c-cpp-code-defects.md).
136136
137137
1. Windows desktop programs require <windows.h>. <tchar.h> defines the `TCHAR` macro, which resolves ultimately to **`wchar_t`** if the UNICODE symbol is defined in your project, otherwise it resolves to **`char`**. If you always build with UNICODE enabled, you don't need TCHAR and can just use **`wchar_t`** directly.
138138
@@ -169,7 +169,7 @@ Next, you'll learn how to create the code for a Windows desktop application in V
169169
wcex.cbClsExtra = 0;
170170
wcex.cbWndExtra = 0;
171171
wcex.hInstance = hInstance;
172-
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
172+
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
173173
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
174174
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
175175
wcex.lpszMenuName = NULL;
@@ -193,13 +193,14 @@ Next, you'll learn how to create the code for a Windows desktop application in V
193193
}
194194
```
195195
196-
1. Now you can create a window. Use the [CreateWindow](/windows/win32/api/winuser/nf-winuser-createwindoww) function.
196+
1. Now you can create a window. Use the [CreateWindowEx](/windows/win32/api/winuser/nf-winuser-createwindowexw) function.
197197
198198
```cpp
199199
static TCHAR szWindowClass[] = _T("DesktopApp");
200200
static TCHAR szTitle[] = _T("Windows Desktop Guided Tour Application");
201201
202-
// The parameters to CreateWindow explained:
202+
// The parameters to CreateWindowEx explained:
203+
// WS_EX_OVERLAPPEDWINDOW : An optional extended window style.
203204
// szWindowClass: the name of the application
204205
// szTitle: the text that appears in the title bar
205206
// WS_OVERLAPPEDWINDOW: the type of window to create
@@ -209,7 +210,8 @@ Next, you'll learn how to create the code for a Windows desktop application in V
209210
// NULL: this application does not have a menu bar
210211
// hInstance: the first parameter from WinMain
211212
// NULL: not used in this application
212-
HWND hWnd = CreateWindow(
213+
HWND hWnd = CreateWindowEx(
214+
WS_EX_OVERLAPPEDWINDOW,
213215
szWindowClass,
214216
szTitle,
215217
WS_OVERLAPPEDWINDOW,
@@ -223,7 +225,7 @@ Next, you'll learn how to create the code for a Windows desktop application in V
223225
if (!hWnd)
224226
{
225227
MessageBox(NULL,
226-
_T("Call to CreateWindow failed!"),
228+
_T("Call to CreateWindowEx failed!"),
227229
_T("Windows Desktop Guided Tour"),
228230
NULL);
229231
@@ -277,7 +279,7 @@ Next, you'll learn how to create the code for a Windows desktop application in V
277279
wcex.cbClsExtra = 0;
278280
wcex.cbWndExtra = 0;
279281
wcex.hInstance = hInstance;
280-
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
282+
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
281283
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
282284
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
283285
wcex.lpszMenuName = NULL;
@@ -297,7 +299,8 @@ Next, you'll learn how to create the code for a Windows desktop application in V
297299
// Store instance handle in our global variable
298300
hInst = hInstance;
299301

300-
// The parameters to CreateWindow explained:
302+
// The parameters to CreateWindowEx explained:
303+
// WS_EX_OVERLAPPEDWINDOW : An optional extended window style.
301304
// szWindowClass: the name of the application
302305
// szTitle: the text that appears in the title bar
303306
// WS_OVERLAPPEDWINDOW: the type of window to create
@@ -307,7 +310,8 @@ Next, you'll learn how to create the code for a Windows desktop application in V
307310
// NULL: this application dows not have a menu bar
308311
// hInstance: the first parameter from WinMain
309312
// NULL: not used in this application
310-
HWND hWnd = CreateWindow(
313+
HWND hWnd = CreateWindowEx(
314+
WS_EX_OVERLAPPEDWINDOW,
311315
szWindowClass,
312316
szTitle,
313317
WS_OVERLAPPEDWINDOW,
@@ -447,7 +451,7 @@ As promised, here's the complete code for the working application.
447451
// Forward declarations of functions included in this code module:
448452
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
449453
450-
int CALLBACK WinMain(
454+
int WINAPI WinMain(
451455
_In_ HINSTANCE hInstance,
452456
_In_opt_ HINSTANCE hPrevInstance,
453457
_In_ LPSTR lpCmdLine,
@@ -462,7 +466,7 @@ As promised, here's the complete code for the working application.
462466
wcex.cbClsExtra = 0;
463467
wcex.cbWndExtra = 0;
464468
wcex.hInstance = hInstance;
465-
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
469+
wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
466470
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
467471
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
468472
wcex.lpszMenuName = NULL;
@@ -482,7 +486,8 @@ As promised, here's the complete code for the working application.
482486
// Store instance handle in our global variable
483487
hInst = hInstance;
484488
485-
// The parameters to CreateWindow explained:
489+
// The parameters to CreateWindowEx explained:
490+
// WS_EX_OVERLAPPEDWINDOW : An optional extended window style.
486491
// szWindowClass: the name of the application
487492
// szTitle: the text that appears in the title bar
488493
// WS_OVERLAPPEDWINDOW: the type of window to create
@@ -492,7 +497,8 @@ As promised, here's the complete code for the working application.
492497
// NULL: this application does not have a menu bar
493498
// hInstance: the first parameter from WinMain
494499
// NULL: not used in this application
495-
HWND hWnd = CreateWindow(
500+
HWND hWnd = CreateWindowEx(
501+
WS_EX_OVERLAPPEDWINDOW,
496502
szWindowClass,
497503
szTitle,
498504
WS_OVERLAPPEDWINDOW,

0 commit comments

Comments
 (0)