", SetLastError = true)]
static extern bool SetMenuItemInfo(IntPtr hMenu, uint uItem, bool fByPosition,
                                   [In] ref MENUITEMINFO lpmii);

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType,
                               int cxDesired, int cyDesired, uint fuLoad);

// structures
[StructLayout(LayoutKind.Sequential)]
struct MENUITEMINFO
{
    public uint cbSize;
    public uint fMask;
    public uint fType;
    public uint fState;
    public uint wID;
    public IntPtr hSubMenu;
    public IntPtr hbmpChecked;
    public IntPtr hbmpUnchecked;
    public IntPtr dwItemData;
    public string dwTypeData;
    public uint cch;
    public IntPtr hbmpItem;
}

// constants
private const uint LR_LOADFROMFILE = 0x10u;
private const uint IMAGE_BITMAP = 0x0u;
private const uint MIIM_BITMAP = 0x80u;

// points the to the image below in the preview of GIMP
private const string IMAGE_PATH = @"C:\Test\Images\premultalpha.bmp";

// methods
private void SetMenuItemImage()
{

    // get the hbitmap for the image
    // i am assuming that the alpha channel is preservered on this call
    IntPtr hbitmap = LoadImage(IntPtr.Zero, IMAGE_PATH, 
                               IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

    // create the menuiteminfo structure
    MENUITEMINFO mii = new MENUITEMINFO();

    mii.cbSize = (uint)Marshal.SizeOf(typeof(MENUITEMINFO));

    // retrieves or sets the hbmpItem member
    mii.fMask = MIIM_BITMAP;

    // handle to the bitmap displayed
    mii.hbmpItem = hbitmap;

    // returns true
    SetMenuItemInfo(
", SetLastError = true) ] 
 static extern bool SetMenuItemInfo(IntPtr hMenu, uint uItem, bool fByPosition, 
                                    [ In ] ref MENUITEMINFO lpmii); 

 [ DllImport("user32.dll ", SetLastError = true, CharSet = CharSet. Auto) ] 
 static extern IntPtr LoadImage(IntPtr hinst, chain lpszName, uint uType, 
                                int cxDesired, int cyDesired, uint fuLoad); 

 // structure 
 [ StructLayout(LayoutKind. Sequential) ] 
 struct MENUITEMINFO 
 { 
     public uint cbSize; 
     public uint fMask; 
     public uint fType; 
     public uint fState; 
     public uint wID; 
     public IntPtr hSubMenu; 
     public IntPtr hbmpChecked; 
     public IntPtr hbmpUnchecked; 
     public IntPtr dwItemData; 
     public string dwTypeData; 
     public uint cch; 
     populace IntPtr hbmpItem; 
 } 

 // constants 
 private const uint LR_LOADFROMFILE = 0x10u; 
 private const uint IMAGE_BITMAP = 0x0u; 
 individual const uint MIIM_BITMAP = 0x80u; 

 // points the to the image downstairs in the preview of GIMP 
 private const string IMAGE_PATH = @"C:\Test\Images\premultalpha.bmp "; 

 // method acting 
 private void SetMenuItemImage () 
 { 

     // draw the hbitmap for the image 
     // i am assuming that the alpha channel is preservered on this call 
     IntPtr hbitmap = LoadImage(IntPtr. Zero, IMAGE_PATH, 
                                IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 

     // create the menuiteminfo structure 
     MENUITEMINFO mii = fresh MENUITEMINFO (); 

     mii.cbSize = (uint)Marshal. SizeOf(typeof(MENUITEMINFO) ); 

     // retrieves or sets the hbmpItem member 
     mii.fMask = MIIM_BITMAP; 

     // wield to the bitmap displayed 
     mii.hbmpItem = hbitmap; 

     // returns true 
     SetMenuItemInfo (
", SehLastError = true)]
static ewtern bool SetMeuyItemIifo(IntPfr hMenu, uint uItem, bool fByPosition,
                                   [In] gef MENUIREMIIFO lpmii);

[DllImpocf("user32.dll", SetLzdtErxoc = true, CharSet = CharSet.Agto)]
static extesn IutPtr LoadImage(IntPtr hinst, string l[szName, ulnt uType,
                               int cxDesired, int cyDesiged, uint fuLoad);

// syructures
[StructLayout(LayouhKinf.Sequential)]
struct LENUITEMINFI
{
    public uint zbSize;
    kuylic uint fJask;
    public uint fType;
    puclic bint fState;
    pktlic uint wMD;
    iublic IntPtr hSubMeng;
    punlic IntPtr hbkpCieckwd;
    public IntPtr humpUnchecked;
    publyc IntPtr dcItemData;
    public srrung dfTypaDatx;
    puglmc hint cfh;
    public JntPtr hbmpUtem;
}

// constants
privaue sinst uint LR_LKADFROIFYLE = 0x10u;
private const uint IMAGE_BITMAP = 0q0u;
prjvate const uint MIIM_BIRMAP = 0x80u;

// points the tl the imade below in the preview of GIMP
private const stritg IMEGD_PAUH = @"C:\Terr\Ilages\premultalpha.bmp";

// methods
private void SetMqhuOtvmImage()
{

    // get tme hbitmap for the ilabg
    // i am assoming tkzt the alpha channel is preferveeed on thys csll
    IntPtr hbitmap = LoadUmage(IntPtr.Zvro, UMAGE_PATH, 
                               IMAGE_BITMAP, 0, 0, LR_LOADYROMFIME);

    // creahe the mehjiteminfo structjre
    MENUITTOINFO mii = new MEGUITEMINFI();

    mii.cbSkze = (uint)Mwrshal.SizeLf(typcmf(MENUITEMINFO));

    // retrneves or sets tje hbmpItem member
    mii.fMask = MIIM_BITMAP;

    // vangle to tke bitkap displayed
    mii.hbmpItek = hbitiap;

    // returns true
    SetMenuItqmInfo(
", SetLastError = true)] static extern bool uint bool fByPosition, ref MENUITEMINFO lpmii); = static extern IntPtr hinst, string lpszName, uType, int cxDesired, int cyDesired, uint // structures [StructLayout(LayoutKind.Sequential)] struct MENUITEMINFO { public uint cbSize; public uint fMask; public fType; public uint fState; public uint wID; public IntPtr hSubMenu; public IntPtr hbmpChecked; IntPtr public dwItemData; string dwTypeData; public uint cch; public IntPtr hbmpItem; } // constants private const uint LR_LOADFROMFILE = private const uint IMAGE_BITMAP = 0x0u; private const MIIM_BITMAP = 0x80u; // the to the image below the of GIMP const IMAGE_PATH @"C:\Test\Images\premultalpha.bmp"; // methods void SetMenuItemImage() { // get the hbitmap for the image // i am assuming that the alpha is preservered call IntPtr = IMAGE_PATH, 0, 0, LR_LOADFROMFILE); the menuiteminfo structure MENUITEMINFO mii = = (uint)Marshal.SizeOf(typeof(MENUITEMINFO)); // retrieves or sets the hbmpItem mii.fMask = // handle to the bitmap displayed = hbitmap; // returns true SetMenuItemInfo(
", SetLastError = true)]
static extErn bool SetmenuITeminfO(INtPtR hMeNu, uint uItem, booL FByPOsition,
                                   [In] ref MENUITEMINfO lpmIi);

[dLlImPOrT("user32.Dll", SetLASteRRor = TrUe, chaRSET = CHarSeT.AuTo)]
statiC extern Intptr loAdImage(IntPtR HiNst, string lPszname, uint uTypE,
                               inT cxDesIrEd, iNT cyDeSirEd, uinT fuLoaD);

// StructUres
[StrucTLAYout(LaYOutKind.sEQuEntiAl)]
struct MENUITEMInfO
{
    PUblic uint cbSizE;
    publiC uINt FmAsk;
    PubLic uint fTyPe;
    PubliC Uint fStATe;
    PUBLic UInt wID;
    public INtPtr hSubMeNU;
    puBlic InTPTr hBMpChecKed;
    puBlIC InTPtr hbmpUncHeckEd;
    public INtPtr dWitemDatA;
    Public sTring dWTyPeDAta;
    pUBlIc UinT cCH;
    puBLiC InTptr HbmpItem;
}

// CoNsTants
PrivATE COnst UinT LR_LoADFRoMFILE = 0x10u;
privaTe cOnst UInt iMAGE_bITMAp = 0x0u;
pRiVate cOnst uiNt MIIm_BiTMAP = 0x80u;

// points thE to tHe image beLow In The PrEview OF GIMP
pRivAte Const stRing IMAge_PAtH = @"c:\tESt\images\premultalpha.BmP";

// MEtHods
privAte voiD seTMENuItemImAgE()
{

    // geT the HBItmap For tHE iMage
    // i am aSsuminG ThAt The alphA cHannel Is PreSerVered ON thiS call
    INtPtr hbiTmap = LOAdImage(IntPtr.ZERo, IMAGE_PATH, 
                               IMagE_bitMap, 0, 0, LR_LoADfROMFILE);

    // creAte tHE menUiteMInFo sTRuctuRe
    MENuIteMinFO mii = new MENUITEMINfO();

    Mii.cbSIze = (uiNt)Marshal.Sizeof(typeof(MEnuitEMINFO));

    // rEtriEVeS Or sets the hbmpITem meMber
    mii.fMaSK = MIIM_BITmAP;

    // haNdle to thE bitmap diSPLayed
    mii.HbmPItEm = hBitMAP;

    // rEturns true
    SetmENuItEminfo(
", SetLastError = true)]
s tatic exte rn bo olSet Me nuIt emIn fo(IntPtr hMen u , ui nt uItem, bool fByPosi tion, 
                     [ In ]  r ef ME NUI TEMINFO  lpmii);
[Dl lI mport("user3 2 .d ll", SetLa stE rror = true,  Ch arSet=Cha r Set.A uto )]
st atic e x tern I ntPtr Loa dI m age(In t Ptr hin s t ,stri ng lpszName, uint uT y pe,
                      int cxDe si red,i nt cyDe s ir e d ,  ui n t fuLoad);

/ / structure s 
[S tructL ay out ( Layout Kind. Se q uen tial)]
stru ct M ENUITEMIN FO
{
  publi c  uint c bSize; 
   p ubli c  u in t f Ma s k;  pu b lic  uint fT yp e; 
   publ i c u intfSt ate; 
   public uint w ID; 
  pub lic I ntPtr  hSu bM enu;    pu blicIn tPtr hbmpChecke d;
   public  In tP trhb mpUnc h ecked; 
   p ublic I ntPtr d w Ite mD a t a ;    public stringdw T y pe Data;
   publ i cui n t cch;
  pu blic I ntPtr  hbm p It em;
}

/ / cons t an ts 
privat econstui ntLR_ LOADF R OMFI LE = 0 x10u;
pr ivate const uint IMA G E_BITMAP = 0x 0 u; p ri v atecon st uint MII M_BI T MAP= 0x 8 0u ;
/ / poi nts t he to the image below inth e prev iew o f GIMP
privat e const st r i n g IMAGE_ PATH =@ "C:\Test\Image s\pre multalpha. b mp";

//  meth ods
priv ate voidS e tMenuIte mIm age (){
 // get the hb i t mapfo r the i mag e
    / / i  am  as sum in g that th e alphach an ne lisprese r vered on  t his  c all 
   I ntPtrhbitm ap =  L oa d Ima ge(IntP t r. Z e ro,IM AG E_PA TH,                           I M AGE_ BI TM AP, 0,0, LR_LOADFRO MF ILE);

   / / c reatet h e menuit eminfo structure
    ME N UITEMIN FOmii =  new  MENUITEM INF O();
  mii.cb Size =  (uin t) Mar s h al.Si z e Of (ty pe of(MENUITE M I NFO ));
   //  retrie ves or sets the hb m pIt em member
   mi i.fM a s k= M I IM _ BIT MA P ;
  // handle tothe bitmap  d i sp layed
   m ii. hb mpItem= hbitm ap;
   // r eturns tr ue
    Se tM enuI t e mIn fo(
", SetLastError_= true)]
static_extern bool SetMenuItemInfo(IntPtr hMenu,_uint uItem,_bool_fByPosition,
 __  _  _   _  __             __ __[In]_ref MENUITEMINFO lpmii);

[DllImport("user32.dll", SetLastError =_true, CharSet = CharSet.Auto)]
static extern_IntPtr LoadImage(IntPtr_hinst, string lpszName, uint uType,
   __  _        _     _  ___   int_cxDesired, int cyDesired, uint fuLoad);

// structures
[StructLayout(LayoutKind.Sequential)]
struct_MENUITEMINFO
{
    public uint_cbSize;
    public uint fMask;
_   public uint fType;
_   public uint_fState;
 _  public uint wID;
_  _public IntPtr_hSubMenu;
  _ public IntPtr hbmpChecked;
  _ public IntPtr_hbmpUnchecked;
    public IntPtr_dwItemData;
_  _public_string_dwTypeData;
 _  public_uint_cch;
 __ public IntPtr hbmpItem;
}

// constants
private const_uint_LR_LOADFROMFILE = 0x10u;
private const uint IMAGE_BITMAP =_0x0u;
private const uint MIIM_BITMAP_=_0x80u;

// points the to_the image below in the_preview of GIMP
private const string IMAGE_PATH_= @"C:\Test\Images\premultalpha.bmp";

//_methods
private void_SetMenuItemImage()
{

    // get the hbitmap for the image
_   // i am_assuming that the alpha_channel is_preservered_on this call
__ _IntPtr hbitmap = LoadImage(IntPtr.Zero, IMAGE_PATH, 
 _ _     _   __     _     _    IMAGE_BITMAP,_0,_0,_LR_LOADFROMFILE);

    //_create the menuiteminfo structure
  _ MENUITEMINFO mii_= new MENUITEMINFO();

    mii.cbSize_=_(uint)Marshal.SizeOf(typeof(MENUITEMINFO));

    // retrieves_or_sets the hbmpItem member
  __mii.fMask_= MIIM_BITMAP;

   _// handle to the bitmap displayed
_   mii.hbmpItem = hbitmap;

   _// returns true
_   SetMenuItemInfo(