在delphi的菜单中如何调字体大小?
有无这样的可调字体大小的菜单组件?在哪里可以下?
谢谢!

解决方案 »

  1.   

    自己写ondraw程序,将默认菜单的绘图取消
      

  2.   

    我给你些信息,就是自己用代码来改menu的信息
    //********************************************************
    //button1使用form1的标题菜单,并将’图标文字‘指定为button2目前的字体
    //********************************************************
    procedure TForm1.Button2Click(Sender: TObject);
    var
      lf:TLogFont;
      NM:TNonClientMetrics;
    begin
      //取得TNonClientMetrics结构
      SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NM),@NM,0);
      //以CreateFontIndirect建立Font对象,指派给button1.font
      Button1.Font.Handle:=CreateFontIndirect(NM.lfCaptionFont);
      //取得描述button2.font的TLogFont属性
      GetObject(Button2.Font.Handle,SizeOf(TLogFont),@lf);
      //调用SystemParametersInfo将此TLogFont结构设置为图标字体
      SystemParametersInfo(SPI_SETICONTITLELOGFONT,sizeof(lf),@lf,0);
    end;
    你改改就可以了
      

  3.   

    自己画是一个办法,还有个办法我没试过,就是自己建个字体,再取得菜单的DC,用SelectObject将字体句柄选择到DC中
      

  4.   

    其实都没有必要哪么麻烦,只要主窗口的ONCREATE事件中编写一些简单语句.BEGIN
     application.menuitem.font.size:=24;
     application.menuitem.font.name:='宋体';
     application.menuitem.font.color:=crred;
    end;
      

  5.   

    楼主要明白只有有窗口句柄的对象才有DC,像菜单这样的对象是没有句柄的,它在自画时用的是父窗口的DC
    下面的代码可以看看,应该有帮助
    注意这几句(后面有完整的代码,来自DELPHI源码)
        WM_DRAWITEM:
          with PDrawItemStruct(Message.LParam)^ do
          begin
            for I := 0 to Count - 1 do
            begin
              MenuItem := TPopupMenu(Items[I]).FindItem(itemID, fkCommand);
              if MenuItem <> nil then
              begin
                Canvas := TControlCanvas.Create;
                with Canvas do
                try
                  SaveIndex := SaveDC(hDC);
                  try
                    Handle := hDC;
                    Font := Screen.MenuFont;
                    DrawMenuItem(MenuItem, Canvas, rcItem, TOwnerDrawState(LongRec(itemState).Lo));procedure TPopupList.WndProc(var Message: TMessage);
    var
      I, Item: Integer;
      MenuItem: TMenuItem;
      FindKind: TFindItemKind;
      ContextID: Integer;
      Canvas: TCanvas;
      SaveIndex: Integer;
      DC: HDC;
    begin
      case Message.Msg of
        WM_COMMAND:
          for I := 0 to Count - 1 do
            if TPopupMenu(Items[I]).DispatchCommand(Message.wParam) then Exit;
        WM_INITMENUPOPUP:
          for I := 0 to Count - 1 do
            with TWMInitMenuPopup(Message) do
              if TPopupMenu(Items[I]).DispatchPopup(MenuPopup) then Exit;
        WM_MENUSELECT:
          with TWMMenuSelect(Message) do
          begin
            FindKind := fkCommand;
            if MenuFlag and MF_POPUP <> 0 then FindKind := fkHandle;
            for I := 0 to Count - 1 do
            begin
              if FindKind = fkHandle then
              begin
                if Menu <> 0 then
                  Item := GetSubMenu(Menu, IDItem) else
                  Item := -1;
              end
              else
                Item := IDItem;
              MenuItem := TPopupMenu(Items[I]).FindItem(Item, FindKind);
              if MenuItem <> nil then
              begin
                Application.Hint := GetLongHint(MenuItem.Hint);
                Exit;
              end;
            end;
            Application.Hint := '';
          end;
        WM_HELP:
          with PHelpInfo(Message.LParam)^ do
          begin
            for I := 0 to Count - 1 do
            begin
              if hItemHandle = TMenu(Items[I]).Handle then
                MenuItem := TMenu(Items[I]).Items
              else
                MenuItem := TPopupMenu(Items[I]).FindItem(hItemHandle, fkHandle);
              if MenuItem <> nil then
              begin
                ContextID := TMenu(Items[I]).GetHelpContext(iCtrlID, True);
                if ContextID = 0 then
                  ContextID := TMenu(Items[I]).GetHelpContext(hItemHandle, False);
                if Screen.ActiveForm = nil then Exit;
                if (ContextID = 0) then
                  ContextID := Screen.ActiveForm.HelpContext;
                if (biHelp in Screen.ActiveForm.BorderIcons) then
                  Application.HelpCommand(HELP_CONTEXTPOPUP, ContextID)
                else
                  Application.HelpContext(ContextID);
                Exit;
              end;
            end;
          end;
        WM_DRAWITEM:
          with PDrawItemStruct(Message.LParam)^ do
          begin
            for I := 0 to Count - 1 do
            begin
              MenuItem := TPopupMenu(Items[I]).FindItem(itemID, fkCommand);
              if MenuItem <> nil then
              begin
                Canvas := TControlCanvas.Create;
                with Canvas do
                try
                  SaveIndex := SaveDC(hDC);
                  try
                    Handle := hDC;
                    Font := Screen.MenuFont;
                    DrawMenuItem(MenuItem, Canvas, rcItem, TOwnerDrawState(LongRec(itemState).Lo));
                  finally
                    Handle := 0;
                    RestoreDC(hDC, SaveIndex);
                  end;
                finally
                  Canvas.Free;
                end;
                Exit;
              end;
            end;
          end;
        WM_MEASUREITEM:
          with PMeasureItemStruct(Message.LParam)^ do
          begin
            for I := 0 to Count - 1 do
            begin
              MenuItem := TPopupMenu(Items[I]).FindItem(itemID, fkCommand);
              if MenuItem <> nil then
              begin
                DC := GetWindowDC(Window);
                try
                  Canvas := TControlCanvas.Create;
                  with Canvas do
                  try
                    SaveIndex := SaveDC(DC);
                    try
                      Handle := DC;
                      Font := Screen.MenuFont;
                      MenuItem.MeasureItem(Canvas, Integer(itemWidth),
                        Integer(itemHeight));
                    finally
                      Handle := 0;
                      RestoreDC(DC, SaveIndex);
                    end;
                  finally
                    Canvas.Free;
                  end;
                finally
                  ReleaseDC(Window, DC);
                end;
                Exit;
              end;
            end;
          end;
        WM_MENUCHAR:
          for I := 0 to Count - 1 do
            with TPopupMenu(Items[I]) do
              if (Handle = HMENU(Message.LParam)) or
                (FindItem(Message.LParam, fkHandle) <> nil) then
              begin
                ProcessMenuChar(TWMMenuChar(Message));
                Exit;
              end;
      end;
      with Message do Result := DefWindowProc(Window, Msg, wParam, lParam);
    end;
      

  6.   

    楼主要明白只有有窗口句柄的对象才有DC,像菜单这样的对象是没有句柄的,它在自画时用的是父窗口
    改为
    楼主要明白只有有窗口句柄的对象才有DC,像菜单这样的对象是没有DC句柄的,它在自画时用的是父窗口DC