看看SetMenuItemBitmaps的返回值,有没成功?Pic直接用TBitmap试试。

解决方案 »

  1.   

    PopupMenu的Handle好象是空的,每次Popup时都会重新创建菜单项,所以你的方法无效。如果你要根据它来赋的话,可能需要在响应OnPopup事件中处理(这还不一定奏效)。TMenuItem中有Bitmap属性,你可以利用它。procedure TForm1.LoadMenuIcon;
    const
      mn: array [1..3] of string=('Setup', 'Help', 'About');
    var
      i: integer;
    begin
      for i:=1 to 3 do
        PopupMenu1.Items[i-1].Bitmap.LoadFromResourceName(hInstance, mn[i]);
    end;
      

  2.   

    >PopupMenu的Handle好象是空的我的意思是:得到的菜单句柄中没有菜单项。
      

  3.   

    to agui(阿贵)
    >PopupMenu的Handle好象是空的,每次Popup时都会重新创建菜单项,所以你的方法无效.你的话有点问题,每次Popup的Handle,确实不一样,但是并不是因为不一样就不能用它。
    那个函数是API函数,我想也许Windows的Menu和Delphi有点不一样。还是agui(阿贵后来的方法好,这才是Delphi的方法。
      

  4.   

    说:“PopupMenu的Handle好象是空”的朋友,
    错。
    我曾在一个没有其他功能的简单程序中测试这种方法,如下
    SetMenuItemBitmaps(PopupMenu1.Handle, 0, MF_BYPOSITION,
      image1.Picture.Bitmap.Handle, image1.Picture.Bitmap.Handle);
    (在Form1。ONCreate中)
    就完全没问题,真奇怪。
      

  5.   

    “PopupMenu的Handle好象是空”我只是说好象嘛,没有很肯定啊。:)MSDN如是说:
    When the menu is destroyed, these bitmaps are not destroyed; it is up to the application to destroy them. 
    我怀疑Windows并没有复制位图数据,只是复制了句柄。所以你应该在程序中保存位图的句柄,直到窗体Destroy时再将它释放掉。用TPicture对象会将位图数据销毁掉(在给Bitmap赋值和Free时)。建议你用HBITMAP的数组保存,用LoadBitmap装载,然后在FormDestroy中释放,调用DeleteObject。The selected and clear bitmaps should be monochrome. The system uses the Boolean AND operator to combine bitmaps with the menu so that the white part becomes transparent and the black part becomes the menu-item color. If you use color bitmaps, the results may be undesirable.
    这个算是一个提示吧,它不保证彩色位图是否会正确显示。
      

  6.   

    谢谢各位,最新研究成果:
    给用全局变量,
    并放在Onpopup中
    可以显示,但问题是:
    1、一开始没有,知道在菜单上动动才出图
    2、图的颜色被减掉,大概成了256色
    那么多软件都可以,不会没办法吧,
    请大家帮我,最好能有成功的代码离子
    谢!
      

  7.   

    Delphi3的TMenuItem中有没有自绘的事件啊?如果有,就自己画好了。Delphi4以上有OnDrawItem。TMenuDrawItemEvent = procedure (Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean) of object;
      

  8.   

    一个方法,升级到Delphi4,很容易的,向下兼容