with Message.DrawItemStruct^ do
是啥意思???????

解决方案 »

  1.   

    是表示指针Message.DrawItemStruct指向的东西。
    如果该该指针指向的东西是具有成员的,如对象,结构等,就可在其后语句里省略描述这个东西,而直接写出这个东西的成员名就可以操纵该成员了。
      

  2.   

    另请问在DELPHI中如何实现Microsoft Start Menu的效果?
      

  3.   

    这是我在以前的帖子中找到的,但编译时老报错(在*****的位置),请高手指点1、设置TPopupMenu的OwnerDraw为True;
    2、设置TPopupMenu的Images
    3、设置TMenuItem的OnMeasureItem和OnDrawItem分别指向两个例程。procedure TfrmMain.pmTrayPopup(Sender: TObject);
    begin
      pmTray.Tag := 1;  //对于左边的位图保证只绘制一次
    end;procedure TfrmMain.MenuMeasureItem(Sender: TObject; ACanvas: TCanvas;
      var Width, Height: Integer);
    begin
      if (Sender as TMenuItem).IsLine then 
        Height := 4 //分隔条
      else
        Height := Canvas.TextHeight('高') + 6;
      //const BMWidth = 位图宽度
      Inc(Width, BMWidth + 7); //为左边的位图保留一些空间
    end;procedure TfrmMain.MenuDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    var ABitmap: TBitmap;
        Item: TMenuItem;
        Rc: TRect;
        nLeft, nTop: Integer;
        Ico: HICON;
    begin
      Item := Sender as TMenuItem;
      ABitmap := TBitmap.Create;
      try
        //对于左边的位图保证只绘制一次
        if (pmTray.Tag = 1) and (Item.MenuIndex = 0) then 
        begin
          pmTray.Tag := 0;
          ABitmap.LoadFromResourceID(hInstance, PostMan); //左边图形的ResourceID
          CopyRect(Rc, ACanvas.ClipRect);
          Rc.Left := BMWidth + 2;
          CopyRect(Rc, ACanvas.ClipRect);
          Rc.Right := Rc.Left + BMWidth + 2;
          //用图形左下的颜色填充矩形
          ACanvas.Brush.Color := ABitmap.Canvas.Pixels[0, ABitmap.Height - 1];
          ACanvas.FillRect(Rc);
          //绘制一个凹下的矩形框
          Frame3D(ACanvas, Rc, clBtnShadow, clBtnHighlight, 1);
          ACanvas.Draw(Rc.Left, Rc.Top, ABitmap);
          //绘制Application图标
          Ico := LoadImage(hInstance, PChar(szMainIcon), IMAGE_ICON, 16, 16, 
                          LR_DEFAULTCOLOR);
          nLeft := (BMWidth - 16) div 2 + 1;
          DrawIconEx(ACanvas.Handle, nLeft, Rc.Bottom - nLeft - 16, 
                    Ico, 16, 16, 0, 0, DI_NORMAL);
          DestroyIcon(Ico);
          ACanvas.Brush.Color := clBtnFace;
        end;
        CopyRect(Rc, ARect);
        Inc(Rc.Left, BMWidth + 2);
        nTop := Grade + Ord(Selected);
        //绘制背景图形
        ABitmap.LoadFromResourceID(hInstance, nTop);   ***********************************************************
        ACanvas.CopyRect(Rc, ABitmap.Canvas, Rect(0, 0, ABitmap.Width, ABitmap.Height));
        if Item.IsLine then //绘制菜单分隔条
        begin
          nTop := (ARect.Bottom + ARect.Top) div 2 - 1;
          ACanvas.Pen.Color := clBtnShadow;
          ACanvas.MoveTo(BMWidth + 3, nTop);
          ACanvas.LineTo(ARect.Right, nTop);
          ACanvas.Pen.Color := clBtnHighlight;
          ACanvas.MoveTo(BMWidth + 3, nTop + 1);
          ACanvas.LineTo(ARect.Right, nTop + 1);
        end else
        begin
          nTop :=  (Rc.Bottom + Rc.Top - imglstState.Height) div 2;
          nLeft := Rc.Left + (Rc.Bottom - Rc.Top - imglstState.Width) div 2 + 2;
          if Selected then //绘制被选择菜单的外观
          begin
            with Rc do
            Right := Left + Bottom - Top;
            DrawEdge(ACanvas.Handle, Rc, BDR_RAISEDINNER, BF_RECT);
            Inc(Rc.Left, Rc.Bottom - Rc.Top + 1);
            Rc.Right := ARect.Right;
            DrawEdge(ACanvas.Handle, Rc, BDR_SUNKENOUTER, BF_RECT);
          end;
          //绘制菜单前面的小图形,一个TImageList
          imglstState.Draw(ACanvas, nLeft - 1, nTop, Item.ImageIndex, Item.Enabled);
          CopyRect(Rc, ARect);
          InflateRect(Rc, -1, -1);
          Inc(Rc.Left, BMWidth + ARect.Bottom - ARect.Top + 6);
          ACanvas.Brush.Style := bsClear;
          if not Item.Enabled then
          begin
            OffsetRect(Rc, 1, 1);
            ACanvas.Font.Color := clBtnHighlight;
          end else
          with ACanvas.Font do
          if Selected then Color := clRed else Color := clBtnText;
          ACanvas.Brush.Style := bsClear;
          if Item.Enabled or (not Selected) then
          DrawText(ACanvas.Handle, PChar(Item.Caption), Length(Item.Caption), Rc,
                  DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS);
          if not Item.Enabled then
          begin
            OffsetRect(Rc, -1, -1);
            ACanvas.Font.Color := clBtnShadow;
            DrawText(ACanvas.Handle, PChar(Item.Caption), Length(Item.Caption), Rc,
                    DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS);
          end;    
        end;
      finally
        ABitmap.Free;
      end;    
    end;
     
      

  4.   

    sorry !标错了
    应在下面的位置procedure TfrmMain.pmTrayPopup(Sender: TObject);
    begin
      pmTray.Tag := 1;  //对于左边的位图保证只绘制一次
    end;procedure TfrmMain.MenuMeasureItem(Sender: TObject; ACanvas: TCanvas;
      var Width, Height: Integer);
    begin
      if (Sender as TMenuItem).IsLine then 
        Height := 4 //分隔条
      else
        Height := Canvas.TextHeight('高') + 6;
      //const BMWidth = 位图宽度
      Inc(Width, BMWidth + 7); //为左边的位图保留一些空间
    end;procedure TfrmMain.MenuDrawItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
    var ABitmap: TBitmap;
        Item: TMenuItem;
        Rc: TRect;
        nLeft, nTop: Integer;
        Ico: HICON;
    begin
      Item := Sender as TMenuItem;
      ABitmap := TBitmap.Create;
      try
        //对于左边的位图保证只绘制一次
        if (pmTray.Tag = 1) and (Item.MenuIndex = 0) then 
        begin
          pmTray.Tag := 0;
          ABitmap.LoadFromResourceID(hInstance, PostMan); //左边图形的ResourceID********************************************************************************************************
          CopyRect(Rc, ACanvas.ClipRect);
          Rc.Left := BMWidth + 2;
          CopyRect(Rc, ACanvas.ClipRect);
          Rc.Right := Rc.Left + BMWidth + 2;
          //用图形左下的颜色填充矩形
          ACanvas.Brush.Color := ABitmap.Canvas.Pixels[0, ABitmap.Height - 1];
          ACanvas.FillRect(Rc);
          //绘制一个凹下的矩形框
          Frame3D(ACanvas, Rc, clBtnShadow, clBtnHighlight, 1);
          ACanvas.Draw(Rc.Left, Rc.Top, ABitmap);
          //绘制Application图标
          Ico := LoadImage(hInstance, PChar(szMainIcon), IMAGE_ICON, 16, 16, 
                          LR_DEFAULTCOLOR);
          nLeft := (BMWidth - 16) div 2 + 1;
          DrawIconEx(ACanvas.Handle, nLeft, Rc.Bottom - nLeft - 16, 
                    Ico, 16, 16, 0, 0, DI_NORMAL);
          DestroyIcon(Ico);
          ACanvas.Brush.Color := clBtnFace;
        end;
        CopyRect(Rc, ARect);
        Inc(Rc.Left, BMWidth + 2);
        nTop := Grade + Ord(Selected);
        //绘制背景图形
        ABitmap.LoadFromResourceID(hInstance, nTop);  
        ACanvas.CopyRect(Rc, ABitmap.Canvas, Rect(0, 0, ABitmap.Width, ABitmap.Height));
        if Item.IsLine then //绘制菜单分隔条
        begin
          nTop := (ARect.Bottom + ARect.Top) div 2 - 1;
          ACanvas.Pen.Color := clBtnShadow;
          ACanvas.MoveTo(BMWidth + 3, nTop);
          ACanvas.LineTo(ARect.Right, nTop);
          ACanvas.Pen.Color := clBtnHighlight;
          ACanvas.MoveTo(BMWidth + 3, nTop + 1);
          ACanvas.LineTo(ARect.Right, nTop + 1);
        end else
        begin
          nTop :=  (Rc.Bottom + Rc.Top - imglstState.Height) div 2;
          nLeft := Rc.Left + (Rc.Bottom - Rc.Top - imglstState.Width) div 2 + 2;
          if Selected then //绘制被选择菜单的外观
          begin
            with Rc do
            Right := Left + Bottom - Top;
            DrawEdge(ACanvas.Handle, Rc, BDR_RAISEDINNER, BF_RECT);
            Inc(Rc.Left, Rc.Bottom - Rc.Top + 1);
            Rc.Right := ARect.Right;
            DrawEdge(ACanvas.Handle, Rc, BDR_SUNKENOUTER, BF_RECT);
          end;
          //绘制菜单前面的小图形,一个TImageList
          imglstState.Draw(ACanvas, nLeft - 1, nTop, Item.ImageIndex, Item.Enabled);
          CopyRect(Rc, ARect);
          InflateRect(Rc, -1, -1);
          Inc(Rc.Left, BMWidth + ARect.Bottom - ARect.Top + 6);
          ACanvas.Brush.Style := bsClear;
          if not Item.Enabled then
          begin
            OffsetRect(Rc, 1, 1);
            ACanvas.Font.Color := clBtnHighlight;
          end else
          with ACanvas.Font do
          if Selected then Color := clRed else Color := clBtnText;
          ACanvas.Brush.Style := bsClear;
          if Item.Enabled or (not Selected) then
          DrawText(ACanvas.Handle, PChar(Item.Caption), Length(Item.Caption), Rc,
                  DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS);
          if not Item.Enabled then
          begin
            OffsetRect(Rc, -1, -1);
            ACanvas.Font.Color := clBtnShadow;
            DrawText(ACanvas.Handle, PChar(Item.Caption), Length(Item.Caption), Rc,
                    DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_END_ELLIPSIS);
          end;    
        end;
      finally
        ABitmap.Free;
      end;    
    end;