MainMenus with bitmaps in items  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 09/10/99

Tip accessed 496 times

 


To put a bitmap in an option of our menu, it is enough with being assigned it by means of the function SetMenuItemBitmaps.
This function allows us to specify two bitmaps: one when the option of the menu is ' Checked' and another for when he is not.

An example:

  • Make a MainMenu (MainMenu1)
  • Add one item in the menu, and name it 'Uno', and in this Item, make a PopUp menu and name it 'Dos'
  • Declare this global variables in your form (put in the var of the Form):


     var
       Form1          : TForm1;
       bmpChequeado,
       bmpNoChequeado : TBitmap;
    



  • Now, put this code in the OnCreate event of the Form, to inizializate and load the two bitmaps:


     procedure TForm1.FormCreate(Sender: TObject);
     begin
       bmpChequeado := TBitmap.Create;
       bmpChequeado.LoadFromFile('C:\Fuentes\Delphi\TrucomaniaExplorer\esp.bmp');
       bmpNOChequeado := TBitmap.Create;
       bmpNOChequeado.LoadFromFile('C:\Fuentes\Delphi\TrucomaniaExplorer\ing.bmp');
       {Add the bitmaps to the Item 0 of the PopUp}
       {Aņadimos los bitmap al item 0 del menu}
       SetMenuItemBitmaps(Uno.handle,
                          0,
                          MF_BYPOSITION,
                          bmpNOChequeado.Handle,
                          bmpChequeado.Handle);
     end;
    
    



    In this example, we assign the bitmap to item 0 of the MenuItem named 'Uno', it's to say the item called 'Dos'
    Of course, you can use a single bitmap for the two states...

  • At finish, put this code in the OnDestroy event of the form to free the bitmaps:


     procedure TForm1.FormDestroy(Sender: TObject);
     begin
       bmpChequeado.Free;
       bmpNOChequeado.Free;
     end;