Using Tab Controls
This topic contains two examples that use tab controls. The first example demonstrates how to use a tab control to switch between multiple pages of text in an application's main window. The second example demonstrates how to use a tab control to switch between multiple pages of controls in a dialog box.
In this section
| Topic | Description |
|---|---|
|
The example in this section demonstrates how to create a tab control and display it in the client area of the application's main window. The application displays a third window (a static control) in the display area of the tab control. The parent window positions and sizes the tab control and static control when it processes the WM_SIZE message. There are seven tabs in this example, one for each day of the week. When the user selects a tab, the application displays the name of the corresponding day in the static control. | |
|
The example in this section demonstrates how to create a dialog box that uses tabs to provide multiple pages of controls. The main dialog box is a modal dialog box. Each page of controls is defined by a dialog box template that has the WS_CHILD style. When a tab is selected, a modeless dialog box is created for the incoming page and the dialog box for the outgoing page is destroyed. Note In many cases, you can implement multiple-page dialog boxes more easily by using property sheets. For more information about property sheets, see About Property Sheets. The template for the main dialog box simply defines two button controls. When processing the WM_INITDIALOG message, the dialog box procedure creates a tab control and loads the dialog box template resources for each of the child dialog boxes. |
Send comments about this topic to Microsoft
Build date: 3/6/2012
- 6/21/2010
- MrPhilTX
- 11/25/2009
- Marine Instruments
GetDialogBaseUnits() assumes you are using the system font.
If you are using another font, change
DWORD dwDlgBase = GetDialogBaseUnits();
int cxMargin = LOWORD(dwDlgBase) / 4;
int cyMargin = HIWORD(dwDlgBase) / 8;
to
RECT rc;
rc.right = 4;
rc.bottom = 8;
MapDialogRect(hwndDlg, &rc);
int baseUnitX = rc.right;
int baseUnitY = rc.bottom;
int cxMargin = baseUnitX / 4;
int cyMargin = baseUnitY / 8;
and change
rcTab.right = rcTab.right * LOWORD(dwDlgBase) / 4;
rcTab.bottom = rcTab.bottom * HIWORD(dwDlgBase) / 8;
to
rcTab.right = rcTab.right * baseUnitX / 4;
rcTab.bottom = rcTab.bottom * baseUnitY / 8;
- 12/2/2008
- atomic inferno
- 12/2/2008
- atomic inferno
Dialog Example Warning
The line:
HRSRC hrsrc = FindResource(NULL, lpszResName, RT_DIALOG);
assumes the resource you are looking for exists in the "main exe". However, this might not be the case, so whatever you pass into "LoadResource" on the next line:
HGLOBAL hglb = LoadResource(g_hinst, hrsrc);
You will need to pass that HINSTANCE into FindResource instead of NULL. Just a "gotcha" that you might not be expecting when using sample code snippets. My final code is:
HRSRC hrsrc = FindResource(g_hinst, lpszResName, RT_DIALOG);
HGLOBAL hglb = LoadResource(g_hinst, hrsrc);
Once I fixed that up, loading in a DLL worked fine. Don't forget error checking!
- 8/18/2008
- pushedx