Creating Windows and User Controls

This section contains simple examples of how to create windows and user controls.

The examples are based on:

The basic user controls are:

These are sometimes referred to as user controls because they are defined within user32.dll.

An Elementary Window
image: simple window, click for larger image

This is an example of how to create and show a simple window. It is a 'does nothing' window but it has all the main features common to ALL windows. These features include:

Create Button Controls
image: create buttons, click for larger image

This is an example of how to create and show the various types of button controls. Like all standard and common controls button controls are windows. The Button control types are:

Image buttons can be created by giving the button the BS_BITMAP or BS_ICON style; the bitmap or icon assigned to the button appearing instead of text. The image is assigned to the control by sending a BM_SETIMAGE message to the button control using the SendMessage API function.

Note that the SimpleWnd example has been used with some minor modifications and the WndProc function now handles the WM_CREATE message in addition to the WM_DESTROY. This example is a 'do nothing' example serving only to demonstrate the creation and display of controls of the BUTTON class. All button controls are created with the CreateWindowEx API function by varying the window styles. The API function CreateWindow can also be used.

Create Combobox Controls
image: create comboboxes, click for larger image

This is an example of how to create and show the various types of combo box controls. Like all standard and common controls combo box controls are windows. The combo box control types are:

Note that the SimpleWnd example has been used with some minor modifications and the WndProc function now handles the WM_CREATE message in addition to the WM_DESTROY. This example is a 'do nothing' example serving only to demonstrate the creation and display of controls of the COMBOBOX class. All combo box controls are created with the CreateWindowEx API function by varying the window styles. The API function CreateWindow can also be used.

Create Edit Controls
image: create edits, click for larger image

This is an example of how to create and show an edit control. Like all standard and common controls edit controls are windows. They are typically used to permit users to enter and edit text from the keyboard. The edit control types are:

Note that the SimpleWnd example has been used with some minor modifications and the WndProc function now handles the WM_CREATE message in addition to the WM_DESTROY. This example is a 'do nothing' example serving only to demonstrate the creation and display of controls of the EDIT class. All edit controls are created with the CreateWindowEx API function by varying the window styles. The API function CreateWindow can also be used.

Create Listbox Controls
image: create listbox, click for larger image

This is an example of how to create and show a list box control. Like all standard and common controls list box controls are windows. They typically contain a list of items for user choice. The list box control types are:

Note that the SimpleWnd example has been used with some minor modifications and the WndProc function now handles the WM_CREATE message in addition to the WM_DESTROY. This example is a 'do nothing' example serving only to demonstrate the creation and display of controls of the LISTBOX class. All list box controls are created with the CreateWindowEx API function by varying the window styles. The API function CreateWindow can also be used.

Create Richedit Controls
image: create richedit, click for larger image

This is an example of how to create and show a rich edit control. Like all standard and common controls rich edit controls are windows. They are similar to ordinary edit controls but have more formatting capabilities. The rich edit control types are:

Note that the SimpleWnd example has been used with some minor modifications and the WndProc function now handles the WM_CREATE message in addition to the WM_DESTROY. This example is a 'do nothing' example serving only to demonstrate the creation and display of controls of the RICHEDIT class. All rich edit controls are created with the CreateWindowEx API function by varying the window styles. The API function CreateWindow can also be used. A new API function - LoadLibrary is introduced. This is used to determine which type or version of rich edit control is available on the host system according to the following table:

Richedit Version Dynamic Link Library(dll) Control Class Name Minimum System
1.0 Riched32.dll RichEdit Win95
2.0 or 3.0 Riched20.dll RICHEDIT_CLASS Win98 (compatible with win95)
4.1 Msftedit.dll MSFTEDIT_CLASS Winxp, service pack 1; UNICODE only

Regardless of the version of rich edit control being used, the header file richedit.h must be included.

Create Scrollbar Controls
image: create scrollbars, click for larger image

This is an example of how to create and show scroll bar controls. Like all standard and common controls scroll bar controls are windows. They are typically used to permit viewing of parts of an object that extend beyond the borders of the window. The scroll bar control types are:

Note that the SimpleWnd example has been used with some minor modifications and the WndProc function now handles the WM_CREATE message in addition to the WM_DESTROY. This example is a 'do nothing' example serving only to demonstrate the creation and display of controls of the SCROLLBAR class. All scroll bar controls are created with the CreateWindowEx API function by varying the window styles. The API function CreateWindow can also be used.

Create Static Controls
image: create statics, click for larger image

This is an example of how to create and show static controls. Like all standard and common controls static controls are windows. They are typically used as labels and can be used to contain images such as icons and bitmaps. The static control types are:

Note that the SimpleWnd example has been used with some minor modifications and the WndProc function now handles the WM_CREATE message in addition to the WM_DESTROY. This example is a 'do nothing' example serving only to demonstrate the creation and display of controls of the STATIC class. All static controls are created with the CreateWindowEx API function by varying the window styles. The API function CreateWindow can also be used. A new API function - SendMessage - is introduced. This function is used to communicate with windows and controls.