You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Walkthrough: Adding a CTaskDialog to an Application
7
+
# Walkthrough: Adding a CTaskDialog to an application
9
8
10
-
This walkthrough introduces the [CTaskDialog Class](../mfc/reference/ctaskdialog-class.md) and shows you how to add one to your application.
9
+
This walkthrough introduces the [`CTaskDialog` class](../mfc/reference/ctaskdialog-class.md) and shows how to add it to your application.
11
10
12
-
The `CTaskDialog` is a task dialog box that replaces the Windows message box in Windows Vista or later. The `CTaskDialog` improves the original message box and adds functionality. The Windows message box is still supported in Visual Studio.
11
+
The `CTaskDialog` is a task dialog box that replaces the Windows message box in Windows Vista or later. The `CTaskDialog` improves on the original message box and adds functionality. The Windows message box is still supported in Visual Studio.
13
12
14
13
> [!NOTE]
15
-
> Versions of Windows earlier than Windows Vista do not support the `CTaskDialog`. You must program an alternative dialog box option if you want to show a message to a user who runs your application on an earlier version of Windows. You can use the static method [CTaskDialog::IsSupported](../mfc/reference/ctaskdialog-class.md#issupported) to determine at run time whether a user's computer can display a `CTaskDialog`. In addition, the `CTaskDialog` is only available when your application is built with the Unicode library.
14
+
> Versions of Windows earlier than Windows Vista don't support the `CTaskDialog`. You must program an alternative dialog box option if you want to show a message to a user who runs your application on an earlier version of Windows. You can use the static method [CTaskDialog::IsSupported](../mfc/reference/ctaskdialog-class.md#issupported) to determine at run time whether a user's computer can display a `CTaskDialog`. In addition, the `CTaskDialog` is only available when your application is built with the Unicode library.
16
15
17
16
The `CTaskDialog` supports several optional elements to gather and display information. For example, a `CTaskDialog` can display command links, customized buttons, customized icons, and a footer. The `CTaskDialog` also has several methods that enable you to query the state of the task dialog box to determine what optional elements the user selected.
18
17
@@ -21,83 +20,49 @@ The `CTaskDialog` supports several optional elements to gather and display infor
21
20
You need the following components to complete this walkthrough:
22
21
23
22
- Visual Studio 2010 or later
24
-
25
23
- Windows Vista or later
26
24
27
-
## Replacing a Windows Message Box with a CTaskDialog
28
-
29
-
The following procedure demonstrates the most basic use of the `CTaskDialog`, which is to replace the Windows message box. This example also changes the icon associated with the task dialog box. Changing the icon makes the `CTaskDialog` appear same to the Windows message box.
30
-
31
-
### To Replace a Windows Message Box with a CTaskDialog
25
+
## Replace the Windows message box with a CTaskDialog
32
26
33
-
1. Use the **MFC Application Wizard** to create an MFC application with all the default settings. See [Walkthrough: Using the New MFC Shell Controls](walkthrough-using-the-new-mfc-shell-controls.md) for instructions on how to open the wizard for your version of Visual Studio.
27
+
The following demonstrates the most basic use of the `CTaskDialog`, which is to replace the Windows message box. This example also changes the icon associated with the task dialog box. Changing the icon makes the `CTaskDialog` appear similar to the Windows message box.
34
28
29
+
1. Use the **MFC Application Wizard** to create a Microsoft Foundation Classes (MFC) application with all the default settings. See [Walkthrough: Using the New MFC Shell Controls](walkthrough-using-the-new-mfc-shell-controls.md) for instructions on how to open the wizard for your version of Visual Studio.
35
30
1. Call it *MyProject*.
36
-
37
-
1. Use the **Solution Explorer** to open the file MyProject.cpp.
38
-
31
+
1. Use the **Solution Explorer** to open `MyProject.cpp`.
39
32
1. Add `#include "afxtaskdialog.h"` after the list of includes.
40
-
41
33
1. Find the method `CMyProjectApp::InitInstance`. Insert the following lines of code before the `return TRUE;` statement. This code creates the strings that we use in either the Windows message box or in the `CTaskDialog`.
42
34
43
35
```cpp
44
36
CString message("My message to the user");
45
37
CString dialogTitle("My Task Dialog title");
46
38
CString emptyString;
47
-
```
48
-
49
-
1. Add the following code after the code from step 4. This code guarantees that the user's computer supports the `CTaskDialog`. If the dialog isn't supported, the application displays a Windows message box instead.
50
39
51
-
```cpp
40
+
// Check whether the user's computer supports `CTaskDialog`.
1. On the next line, add the following code. This code sets the warning icon.
69
-
70
-
```cpp
71
-
taskDialog.SetMainIcon(TD_WARNING_ICON);
72
-
```
73
-
74
-
1. On the next line, add the following code. This code displays the task dialog box.
75
-
76
-
```cpp
77
-
taskDialog.DoModal();
78
-
```
79
-
80
-
You can avoid step 7if you don't want the `CTaskDialog` to display the same icon as the Windows message box. If you avoid that step, the `CTaskDialog` has no icon when the application displays it.
81
-
82
54
Compile and run the application. The application displays the task dialog box after it starts.
83
55
84
-
## Adding Functionality to the CTaskDialog
85
-
86
-
The following procedure shows you how to add functionality to the `CTaskDialog` that you created in the previous procedure. The example code shows you how to execute specific instructions based on the user's selections.
87
-
88
-
### To Add Functionality to the CTaskDialog
56
+
## Add functionality to the CTaskDialog
89
57
90
-
1. Navigate to the **Resource View**. If you can't see the **Resource View**, you can open it from the **View** menu.
58
+
The following shows you how to add functionality to the `CTaskDialog` that you created in the previous procedure. The example code shows you how to execute specific instructions based on the user's selections.
91
59
92
-
1. Expand the **Resource View** until you can select the **String Table** folder. Expand it and double-click the **String Table** entry.
93
-
94
-
1. Scroll to the bottom of the string table and add a new entry. Change the ID to `TEMP_LINE1`. Set the caption to **Command Line 1**.
95
-
96
-
1. Add another new entry. Change the ID to `TEMP_LINE2`. Set the caption to **Command Line 2**.
97
-
98
-
1. Navigate back to MyProject.cpp.
99
-
100
-
1. After `CString emptyString;`, add the following code:
60
+
1. Navigate to the **Resource View** via **View** > **Other Windows** > **Resource View**.
61
+
1. Expand the **Resource View** to the **String Table** folder. Expand it and double-click **String Table**.
62
+
1. Scroll to the bottom of the string table and add a new entry. Change the ID to `TEMP_LINE1`. Set the caption to `Command Line 1`.
63
+
1. Add another new entry. Change the ID to `TEMP_LINE2`. Set the caption to `Command Line 2`.
64
+
1. Navigate back to `MyProject.cpp`.
65
+
1. In the `CMyProjectApp::InitInstance()` function, after `CString emptyString;` add the following code:
101
66
102
67
```cpp
103
68
CString expandedLabel("Hide extra information");
@@ -109,67 +74,52 @@ The following procedure shows you how to add functionality to the `CTaskDialog`
taskDialog.SetFooterText(L"This is a small footnote to the user");
118
81
taskDialog.SetVerificationCheckboxText(L"Remember your selection");
119
-
```
120
-
121
-
1. Add the following line of code that displays the task dialog box to the user and retrieves the user's selection:
122
-
123
-
```cpp
124
82
INT_PTR result = taskDialog.DoModal();
125
-
```
126
-
127
-
1. Insert the following code after the call to `taskDialog.DoModal()`. This section of code processes the user's input:
128
83
129
-
```cpp
130
84
if (taskDialog.GetVerificationCheckboxState())
131
85
{
132
-
// PROCESS IF the user selects the verification checkbox
86
+
// Your code if the user selects the verification checkbox
133
87
}
134
88
135
89
switch (result)
136
90
{
137
-
case TEMP_LINE1:
138
-
// PROCESS IF the first command line
139
-
break;
140
-
case TEMP_LINE2:
141
-
// PROCESS IF the second command line
142
-
break;
143
-
case IDYES:
144
-
// PROCESS IF the user clicks yes
145
-
break;
146
-
case IDNO:
147
-
// PROCESS IF the user clicks no
148
-
break;
149
-
case IDCANCEL:
150
-
// PROCESS IF the user clicks cancel
151
-
break;
152
-
default:
153
-
// This case should not be hit because closing
154
-
// the dialog box results in IDCANCEL
155
-
break;
91
+
case TEMP_LINE1:
92
+
// PROCESS IF the first command line
93
+
break;
94
+
case TEMP_LINE2:
95
+
// PROCESS IF the second command line
96
+
break;
97
+
case IDYES:
98
+
// PROCESS IF the user clicks yes
99
+
break;
100
+
case IDNO:
101
+
// PROCESS IF the user clicks no
102
+
break;
103
+
case IDCANCEL:
104
+
// PROCESS IF the user clicks cancel
105
+
break;
106
+
default:
107
+
// This case should not be hit because closing
108
+
// the dialog box results in IDCANCEL
109
+
break;
156
110
}
157
111
```
158
112
159
-
In the code in step 9, replace the comments that start with `PROCESS IF` with the code that you want to execute under the specified conditions.
160
-
161
113
Compile and run the application. The application displays the task dialog box that uses the new controls and additional information.
162
114
163
115
## Displaying a CTaskDialog Without Creating a CTaskDialog Object
164
116
165
-
The following procedure shows you how to display a `CTaskDialog` without first creating a `CTaskDialog` object. This example continues the previous procedures.
117
+
The following shows you how to display a `CTaskDialog` without first creating a `CTaskDialog` object. This example continues the previous procedures.
166
118
167
119
### To Display a CTaskDialog Without Creating a CTaskDialog Object
168
120
169
-
1. Open the MyProject.cpp file if it isn't already open.
170
-
171
-
1. Navigate to the closing bracket for the `if (CTaskDialog::IsSupported())` statement.
172
-
121
+
1. Open the `MyProject.cpp` file.
122
+
1. In the `CMyProjectApp::InitInstance()` function, navigate to the closing bracket for the `if (CTaskDialog::IsSupported())` statement.
173
123
1. Insert the following code immediately before the closing bracket of the **`if`** statement (before the **`else`** block):
174
124
175
125
```cpp
@@ -180,12 +130,12 @@ The following procedure shows you how to display a `CTaskDialog` without first c
180
130
TEMP_LINE2);
181
131
```
182
132
183
-
Compile and run the application. The application displays two task dialog boxes. The first dialog box is from the **To Add Functionality to the CTaskDialog** procedure; the second dialog box is from the last procedure.
133
+
Compile and run the application. The application displays two task dialog boxes. The first dialog box is from the **To Add Functionality to the CTaskDialog** procedure; the second dialog box is from the previous procedure.
184
134
185
135
These examples don't demonstrate all the available options for a `CTaskDialog`, but should help you get started. See [CTaskDialog Class](../mfc/reference/ctaskdialog-class.md) for a full description of the class.
This pragma takes effect at the first function defined after the pragma is seen. Stack probes are neither a part of macros nor of functions that are generated inline.
20
+
This pragma only applies to 32-bit platforms (x86, ARM32). It has no effect on 64-bit platforms.
21
21
22
-
If you don't give an argument for the **`check_stack`** pragma, stack checking reverts to the behavior specified on the command line. For more information, see [Compiler options](../build/reference/compiler-options.md). The interaction of the `#pragma check_stack` and the [`/Gs`](../build/reference/gs-control-stack-checking-calls.md) option is summarized in the following table.
22
+
This pragma takes effect at the first function defined after the pragma is seen. Stack probes are not inserted for macros or functions that are generated inline.
23
23
24
-
### Using the check_stack Pragma
24
+
`#pragma check_stack(off)` / `#pragma Check_stack-` is ignored if the size of the function locals is larger than 4096 or the value specified by `/Gs`.
|`#pragma check_stack( )` or<br /><br /> `#pragma check_stack`| Yes | Turns off stack checking for functions that follow |
29
-
|`#pragma check_stack( )` or<br /><br /> `#pragma check_stack`| No | Turns on stack checking for functions that follow |
30
-
|`#pragma check_stack(on)`<br /><br /> or `#pragma check_stack +`| Yes or No | Turns on stack checking for functions that follow |
31
-
|`#pragma check_stack(off)`<br /><br /> or `#pragma check_stack -`| Yes or No | Turns off stack checking for functions that follow |
26
+
The default behavior of the compiler is to insert stack probes at the beginning of each function if the size of the locals exceeds 4096 or the value specified by `/Gs`.
27
+
28
+
Use [/Gs (Control stack checking calls)](../build/reference/gs-control-stack-checking-calls.md) to change the threshold of the locals that trigger stack probes. Use with caution.
29
+
30
+
Using `#pragma check_stack()` without arguments is deprecated.
Copy file name to clipboardExpand all lines: docs/sanitizers/asan.md
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -84,7 +84,10 @@ This article covers the information you require to enable the three workflows li
84
84
85
85
## <aname="command-prompt"></a> Use AddressSanitizer from a developer command prompt
86
86
87
-
Use the **`/fsanitize=address`** compiler option in a [developer command prompt](../build/building-on-the-command-line.md#developer_command_prompt_shortcuts) to enable compiling for the AddressSanitizer runtime. The **`/fsanitize=address`** option is compatible with all existing C++ or C optimization levels (for example, `/Od`, `/O1`, `/O2`, `/O2 /GL`, and `PGO`). The option works with static and dynamic CRTs (for example, `/MD`, `/MDd`, `/MT`, and `/MTd`). It works whether you create an EXE or a DLL. Debug information is required for optimal formatting of call stacks. In the following example, `cl /fsanitize=address /Zi` is passed on the command line.
87
+
Use the **`/fsanitize=address`** compiler option in a [developer command prompt](../build/building-on-the-command-line.md#developer_command_prompt_shortcuts) to enable compiling for the AddressSanitizer runtime. The **`/fsanitize=address`** option is compatible with existing C++ or C optimization levels (for example, `/Od`, `/O1`, `/O2`, and `/O2 /GL`). The option works with static and dynamic CRTs (for example, `/MD`, `/MDd`, `/MT`, and `/MTd`). It works whether you create an EXE or a DLL. Debug information is required for optimal formatting of call stacks. In the following example, `cl /fsanitize=address /Zi` is passed on the command line.
88
+
89
+
> [!NOTE]
90
+
> AddressSanitizer doesn't support Profile-guided optimization (PGO). AddressSanitizer shouldn't be used in production.
88
91
89
92
The AddressSanitizer libraries (.lib files) are linked for you automatically. For more information, see [AddressSanitizer language, build, and debugging reference](asan-building.md).
0 commit comments