Saturday, February 26, 2011 3:12 PM
rbennett806
How to Create a Notification Window
This page explains how to create a user notification window using Microsoft Visual C++ 2010 Express edition (the free evaluation version). It is written as a quick guide to introduce you to some concepts, with an IT support professional in mind, and not a developer. In the example shown here we're looking to create a simple window that will be used in an SCCM managed environment to remind the currently logged in user to shut down their computer at the end of their work day. Please keep in mind that the steps listed below are geared specifically for this example, and may not be appropriate for other projects.

(a basic notification window)
- Download and install the Visual C++ 2010 Express edition.
- http://www.microsoft.com/express/Downloads/
- You do NOT need to install the optional SQL Server components for the example used in this guide
- When finished installing, check for any available Microsoft Updates.
- Initialize the project.
- Launch Microsoft Visual C++ 2010 Express.
- Select the File | New | Project menu item.
- Select the "Windows Forms Application" template.
- Name the project "Shutdown Reminder".
- Make sure to note the location of the project files.
- You may need to ensure that your files reside on the local machine and not a network drive.
- Click the OK button.
- Using Windows Explorer, create a subfolder called "Images" within your project folder.

- Copy a small image file (.BMP, .JPG, .PNG) into the "Images" folder.
- This test image will be used in the following steps and should be at 72 DPI (otherwise it may appear larger than expected).
- Copy an icon file (.ICO) into the "Images" folder.
- Design the form:
- Drag the window handles of the form to set the desired size for the notification window.
- Right-click on the blank form and select Properties.
- In the Properties window pane:
- Text = Shutdown Reminder
- BackColor = (set it to Web White)
- StartPosition = CenterScreen
- Icon = (path to the icon file from Step 2h)
- Click the ellipses to browse to the file.
- MaximizeBox = False
- MinimizeBox = False
- TopMost = True
- Add some text:
- In the Toolbox window pane click the
Label control.
- Click on the form window and place the Label control.
- Right-click on the empty control and select Properties.
- In the Properties window:
- Text = Please remember to shut down the computer every night. This helps to ensure that everything is safe and secure from malicious events.
- ForeColor = (set it to Web DarkRed)
- Select the View | Code menu item to bring up the code editor.
- Locate your newly added text, and insert "\r\n" (without the quotes) in the spot in the string where you want to place a line break and have the text continue on the next line.
this->label1->Text = L"Please remember to shut down the computer every night. \r\nThis helps to ensure that"
L" everything is safe and secure from malicious events.";
- Click the "Form1.h [Design]*" tab when finished editing.
- Drag the text to the desired location within the form window.
- Add a picture:
- In the Toolbox window pane click the
PictureBox control.
- Click and drag on the form window to outline a picture box.
- The size of the picture box isn't important at this point.
- Right-click on the empty PictureBox control and select Properties.
- In the Properties window:
- Image = (path to the image file from Step 2g)
- Click the ellipses to browse to the file.
- Click the small triangle residing along the frame of the PictureBox control and select Size Mode = AutoSize
- Drag the picture to the desired location within the form window.
- Add a button:
- In the Toolbox window pane click the
Button control.
- Click on the form window and place the Button control.
- Right-click on the empty control and select Properties.
- In the Properties window pane:
- Text = OK
- Dialog Result = OK
- Click the
Event symbol near the top of the Properties window.
- Double-click within the empty "Click" field.
- This creates the initial code and opens the code editor.
- Enter the following code within the "{" "}" brackets:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
- If you changed the name of the button the name may be different than "button1_Click".
- Click the "Form1.h [Design]*" tab when finished editing.
- Drag the button to the desired location within the form window.
- Debug the application:
- Select the Debug | Build Solution menu item.
- View the output area towards the bottom of the screen to ensure that there were no errors.
- Fix any errors that arise before proceeding.
- Select the Debug | Start Debugging menu item.
- Test the application to make sure it looks as expected and that the OK button closes the window.
- Compile the release version:
- Locate the "Debug" item
on the Standard menu bar (displayed by default) and change it to "Release".
- Select the Debug | Build Solution menu item.
- Navigate to "…\Shutdown Reminder\Release\" and test the compiled .EXE to see if it works.
For those that learn quicker from an example, you may click HERE for the source files used in this project.
To help ensure that your release .EXE works on multiple operating systems, copy "msvcm90.dll", "msvcp90.dll", and "msvcr90.dll" from within your "C:\Program Files\Microsoft Visual Studio 10.0\VC\redist\x86\Microsoft.VC90.CRT" folder into the "…\Shutdown Reminder\Release" folder. If the files do not exist in that location, then try searching for them within your "C:\Windows\winsxs" subfolders.
If deploying this notification window via SCCM it is suggested that a script be used to execute the .EXE file. This is because if you use the .EXE on the SCCM package's CommandLine, the service will wait until it receives a return code (or a preset time expires) before continuing to process any additional packages that may be waiting. Using a script allows SCCM to grab the return code from the script itself instead of the .EXE, and for other items to continue processing even while the notification window remains displayed on the screen.
*A Dell OptiPlex GX620 running 64-bit Windows 7 Enterprise Edition was used to document these steps.
Filed under: SCCM