<script language="Javascript" type="text/javascript"> </script> marginwidth="0" src="http://as.casalemedia.com/s?s=56757&u=http%3A//www.functionx.com/win32/Lesson03.htm&f=2&id=3730058213.985348" frameborder="0" width="728" scrolling="no" height="90"> |
List-Based Resources | |
|
|
Menu Creation |
A menu is one of the text-based resources. It is created directly in the rc file. As with other resources, the process of creating a menu depends on the environment you are using. If you are using Borland C++ Builder, you can open your rc file and manually create your menu. If you are using Microsoft Visual C++, you can use the built-in menu editor. In this case, the actual text that defines and describes the menu would be automatically added to the rc file. |
Practical Learning: Creating a Menu |
|
String Tables |
Introduction |
As its name indicates, a string table is a list of strings created in the resource file. Like the menu resource, the string table is created directly in the resource file. The advantage of using a string table is that the string defined in it are declared globally, meaning that they can be accessed by any object of the application without being declared |
String Table Creation |
As mentioned already, a string table is created in the rc file. Therefore, in Borland C++ Builder and other environments, the list can be manually entered in the resource file. In Visual C++, to create the list, you can add the String Table from the Add Resource dialog box. This opens a special window in which you can edit each string. Besides new strings you create in the list with their own new identifiers, you can also use the string table to assign strings to already created identifiers. For example, to can assign a string to some or all of the menu items we created earlier. After creating a string table, you can access any of its strings from anywhere in the application. To access a string, call the LoadString() function. |
Practical Learning: Creating and Using a String Table |
|
Toolbars |
Introduction |
A toolbar is an object used to let the user perform actions on an application. Like the menu, the toolbar provides a list of commands. While a menu may require various actions to get to the desired command, a toolbar presents buttons that would lead to the same actions as the menu, only faster. As such, a toolbar is mainly made of buttons placed on it, but a toolbar can also contain many other types of controls. |
Toolbar Creation |
A toolbar is primarily made of buttons that each displays a small icon, typically 16x16. If you intend to create this type of toolbar, you can start by creating one or more pictures. There are two main types of pictures you would use. The first type uses a kind of picture called a bitmap (we will learn about bitmaps in future lessons). You can create a long picture resource that has a height of 16 pixels (a toolbar can also be taller than that but this height is the most common). Then, add a factor of 16 pixels width for each desired button. This means that, if the toolbar will have one button, you can create a bitmap of 16x16 pixels. If the toolbar will have 4 buttons, you can create a bitmap of height = 16pixels and width = 16 * 4 = 64pixels. After creating this type of bitmap, save it and give it an identifier. The other type of toolbar can use icons that each is created on its own. Like most other objects you will use in your applications, a toolbar should have an identifier. This would help you and Windows identifier the toolbar. Since a toolbar is made of small buttons, each button is an object of type TBBUTTON. The TBBUTTON structure is defined as follows: typedef struct _TBBUTTON { int iBitmap; int idCommand; BYTE fsState; BYTE fsStyle; #ifdef _WIN64 BYTE bReserved[6] // padding for alignment #elif defined(_WIN32) BYTE bReserved[2] // padding for alignment #endif DWORD_PTR dwData; INT_PTR iString; } TBBUTTON, NEAR *PTBBUTTON *LPTBBUTTON; The buttons are stored in an array of TBBUTTON values. Unlike the other resources we have used so far, to add a toolbar to your application, you must programmatically create it. To do this, call either the CreateWindowEx or the CreateToolbarEx() function. The syntax of the CreateToolbarEx() function is: HWND CreateToolbarEx(HWND hwnd, DWORD ws, UINT wID, int nBitmaps, HINSTANCE hBMInst, UINT_PTR wBMID, LPCTBBUTTON lpButtons, int iNumButtons, int dxButton, int dyButton, int dxBitmap, int dyBitmap, UINT uStructSize ); The first argument is the window that serves as the parent to the toolbar. This is usually the first window you would have created. The second argument specifies the style used to display the toolbar. This parameter is a combination of windows styles and toolbar styles. The third argument is the identifier of the toolbar. The nBitmaps is used to specify the number of pictures included in the bitmap you will use The hBMInst is the application that will manage the toolbar The hBMID is an identifier of the bitmap The lpButtons argument is a pointer to the array of TBBUTTON values you have defined already. The iNumButtons specifies the number of buttons that will be created on the toolbar The dxButton and dyButton parameters represent the dimension of each button The dxBitmap and dyBitmap parameters represent the dimension of the bitmap that will be used on the buttons The last argument is the size of the TBBUTTON structure. The functions and classes (actually, structures) used to create and manage a toolbar are defined in the commctrl.h header file. The commctrl.h header is part of the comctl32.lib library. This library is not carried by the windows.h header or its associated libraries. Therefore, since the toolbar belongs to the family of Common Controls, you must explicitly add the comctl32.lib library whenever you want to use one of them. |
Practical Learning: Creating a Toolbar |
|
| ||
Previous | Copyright © 2004-2005 FunctionX, Inc. | Next |
|