01-06-2001. I have added a Listbox resource in the Dialog04 Project.
19-05-2001. Thanks for the great response. I will soon update this page with new information.
04-03-2001. Updated this page with the "Visual Studio" way to let Windows register a Window
Class for the Dialog box. This way all Dialog Messages will be processed by the Window Procedure.
Read here.
06-02-2001. Updated this page with the "Dialog 03" project. This project uses the progressbar
resource. This time text is added to the progressbar.
If you want to receive the complete project you can mail me.
Please let me know what you think about this page.
02-02-2001. Updated this page with the "Dialog 02" project. This project uses the Edit, Spin control
and the "Button" resource.
01-02-2001. Updated this page with the "Dialog 01" project. This project uses the Progress control
and the "Button" resource.
04-08-2000. In the newsgroup
comp.os.ms-windows.programmer.win32, a lot of information can be found about
win32 programming.
Intro
The previous project (Butt) was made
the HARD way. Buttons where made by hand. This Win32 project will demonstrate you how to make a
one Dialog Window the EASY way. Now we will use the Visual Studio Resource editor.
The examples can be used on Windows 95, Windows 98, Windows ME and Windows NT.
Keep visiting this page because I will add a lot of Dialog examples.
In the near future the following resources will be used:
Progress control or ProgressBar
Button
Static Text
Slider Control or TrackBar
Spin Box
Combo Box
ComboBox
Drop-down Combo Box
Single-line Text box
List box
Check boxes
Option Buttons
Radio Buttons
Links will help you to find more information on the subject. If you have an interesting link, let me know.
Please notify me if links are dead.
You can find information at http://msdn.microsoft.com.
Use Steps 1 to 18 for creating a project in Visual Studio. Step 19 and successive will determine the dialog
contents for each project.
Dialog 01 Project
In this project the following resources are used:
Progress control or ProgressBar
Button
Notes:
Wait with compile and Build until all 18 steps are executed.
Type all text between < >. So type also the " in <">.
Do not edit the "resource.h" by hand. Let Visual Studio do that for you.
You can make the Visual Studio project yourself if you follow the following steps:
Steps:
Make new project.
Enter the Poject name <Dialog01>. The Location should look like <C:\projects\Dialog01>
Make the new file <Dialog01.c> for this project.
Copy the contents of the <Dialog01.txt> file into your new
<Dialog01.c> file.
Copy the icon file <macbase.ico> into the <C:\projects\Dialog01> directory.
Now we will insert the Dialog window. Select Insert of the Visual Studio Menu.
Select "Dialog" and "IDD_FORMVIEW" and hit New.
Double click on the empty dialog window you just have created. Then click the "General Tab".
Change the ID to <"DIALOG01">. Select the "Styles" Tab. Change "Style"
to "Overlapped". Set "System menu" and "Minimize Box" to On. Select Tab "
More Styles" and set "Center". Select the "General" tab again and fill the Caption
field with <"Dialog 01">.
Save the script you have just created with "SaveAs" with the file name <Dialog01.rc>in
the <C:\projects\Dialog01> directory.
Add the resource script to the project by Going to the Project "FileView" and click with the
right mouse button on "Dialog01 files" and select the files: <Dialog01.rc> and
<resource.h>.
To add the Icon you have to Click on the Tab "ResourceView" in the Project View. Then click with the right mouse button on "Dialog01 resource"". Select "Import…". Then select the icon file <macbase.ico>.
Go to the properties of the Icon.
Change the "ID" to <"DIALOG01">.
Add the line <#include "resource.h"> in the "Dialog01.c" file. Just delete
the first "//" on line 11 of the "Dialog01.c" file.
Now there are 2 way's to registers a window class for the dialog box. All window procedures will be used to
process the dialog box messages.
The First ways is described here:
Close the "Dialog01.rc" file in Visual Studio –if it is Open-. Then use a text editor
to edit the "Dialog01.rc" file. The Dialog script part will probably look like:
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
DIALOG01 DIALOG DISCARDABLE 0, 0, 185, 93
STYLE DS_CENTER | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog 01"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "TODO: layout formview",IDC_STATIC,55,42,74,8
END
Add the line : CLASS "DIALOG01".
Change the line : DIALOG01 DIALOG DISCARDABLE 0, 0, 185, 93 to :
DIALOG01 DIALOGEX 0, 0, 185, 93. The script should look like this:
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
DIALOG01 DIALOGEX 0, 0, 185, 93
STYLE DS_CENTER | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog 01"
CLASS "DIALOG01"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "TODO: layout formview",IDC_STATIC,55,42,74,8
END
The second way was recently found by a colleague of mine. This is obvious the real Visual Studio way to do it.
Go to the "Resource File View" and clear the " Enable MFC Features" (if it's set).
Step 19 will enable the "Class name" field in the "Dialog Properties dialog". Fill in the
<DIALOG01>, without the <"">.
Now you can Build and execute the Project. The result should look like this:
Now we will add contents to the Dialog. Goto the Project "ResourceView" and open the "Dialog01
resources" folder. Then open the "Dialog" folder. Double click on "DIALOG01" to open the
Resource editor. The editor should have a Control window like this:
If you do not see the control window you need to enable that window. To enable it, go to the Visual Studio
menu "Tools", "Customize" and "Toolbars". There you can enable the control window.
Remove the Static Text from the dialog. Just select it with the left mouse key and delete it.
For the "Dialog 01", we will add 2 buttons and a progress bar to the Dialog window. To place a
button on the Dialog, you just select a button in the control window and drag it onto the Dialog window. Your
Dialog should look like this:
Now we will change the properties of the resources. To enter the properties Dialog, just double click on the
Resource.
Change the ID of Button 1 to "IDC_BUTTONSTART" and the caption to "Start". Change the ID
of Button 2 to "IDC_BUTTONSTOP" and the caption to "Stop". Change the ID of the progressbar
to "IDC_PROGRESSBAR". At the "Styles" Tab you can change the Style to Smooth.
Because we are using the progressbar resource we need to include the header file <commctrl.h> in
the "Dialog01.c" file. You just have to delete the first "//" on line 12.
You also should link a new library. Go to the Visual Studio menu "Project", "Settings…".
Select the Tab Link. Add <comctl32.lib> to the end of the Object/library modules line. Do this for
the "Win32 Debug" Setting and "Win32 Release" Setting.
To initialise the controls dll. You need to add the function "InitCommonControls". Just delete the
first "//" on line 52.
We need to add one more resource id. Go to the Visual Studio menu "View",
"Resource Symbols…".
Please only add new symbols using the resource editor or with the "new Symbol" dialog. Add the
symbol ID <IDC_INIT>. The value is calculated by Visual Studio.
Now we can delete all comment markers that disabled the rest of the "Dialog01" program. Delete the
first "//" on lines 14,15,16,17,19,20 and 56. Delete "/*" on line 66 and "*/" on
line 97. Delete "/*" on line 106 and "*/" on line 135.
If you do a build at this point. You will have a working Dialog.
Dialog 02 Project
In this project the following resources are used:
Edit Box
Spin Control
Button
Notes:
Do not forget to Add <CLASS "DIALOG02"> in the "Dialog02.rc" resource script (as in Dialog01).
You can download the "Dialog02.exe" program here. You can
make the Visual Studio project yourself if you follow the following steps:
Copy the contents of the <Dialog02.txt> file into your new
<Dialog02.c> file.
Steps:
Drag the "Edit Box" to the dialog window. Edit the properties of the Edit Box.
Change on the "General" Tab the ID to <IDC_EDITCONTROL>.
On the "Styles" Tab, switch the "Auto H Scroll" off and set the "Read-only" flag on.
Drag the "Spin" box to the dialog window and place it next right to the Edit Box.
Edit the properties of the "Spin" control. On the "General" Tab the ID should be changed
to <IDC_SPINCONTROL>.
On the "Styles" Tab, the "Set buddy integer" flag should be set.
Drag a "Button" onto the dialog window. On the "General" Tab the ID should be changed
to <IDC_BUTTONCLOSE>.
If you do a build at this point. You will have a working Dialog.
Dialog 03 Project
In this project the following resources are used:
Progress control or ProgressBar (Owner draw)
Button
Notes:
Do not forget to Add <CLASS "DIALOG03"> in the "Dialog03.rc" resource script (as in Dialog01).
You can download the "Dialog03.exe" program here. You can
make the Visual Studio project yourself if you follow the following steps:
Copy the contents of the <Dialog03.txt> file into your new
<Dialog03.c> file.
Steps:
Use the "Dialog01.rc" example as base for this "Dialog03.rc". The main difference is
the hook of the "ProgressBarProc". In this function the "WM_PAINT" is handled. The bar is now painted in two
steps and filled using a "brush". The text is also drawn in two steps.
If you do a build, you will have a working Dialog.
Dialog 04 Project
In this project the following resources are used:
Listbox
Button
Notes:
Do not forget to Add <CLASS "DIALOG04"> in the "Dialog04.rc" resource script (as in Dialog01).
You can download the "Dialog04.exe" program here. You can
make the Visual Studio project yourself if you follow the following steps:
Copy the contents of the <Dialog04.txt> file into your new
<Dialog04.c> file.
Steps:
Use the "Dialog01.rc" example as base for this "Dialog04.rc".
Add a button resource to the Dialog. Use <IDC_CLEARLISTBOX> as ID.
Add a Listbox resource to the Dialog. Use <IDC_LISTBOX> as ID.
Set the Listbox Styles as in the next figure.
If you do a build, you will have a working Dialog.