Results 1 to 3 of 3

Thread: Hoe toch "OnMouseOver" in MainMenu bij Ownerdraw?

  1. #1
    Silly member NGLN's Avatar
    Join Date
    Aug 2004
    Location
    Werkendam
    Posts
    5,133

    Hoe toch "OnMouseOver" in MainMenu bij Ownerdraw?

    Bij een standaard menubalk in D5 lichten de toplevel-menu's (Bestand, Bewerken, Beeld, Help) op als de muis daarover wordt bewogen.

    Nu heb ik (m.b.v. dit onderwerp) mijn menubalk een XP-look gegeven, maar dit "OnMouseOver"-gedrag is er niet meer zodra ik een OnDrawItem van een MenuItem instel.

    Is het mogelijk dat de toplevel-menuitems wél oplichten bij dit geownerdrawd menu?
    (Sender as TNLDUser).Signature := 'Groeten van Albert';

  2. #2
    Silly member NGLN's Avatar
    Join Date
    Aug 2004
    Location
    Werkendam
    Posts
    5,133
    Heb het gevonden! De helpfunctie was niet echt toereikend:
    Code:
    TOwnerDrawState is used by event handlers in owner-draw controls to indicate
    the state of an item about to be drawn. It is a set that includes zero or more
    of the following:
    
    Value	        Meaning
    
    odSelected	The item is selected.
    odGrayed	The item should appear grayed.
    odDisabled	The item is disabled.
    odChecked	The item should appear checked. (does not apply to all objects)
    odFocused	Keyboard input is directed to the item.
    odDefault	The item is the default item (does not apply to all objects)
    odComboBoxEdit	The drawing takes place in the edit box of a combo box control.
    Hier moet er nog (minstens) één aan toegevoegd worden:
    Code:
    odHotLight      The item is not selected, but mouse is over.
    Ik zal de bijgewerkte code later als tip even posten, is misschien wel handig voor anderen.
    (Sender as TNLDUser).Signature := 'Groeten van Albert';

  3. #3
    Silly member NGLN's Avatar
    Join Date
    Aug 2004
    Location
    Werkendam
    Posts
    5,133

    XP-style, XP-look, XP look menubalk, menu

    Code voor een XP-look menu in Delphi 5.

    Disclaimer: Nog zonder bitmap-ondersteuning (zie daarvoor link in eerste post), maar wel met checkvinkje.

    Code:
    type
      TForm1 = class(TForm)
        ...
      published
        procedure AdvancedDrawMenuItem(Sender: TObject; ACanvas: TCanvas;
          ARect: TRect; State: TOwnerDrawState);
        procedure MeasureMenuItem(Sender: TObject;
          ACanvas: TCanvas; var Width, Height: Integer);
      end;
    
    const
      GlyphBarWidth = 20;
      TextMargin = 5;
    
    procedure TForm1.MeasureMenuItem(Sender: TObject;
      ACanvas: TCanvas; var Width, Height: Integer);
    begin
      if not TMenuItem(Sender).IsLine then Inc(Height, 3);
      if not (TMenuItem(Sender).GetParentComponent is TMainMenu) then
        Inc(Width, GlyphBarWidth + TextMargin + 10);
    end;
    
    function LightenColor(Color: TColor; Value: integer): TColor;
    var
      R, G, B: Integer;
    begin
      if Value > 100 then Value := 100;
      Color := ColorToRGB(Color);
      R := Color and $000000FF;
      G := (Color and $0000FF00) shr 8;
      B := (Color and $00FF0000) shr 16;
      R := R + Round((255 - R) * (Value / 100));
      G := G + Round((255 - G) * (Value / 100));
      B := B + Round((255 - B) * (Value / 100));
      Result := RGB(R, G, B);
    end;
    
    procedure TForm1.AdvancedDrawMenuItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; State: TOwnerDrawState);
    var
      Item: TMenuItem;
      TopLevel: Boolean;
      GlyphRect, TextRect: TRect;
      Txt: String;
      Glyph: TBitmap;
    begin
      Item := TMenuItem(Sender);
      TopLevel := Item.GetParentComponent is TMainMenu;
      GlyphRect := ARect;
      GlyphRect.Right := GlyphRect.Left + GlyphBarWidth;
      TextRect := ARect;
      if TopLevel then
        OffsetRect(TextRect, TextMargin, -1)
      else begin
        Inc(TextRect.Left, GlyphBarWidth);
        InflateRect(TextRect, -TextMargin, 0);
      end;
      Inc(TextRect.Top, 4);
      with ACanvas, Item do begin
        if TopLevel then Brush.Color := clBtnFace else Brush.Color := clMenu;
        FillRect(ARect);
        if Enabled then Font.Color := clMenuText else Font.Color := clGrayText;
        if Default then Font.Style := [fsBold];
        if not TopLevel then begin
          Brush.Color := clBtnFace;
          FillRect(GlyphRect);
        end;
        if Enabled then begin
          if (odHotLight in State) and TopLevel then begin
            Pen.Color := clHighLight;
            Brush.Color := LightenColor(clHighlight, 68);
            Rectangle(Rect(ARect.Left + 1, ARect.Top + 1,
              ARect.Right - 1, ARect.Bottom - 1));
          end;
          if odSelected in State then begin
            if TopLevel then begin
              Pen.Color := clBtnShadow;
              MoveTo(ARect.Left, ARect.Bottom - 1);
              LineTo(ARect.Left, ARect.Top + 1);
              LineTo(ARect.Right - 2, ARect.Top + 1);
              LineTo(ARect.Right - 2, ARect.Bottom);
            end else begin
              Pen.Color := clHighLight;
              Brush.Color := LightenColor(clHighlight, 68);
              Rectangle(ARect);
            end;
          end;
          if Checked then begin
            Pen.Color := clHighLight;
            if odSelected in State then
              Brush.Color := LightenColor(clHighlight, 56)
            else begin
              Brush.Bitmap := AllocPatternBitmap(clBtnFace,
                                LightenColor(clHighlight, 84));
            end;
            InflateRect(GlyphRect, -1, -1);
            Rectangle(GlyphRect);
            Glyph := TBitmap.Create;
            try
              Glyph.Transparent := True;
              Glyph.Handle := LoadBitmap(0, PChar(OBM_CHECK));
              Draw(GlyphRect.Left + (GlyphRect.Right - GlyphRect.Left -
                Glyph.Width) div 2 + 2, GlyphRect.Top + (GlyphRect.Bottom -
                GlyphRect.Top - Glyph.Height) div 2, Glyph);
            finally
              Glyph.Free;
            end;
          end;
        end;
      end;
      if Item.IsLine then begin
        ACanvas.Pen.Color := LightenColor(clGrayText, 40);
        ACanvas.MoveTo(TextRect.Left, Round((ARect.Top + ARect.Bottom) / 2));
        ACanvas.LineTo(ARect.Right, Round((ARect.Top + ARect.Bottom) / 2));
      end else begin
        ACanvas.Brush.Style := bsClear;
        Txt := Item.Caption;
        DrawText(ACanvas.Handle, PChar(Txt), Length(Txt), TextRect, 0);
        if Item.ShortCut <> scNone then begin
          Txt := ShortCutToText(Item.ShortCut) + '  ';
          DrawText(ACanvas.Handle, PChar(Txt), Length(Txt), TextRect, DT_RIGHT);
        end;
      end;
    end;
    Last edited by NGLN; 04-Feb-05 at 10:42. Reason: nieuwe vraag verwijderd...
    (Sender as TNLDUser).Signature := 'Groeten van Albert';

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 25-Jan-03, 17:52
  2. Replies: 4
    Last Post: 10-Aug-02, 22:38
  3. Ownerdraw van de items bij TCustomListView
    By erathus in forum Algemeen
    Replies: 1
    Last Post: 17-May-02, 23:43
  4. hoe kan ik twee pagina's printen
    By Gerard in forum Algemeen
    Replies: 4
    Last Post: 04-Jan-02, 19:36
  5. Replies: 1
    Last Post: 13-Apr-01, 10:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •