| Header file: | toolbar.h |
| Object name: | fTOOLBAR |
| Object index: | 1 of 1 Object |
The fTOOLBAR creates - yes, you guessed it - a toolbar! So far I have not had much luck with this class, and thus, it doesn't really work well. However, you can create a toolbar, and play with it a bit. I have not figured out how to make it go onto one of those rebar things - so that you can move it around. Just play with it should you wish to.
This component is derived from _GUIBASE, and inherits the properties from that.
When creating a toolbar window, just use 0 (Zero) for primary options, and AvWind for secondary options.
| Prototype | Description |
| void AllocateButtons(int Number); | This function sets up the class to handle a certain number of buttons. An amount of memory needs to be held for this, and thus this function exists. Just call it with the number of buttons that you wish to have. |
| void CleanUp(void); | When you are done, or if you want to reset your toolbar, just call this function to de-allocate the memory that the class set aside for the toolbar. You'll actually have to destroy the toolbar to reset it. |
| void AddBitmap(int Number, HINSTANCE Instance, int ID); |
This function sets the bitmap for a particular button. Number is the number of the bitmap - which starts at 0 (Zero). Instance is the module to load the bitmap from, and ID is the ID of the bitmap to load. If you just want to use the current program's resources, just set Instance to GetModuleHandle(NULL).
|
| void AddBitmap(int Number, int ID); |
This function sets the bitmap for a button from an internal Windows set. Number is the number of the bitmap to store this as - Number starts at 0 (Zero) and works up from there. ID can be a mixture of two values, the first being from the top list, and the second being from the bottom list, as follows (taken from the Win32 SDK Reference Manual):
|
| void AddBitmaps(void); | This function just updates all the bitmaps. Ordinarily, the bitmaps are updated as you add them - but just in case, you can use this function to update them. |
| void AddButton(int Number, int ID, int BitmapIndex, int Style, int State); |
This function sets the properties for a button - it will still need to be one of the buttons that you previously allocated. Number is the number of the button which starts at 0 (Zero). ID is the ID of the button, for use when trapping events. BitmapIndex is the number of the bitmap to use - and will be a number that you used when adding a bitmap with the AddBitmap() functions. Style can be one of the following (taken from somewhere, probably the MSDN online SDK reference):
|
| void ChangeBitmap(int Number, int BitmapIndex); | This function changes the bitmap for a certain button. Number indicates the number of the button to change the bitmap for. Number starts at 0 (Zero) and moves upwards. BitmapIndex is the number of the bitmap to change to. |
As this component is not working fully, it was not integrated into the GUI Controller. However, you can still use the GUI controller to do things - via the Menu Controller portion.
The following code shows how you can intercept messages with the GUI controller.
MENUCONTROLLER.AddMenu(TOOLBAR_BUTTON_ID, &FunctionToCall, NULL);
//Where function to call looks like this:
void FunctionToCall(HWND Parent, int ID);
You'll have to add one of these entries for each button, pointing it towards the function that you want. I'd suggest setting this early on - like as your program is starting.
Now what if you are not using the GUI Controller? Don't worry, there are other ways. Instead of using that, you'll have to intercept the WM_COMMAND message sent to the parent window, as shown in the following code.
//In the message queue for the parent window (parent to
//the toolbar).
case WM_COMMAND:
//Check to see which button:
if (wParam == TOOLBAR_BUTTON_ID)
{
//If we got here, then whatever button corresponds
//to TOOLBAR_BUTTON_ID was clicked.
}
break;
There, now that wasn't too hard, was it?
The following snippet gives a basic idea of how to use this component.
//Ok, create a toolbar.
fTOOLBAR Toolbar;
Toolbar.AllocateButtons(5); //5 Button toolbar...
//Create the toolbar on the window...
Toolbar.CreateWin(Window.GetHandle(), "ToolBar Title",
TOTAL_TOOLBAR_ID, 0, AvWind);
//Now BITMAPS are independent of BUTTONS.
Toolbar.AddBitmap(0, GetModuleHandle(NULL), 10); //Bitmap 10 from resources.
Toolbar.AddBitmap(1, GetModuleHandle(NULL), 11);
Toolbar.AddBitmap(2, GetModuleHandle(NULL), 12);
Toolbar.AddBitmap(3, GetModuleHandle(NULL), 13);
Toolbar.AddBitmap(4, GetModuleHandle(NULL), 14);
//Now add some buttons!
Toolbar.AddButtons(0, BUTTON1_ID, 4, TBSTYLE_BUTTON, TBSTATE_ENABLED);
//The above function: Button Number, ID, Bitmap Number, Style, State.
//Note that Bitmap Number is 4 - ie. the last bitmap that you
//added. Bitmaps can be in any order - you just need to set
//the number of the bitmap for each button.
Toolbar.AddButtons(1, BUTTON2_ID, 1, TBSTYLE_BUTTON, TBSTATE_ENABLED);
Toolbar.AddButtons(2, BUTTON2_ID, 0, TBSTYLE_BUTTON, TBSTATE_ENABLED);
Toolbar.AddButtons(3, BUTTON2_ID, 3, TBSTYLE_BUTTON, TBSTATE_ENABLED);
Toolbar.AddButtons(4, BUTTON2_ID, 2, TBSTYLE_BUTTON, TBSTATE_ENABLED);
//Got it? Oh well... just fiddle.
| Back to index | The FreeFoote Foundation Classes Documentation |