Home |  Contact |  Guestbook |  Print Window |   RSS | 

   

     This drawing was made in Singapore in 1997. I was told that it means 'Good Fortune'. Click for the explanation.    

 

 

Windows programming page

 

 

 

 

 

 

      



News:

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 download the "Dialog01.exe" program here. You can make the Visual Studio project yourself if you follow the following steps:

Steps:

  1. Make new project.
  2. Enter the Poject name <Dialog01>. The Location should look like <C:\projects\Dialog01>
  3. Make the new file <Dialog01.c> for this project.
  4. Copy the contents of the <Dialog01.txt> file into your new <Dialog01.c> file.
  5. Copy the icon file <macbase.ico> into the <C:\projects\Dialog01> directory.
  6. Now we will insert the Dialog window. Select Insert of the Visual Studio Menu.
  7. Select "Dialog" and "IDD_FORMVIEW" and hit New.
  8. 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">.
  9. Save the script you have just created with "SaveAs" with the file name <Dialog01.rc>in the <C:\projects\Dialog01> directory.
  10. 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>.
  11. 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>.
  12. Go to the properties of the Icon.
  13. Change the "ID" to <"DIALOG01">.
  14. Add the line <#include "resource.h"> in the "Dialog01.c" file. Just delete the first "//" on line 11 of the "Dialog01.c" file.
  15. 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:
  16. 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:


  17. /////////////////////////////////////////////////////////////////////////////
    //
    // 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

  18. Add the line : CLASS "DIALOG01".
  19. Change the line : DIALOG01 DIALOG DISCARDABLE 0, 0, 185, 93 to :
  20. 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

  21. 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).

  22. Step 19 will enable the "Class name" field in the "Dialog Properties dialog". Fill in the <DIALOG01>, without the <"">.

  23. Now you can Build and execute the Project. The result should look like this:
  24. 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:
  25. 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.
  26. Remove the Static Text from the dialog. Just select it with the left mouse key and delete it.
  27. 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:
  28. Now we will change the properties of the resources. To enter the properties Dialog, just double click on the Resource.
  29. 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.
  30. 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.
  31. To initialise the controls dll. You need to add the function "InitCommonControls". Just delete the first "//" on line 52.
  32. We need to add one more resource id. Go to the Visual Studio menu "View", "Resource Symbols…".
  33. 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.
  34. 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.
  35. 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:

  1. Drag the "Edit Box" to the dialog window. Edit the properties of the Edit Box.
  2. Change on the "General" Tab the ID to <IDC_EDITCONTROL>.
  3. On the "Styles" Tab, switch the "Auto H Scroll" off and set the "Read-only" flag on.
  4. Drag the "Spin" box to the dialog window and place it next right to the Edit Box.
  5. Edit the properties of the "Spin" control. On the "General" Tab the ID should be changed to <IDC_SPINCONTROL>.
  6. On the "Styles" Tab, the "Set buddy integer" flag should be set.
  7. Drag a "Button" onto the dialog window. On the "General" Tab the ID should be changed to <IDC_BUTTONCLOSE>.
  8. 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:

  1. 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.
  2. 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:

  1. Use the "Dialog01.rc" example as base for this "Dialog04.rc".
  2. Add a button resource to the Dialog. Use <IDC_CLEARLISTBOX> as ID.
  3. Add a Listbox resource to the Dialog. Use <IDC_LISTBOX> as ID.
  4. Set the Listbox Styles as in the next figure.
  5. If you do a build, you will have a working Dialog.




 

 

 

 

Last updated:

© Copyright 2006-2016 ronaldsnoeck.com |  Disclaimer |  Privacy