var Bitmap:TBitmap;
procedure TForm1.ddd1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
ACanvas.Draw(0,0,Bitmap);
end;
procedure TForm1.ddd1MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
Bitmap:=TBitmap.Create;
Bitmap.LoadFromFile('1.bmp');
Width:=Bitmap.Width;
Height:=Bitmap.Height;
end;
procedure TForm1.ddd1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
ACanvas.Draw(0,0,Bitmap);
end;
procedure TForm1.ddd1MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
Bitmap:=TBitmap.Create;
Bitmap.LoadFromFile('1.bmp');
Width:=Bitmap.Width;
Height:=Bitmap.Height;
end;
解决方案 »
- 线程中使用ADO,切换输入法卡死,急救啊!!!
- 如何动态加载DLL文件,实现如下功能
- inherited有什么作用?什么时候用?
- 不好意思,刚才的问题再问一次,刚才那帖太快结了,测试后还有问题,怎么DBGRID的点两次ONTitleBtnClick事件,会触发ONDBClick事件??我
- 应该算是参数问题
- 問:Delphi設計報表用什麼好?<在線等-送分>
- memo扩展问题
- 兄弟们,快救俺呀......oo..........oo...........oo....
- 有关李维的ADO/MTS/COM的问题,求救!
- 请问怎么在DELPHI调用WIN2000的登录用户名?
- 请教各位Delphi高手关于数据库程序开发的问题。
- ole和数据库的问题????
PopupMenu.OwnerDraw:=True;
你试一下QQ,它好象是整个菜单都是,不只是某个MENUITEM
它们原理一样吗?
QQ也不是这样吗?
欢迎各位继续发表高见,
const
BarWidth = 23; // 类似于开始菜单的popmenu的宽度
BarSpace = 3;type
TFormMain = class(TForm)
......
......
private
{ Private declarations }
function CreateRotatedFont(F: TFont; Angle: Integer): hFont;
procedure ExpandItemWidth(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
procedure AdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
public
{ Public declarations }
PopupImage: TBitmap; { icon in the bar }
PopupHeight: Integer; { holds the popumenu height }
PopupBitmap: TBitmap; { buffer for the bar }
Drawn: Boolean; { tells us if buffer has been drawn }
end;//////////////////////////////////////////////////////////////////////////////////////////////
// 生成类似于开始菜单的popmenu
procedure TFormmain.ExpandItemWidth(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
begin
Inc(Width, BarWidth); // make space for graphical bar
// way to calculate total height of menu to PopupHeight variable which was reset at OnPopup event
if TMenuItem(Sender).Visible then PopupHeight := PopupHeight + Height;
end;procedure TFormmain.AdvancedDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; State: TOwnerDrawState);
const
VerticalText = '静态页面生成系统';
clStart: TColor = clBlue;
clEnd: TColor = clBlack;
var
i, iTmp: Integer;
r: TRect;
rc1, rc2, gc1, gc2, bc1, bc2: Byte;
ColorStart, ColorEnd: Longint;
MenuItem: TMenuItem;
begin
MenuItem := TMenuItem(Sender);
{ we need to remove draw event so DrawMenuItem won't generate infinite loop! (Recursive) }
MenuItem.OnAdvancedDrawItem := nil;
{ align rect where item is draw so that vcl will leave bar for us }
r := ARect;
Dec(r.Right, BarWidth); // remove bar width
OffsetRect(r, BarWidth, 2);
DrawMenuItem(MenuItem, ACanvas, r, State); // draw item and restore event back
MenuItem.OnAdvancedDrawItem := AdvancedDrawItem;
PopupBitmap.Height := PopupHeight;
PopupBitmap.Width := BarWidth - BarSpace;
with PopupBitmap.Canvas do
if not Drawn then
begin // ... first draw phase ... }
Brush.Style := bsSolid;
if (clStart = clEnd) then // same color, just one fillrect required
begin
Brush.Color := clStart;
FillRect(Rect(0, ARect.Top, BarWidth - BarSpace, ARect.Bottom));
end
else //draw smooth gradient bar part for this item
begin
// this way we can use windows color constants e.g. clBtnFace. Those constant don't keep the RGB values
ColorStart := ColorToRGB(clStart);
ColorEnd := ColorToRGB(clEnd);
// get the color components here so they are faster to access inside the loop
rc1 := GetRValue(ColorStart);
gc1 := GetGValue(ColorStart);
bc1 := GetBValue(ColorStart);
rc2 := GetRValue(ColorEnd);
gc2 := GetGValue(ColorEnd);
bc2 := GetBValue(ColorEnd);
// make sure that division by zero doesn't happen
if PopupHeight <> 0 then
for i := 0 to (ARect.Bottom - ARect.Top) do
begin
Brush.Color := RGB(
(rc1 + (((rc2 - rc1) * (ARect.Top + i)) div PopupHeight)),
(gc1 + (((gc2 - gc1) * (ARect.Top + i)) div PopupHeight)),
(bc1 + (((bc2 - bc1) * (ARect.Top + i)) div PopupHeight)));
FillRect(Rect(0, ARect.Top + i, BarWidth - BarSpace, ARect.Top + i + 1));
end;
end;
with Font do
begin
Name := 'Tahoma';
Size := 9;
Color := clWhite;
Style := [fsBold];
iTmp := Handle; { store old }
Handle := CreateRotatedFont(Font, 90);
end;
Brush.Style := bsClear;
r := Rect(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom + 1);
ExtTextOut(Handle, 1, PopupHeight - PopupImage.Height - 15, ETO_CLIPPED, @r, PChar(VerticalText), Length(VerticalText), nil);
DeleteObject(Font.Handle); // delete created font and restore old handle
Font.Handle := iTmp;
if PopupHeight = ARect.Bottom then
begin // draw bitmap
Drawn := True;
Draw(0, PopupHeight - PopupImage.Height - 6, PopupImage);
end;
{ draw the double buffered bar now }
r := Rect(0, 0, PopupBitmap.Width, ARect.Bottom);
ACanvas.CopyRect(r, PopupBitmap.Canvas, r);
end
else // draw from double buffer
begin
r := Rect(0, ARect.Top, PopupBitmap.Width, ARect.Bottom);
ACanvas.CopyRect(r, PopupBitmap.Canvas, r);
end;
{ end with }
end;function TFormmain.CreateRotatedFont(F: TFont; Angle: Integer): hFont;
var LF : TLogFont;
begin
FillChar(LF, SizeOf(LF), #0);
with LF do
begin
lfHeight := F.Height;
lfWidth := 0;
lfEscapement := Angle*10;
lfOrientation := 0;
if fsBold in F.Style then lfWeight := FW_BOLD
else lfWeight := FW_NORMAL;
lfItalic := Byte(fsItalic in F.Style);
lfUnderline := Byte(fsUnderline in F.Style);
lfStrikeOut := Byte(fsStrikeOut in F.Style);
lfCharSet := DEFAULT_CHARSET;
StrPCopy(lfFaceName, F.Name);
lfQuality := DEFAULT_QUALITY;
lfOutPrecision := OUT_DEFAULT_PRECIS;
lfClipPrecision := CLIP_DEFAULT_PRECIS;
case F.Pitch of
fpVariable: lfPitchAndFamily := VARIABLE_PITCH;
fpFixed: lfPitchAndFamily := FIXED_PITCH;
else
lfPitchAndFamily := DEFAULT_PITCH;
end;
end;
Result := CreateFontIndirect(LF);
end;// popmenu弹出事件 //
procedure TFormMain.PopupMenuIconPopup(Sender: TObject);
var i:integer;
begin
Drawn := False;
PopupHeight := 0;
with TPopupMenu(Sender) do
if (Items.Count > 0) then
for i := 0 to Items.Count-1 do
begin
Items[i].OnMeasureItem := ExpandItemWidth;
Items[i].OnAdvancedDrawItem := AdvancedDrawItem;
end;
end;// end of menu create like start
////////////////////////////////////////////////////////////////////////////////////////////
好长时间了,你看看吧
Thanks to netsong:OICQ那种我已经试出来了不过它不是纯萃的WIN9X上开始处的菜单实际上使用TOOLBAR或PANEL都可以做出来,需要的朋友给我发个EMAIL(因为代码中有其它资源不好贴在这里)。[email protected]
[email protected]
能不能把你的代码公开一下或给我发外MAIL,学习学习?