在delphi的菜单中如何调字体大小?
有无这样的可调字体大小的菜单组件?在哪里可以下?
谢谢!
有无这样的可调字体大小的菜单组件?在哪里可以下?
谢谢!
解决方案 »
- [delphi基础控件]TBXCombobox切换标签时出错,求助
- 招聘有餐饮软件实施/开发经验的工程师
- 这样的语句应该怎么写
- 各位大侠,谁有xp风格控件呀,最好带源码的,谢谢了!
- 请教有关设置窗体的BorderStyle问题?
- 高手请进---有点难度!!!------谢谢
- 读Delphi5开发人员指南的问题。
- 小弟刚学Delphi,几个小问题小散100分,请大家帮帮忙..............
- 关于DBListBox显示的问题(在线等待……)
- DELPHI程序如何编译
- 为什么delphi下DBGrid的Column能改长度,但是delphi7下DBGrid的Column不能改长度?
- 用存储过程出错----在线等
//********************************************************
//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;
你改改就可以了
application.menuitem.font.size:=24;
application.menuitem.font.name:='宋体';
application.menuitem.font.color:=crred;
end;
下面的代码可以看看,应该有帮助
注意这几句(后面有完整的代码,来自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;
改为
楼主要明白只有有窗口句柄的对象才有DC,像菜单这样的对象是没有DC句柄的,它在自画时用的是父窗口DC