PopUpMenus with bitmaps within their items  

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

Tip accessed 461 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 PopUpMenu (PopUpMenu1)
  • Add a item in the menu and assign the menu, by example to Form1 (to be able to see it)
  • Define these global variables to your form (that is to say, put them in the var of the form)


     var
       Form1          : TForm1;
       bmpChequeado,
       bmpNoChequeado : TBitmap;
    



  • Now, put this code in the OnCreate event of the form, to create 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(PopUpMenu1.handle,
                          0,
                          MF_BYPOSITION,
                          bmpNOChequeado.Handle,
                          bmpChequeado.Handle);
     end;
    
    



    Of course, you could assign the same bitmap as much for a state as for the another...

  • Before we forget it, we will put in the event OnDestroy of the form the code to free the two bitmaps:


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