Click to See Complete Forum and Search --> : toolbar icons


qfang
September 28th, 1999, 12:05 PM
I am using VC6 and I tried to create my own toolbar. I have several small bitmap files I want to put in toolbar. How can I do it?

Kelly
September 28th, 1999, 12:33 PM
Hi,
Using the resource editor, the toolbar button images/icons must all be the same size. Moreover, they are all sourced from the same .bmp file as sequential image "segments" that are extracted by the framework. If you have some select images that you want to drop in there, one way to do it would be to open the desired bitmap in MS Paint and select the part of the image that you want in your toolbar, then COPY it to the windows clipboard. Then go back to VS6, open your toolbar, and PASTE your clipboard image into the toolbar at the selected button position. The grid lines can be very hgelpful in lining up your images by hand like this if you are in the bitmap view of the toolbar rather than the toolbar view (in the menu, image->[X]Toolbar Editor). Being new to VS6 myself, I've found myself having to edit the project.rs file manually from time to time to properly place the toolbar separators. Perhaps there is a way to do it in Toolbar Editor mode?

--Kelly

qfang
September 28th, 1999, 03:42 PM
thanks! But how can I insert disabled images?

Kelly
September 29th, 1999, 12:40 PM
Hi,
You don't "insert" diabled images into a toolbar. The "disabled" images which you are accustomed to seeing in the toolbars of other applications are generated by the MFC framework using basic pixel edge detection. You supply the "enabled" images and insert them into the toolbar, and MFC converts the images to "disabled" as appropriate. And "as appropriate" is only when there is no message handler for the button. For example:

you have a dov-view app which has a small toolbar for manipulating the content of your document. WHen the user has documents open, the appdoc.cpp contains a message map which handles messages for the document. An example from one of my applications is here:

BEGIN_MESSAGE_MAP(CUtilityDoc, CDocument)
//{{AFX_MSG_MAP(CUtilityDoc)
//}}AFX_MSG_MAP
ON_COMMAND(ID_PRINT_PREVIEW, CUtilityDoc::OnPrintPreview)
ON_COMMAND(ID_BMP_ROTATE, CUtilityDoc::OnBmpRotate)
END_MESSAGE_MAP()

So when the user clicks on the toolbar button with the ID_PRINT_PREVIEW, the call is dispatched to the OnPrintPreview() handler. Now, when the user is finished manipulating the document and closes it, the Message Map becomes invalid, and there is no longer a message handler for the ID_PRINT_PREVIEW. MFC automatically converts menu items and toolbar items (other things too?) to their "disabled" state. And, as I said, it will supply the disabled toobar image for you based on your original enabled image.

The moral of the story is this: so long as there is a message handler for yout button, the button should be active. In order to activate/deactivate buttons, the buttons' message handlers should be handled by classes which you create/destroy (or in the case of doc/view are created when ID_FILE_OPEN creates the application doc class.)

I hope this helps clarify things, (and that I'm not mistaken in any of this info!),
--Kelly