📄 winskinform.pas
字号:
begin
if visible then begin
sf.activebtn:=nil;
state:=1;
draw;
end;
end;
procedure TNCObject.Draw;
begin
end;
procedure TWinSysButton.Draw;
begin
sf.drawsysbtn(self,state);
end;
procedure TWinSkinMenu.UpdataBtn;
var i,n:integer;
mi:TMenuItemInfo;
Buffer: array[0..79] of Char;
item:Tmenuitem;
newmenu:Thandle;
begin
newmenu := getmenu(sf.hwnd);
if newmenu<>0 then hmenu := newmenu;
if hmenu = 0 then exit;
for i:= 0 to high(Buttons) do Buttons[i].free;
count:= GetMenuItemCount(hmenu);
if count<=0 then exit;
setlength(buttons,count);
for i:= 0 to count-1 do begin
mi.cbSize:= sizeof(TMENUITEMINFO);
mi.fMask := MIIM_ID or MIIM_TYPE or MIIM_STATE or MIIM_SUBMENU;
fillchar(buffer,sizeof(buffer),#0);
mi.dwTypeData := Buffer;
Mi.cch := SizeOf(Buffer);
GetMenuItemInfo(hmenu, i, TRUE, mi);
buttons[i]:=TMenuBtn.create;
buttons[i].fsd:=fsd;
buttons[i].sf:=sf;
buttons[i].index:= i;
buttons[i].hsubmenu:=mi.hSubMenu;
buttons[i].enabled:= (mi.fState and MFS_DISABLED)=0;
buttons[i].visible:= true;
buttons[i].mid:=mi.wid;
buttons[i].caption:= buffer;
inc(n);
if (buttons[i].caption='') and (menu<>nil)
and (i<menu.items.Count) then begin
Item := menu.items[i];
if item<>nil then begin
if Assigned(item.Action) then item.Action.Update;
buttons[i].caption:= item.caption;
buttons[i].enabled:= item.Enabled;
buttons[i].mid:=GetMenuItemID(hmenu,i);
if item.count>0 then
buttons[i].hsubmenu:=item.Handle
else
buttons[i].hsubmenu:=0;
end;
end;
end;
SetMenu(sf.hwnd, 0);
end;
procedure TWinSkinMenu.UpdataBtn3;
var i,n:integer;
item:Tmenuitem;
newmenu:Thandle;
begin
newmenu := getmenu(sf.hwnd);
if newmenu<>0 then hmenu := newmenu;
for i:= 0 to high(Buttons) do Buttons[i].free;
count:= menu.items.Count;
if count<=0 then exit;
setlength(buttons,count);
for i:= 0 to count-1 do begin
buttons[i]:=TMenuBtn.create;
inc(n);
Item := menu.items[i];
if Assigned(item.Action) then item.Action.Update;
buttons[i].caption:= item.caption;
buttons[i].enabled:= item.Enabled;
buttons[i].visible:= item.visible;
buttons[i].mid:=item.Command;
buttons[i].fsd:=fsd;
buttons[i].sf:=sf;
buttons[i].index:= i;
if item.count>0 then
buttons[i].hsubmenu:=item.Handle
else
buttons[i].hsubmenu:=0;
end;
SetMenu(sf.hwnd, 0);
sf.activebtn:=nil;
end;
procedure TWinSkinMenu.UpdataBtn2(newmenu:Thandle);
var i,n,j:integer;
mi:TMenuItemInfo;
Buffer: array[0..79] of Char;
item:Tmenuitem;
begin
if newmenu<>0 then hmenu := newmenu;
if hmenu = 0 then exit;
for i:= 0 to high(Buttons) do Buttons[i].free;
count:= GetMenuItemCount(hmenu);
if count<=0 then exit;
setlength(buttons,count);
for i:= 0 to count-1 do begin
mi.cbSize:= sizeof(TMENUITEMINFO);
mi.fMask := MIIM_ID or MIIM_TYPE or MIIM_STATE or MIIM_SUBMENU;
fillchar(buffer,sizeof(buffer),#0);
mi.dwTypeData := Buffer;
Mi.cch := SizeOf(Buffer);
GetMenuItemInfo(hmenu, i, TRUE, mi);
buttons[i]:=TMenuBtn.create;
buttons[i].fsd:=fsd;
buttons[i].sf:=sf;
buttons[i].index:= i;
buttons[i].hsubmenu:=mi.hSubMenu;
buttons[i].enabled:= (mi.fState and MFS_DISABLED)=0;
buttons[i].visible:= true;
buttons[i].mid:=mi.wid;
buttons[i].caption:= buffer;
inc(n);
if (buttons[i].caption='') and (menu<>nil) then
for j := 0 to menu.items.Count-1 do begin
Item := menu.items[j];
if item.Command=mi.wid then begin
if Assigned(item.Action) then item.Action.Update;
buttons[i].caption:= item.caption;
buttons[i].enabled:= item.Enabled;
buttons[i].mid:=item.Command;
if item.count>0 then
buttons[i].hsubmenu:=item.Handle
else
buttons[i].hsubmenu:=0;
end;
end;
end;
SetMenu(sf.hwnd, 0);
end;
{procedure TWinSkinMenu.UpdataBtn;
var i:integer;
mi:TMenuItemInfo;
Buffer: array[0..79] of Char;
begin
hmenu:= getmenu(sf.hwnd);
for i:= 0 to high(Buttons) do Buttons[i].free;
count:= GetMenuItemCount(hmenu);
if count=0 then exit;
setlength(buttons,count);
for i:= 0 to count-1 do begin
buttons[i]:=TMenuBtn.create;
buttons[i].fsd:=fsd;
buttons[i].sf:=sf;
buttons[i].index:= i;
GetMenuString(hmenu,i,buffer,sizeof(buffer),MF_BYPOSITION);
buttons[i].caption:= buffer;
mi.cbSize:= sizeof(TMENUITEMINFO);
// mi.fMask := MIIM_TYPE;
mi.fMask := MIIM_TYPE or MIIM_STATE or MIIM_SUBMENU;
mi.fType := MFT_STRING;
fillchar(buffer,sizeof(buffer),#0);
mi.dwTypeData := Buffer;
Mi.cch := SizeOf(Buffer);
GetMenuItemInfo(hmenu, i, TRUE, mi);
// if mi.ftype=MFT_STRING then begin
buttons[i].caption:= buffer;
buttons[i].hsubmenu:=mi.hSubMenu;
buttons[i].enabled:= (mi.fState and MFS_DISABLED)=0;
buttons[i].visible:= true;
// end;
end;
SetMenu(sf.hwnd, 0);
end;}
procedure TWinSkinMenu.Copymenu(source,dst:Hmenu);
var i,n,aid:integer;
begin
n:= GetMenuItemCount(source);
for i:=0 to n-1 do begin
aid:=GetMenuItemID(source, i);
end;
end;
constructor TWinSkinMenu.Create(AOwner: TComponent);
begin
inherited create(AOwner);
map:=Tbitmap.create;
end;
destructor TWinSkinMenu.Destroy;
var i:integer;
begin
map.free;
for i:= 0 to length(Buttons)-1 do Buttons[i].free;
setlength(Buttons,0);
inherited destroy;
end;
type
TMenuItemAccess = class(TMenuItem);
TACControl = class(TControl);
TACWinControl = class(TWinControl);
TACGrid = class(TCustomGrid);
procedure TWinSkinMenu.DrawMenu(dc:HDC;rc:TRect);
var i,w,h,x: integer;
r,r1:Trect;
item:Tmenuitem;
btn:Tmenubtn;
begin
r1:=rc;
offsetrect(rc,-rc.left,-rc.top);
bg.width:=rc.right;
bg.height:=rc.bottom;
if fsd.menubar=nil then begin
bg.canvas.brush.color:=fsd.colors[csMenuBar];
bg.canvas.fillrect(rc);
x:=6;
end else begin
if sf.FWindowActive then i:=1
else i:=2;
// DrawRect2(acanvas.handle,rc,fsd.menubar.map,fsd.menubar.r,1,2,0,0,1);
if fsd.menubar.tile=1 then
DrawRect2(bg.canvas.handle,rc,fsd.menubar.map,fsd.menubar.r,i,2,0,0,1)
else
DrawRectTile(bg.canvas,rc,fsd.menubar.map,fsd.menubar.r,i,2);
if Menu.IsRightToLeft then
x:=8+fsd.menubar.r.right
else
x:=4+fsd.menubar.r.left;
if x>rc.right then x:=12;
end;
//save bar map;
bar:=r1;
map.assign(bg);
{ r:=rc;
offsetrect(r,-r.left,-r.top);
map.width:=rc.right;
map.height:=rc.bottom;
BitBlt(map.canvas.handle,0,0,rc.right,rc.bottom,
bg.Canvas.Handle ,0 ,0 ,SrcCopy)}
bg.canvas.Font := Screen.MenuFont;
bg.canvas.Font.color:= fsd.colors[csMenuBarText];
bg.canvas.brush.style:= bsclear;
SetBkMode(bg.Canvas.Handle, TRANSPARENT);
topmenu:=true;
if Menu.IsRightToLeft then begin
//bidi righttoleft
x:= rc.Right-x;
for i:= 0 to high(buttons) do begin
btn:=buttons[i];
w:= bg.canvas.TextWidth(btn.caption);
if w>0 then w:=w+10;
r:= rect(x-w,0,x,rc.bottom-1);
if btn.enabled then
bg.canvas.Font.color:= fsd.colors[csMenuBarText]
else
bg.canvas.Font.color:= fsd.colors[csbuttonshadow];
{ if (item.imageindex<>-1) and (menu.images<>nil) then
MyDrawImgCaption(bg.canvas,r,menu.images,item.imageindex,
item.caption,item.enabled,false)
else}
MyDrawCaption(bg.canvas,r,btn.caption,btn.enabled,false);
r:= rect(r1.left+x-w,r1.top,r1.left+x,r1.bottom-1);
btn.bounds:=r;
x:=x-w;
end;
end else begin
//bidi lefttoright
for i:= 0 to high(buttons) do begin
btn:=buttons[i];
w:= bg.canvas.TextWidth(btn.caption);
if w>0 then w:=w+10;
r:= rect(x,0,x+w,rc.bottom-1);
if btn.enabled then
bg.canvas.Font.color:= fsd.colors[csMenuBarText]
else
bg.canvas.Font.color:= fsd.colors[csbuttonshadow];
{ if (item.imageindex<>-1) and (menu.images<>nil) then
MyDrawImgCaption(bg.canvas,r,menu.images,item.imageindex,
item.caption,item.enabled,false)
else}
MyDrawCaption(bg.canvas,r,btn.caption,btn.enabled,false);
r:= rect(r1.left+x,r1.top,r1.left+x+w,r1.bottom-1);
btn.bounds:=r;
x:=x+w;
end;
end;
topmenu:=false;
if (sf.FormStyle=sfsMDIForm) and sf.MDIChildMax then begin
for i:= 0 to high(sf.sysbtn) do
if (sf.sysbtn[i].data.Visibility=100) and
(not sf.sysbtn[i].data.map.empty) then begin
r:= sf.sysbtn[i].bounds;
offsetrect(r,-sf.bw.left,-sf.bw.top);
DrawRect1(bg.canvas.handle,r,
sf.sysbtn[i].data.map,1,sf.sysbtn[i].data.frame,1);
end;
if not skinmanager.mdimax then skinmanager.setmdimax(true);
end;
BitBlt(dc,r1.left,r1.top,rc.right,rc.bottom,
bg.Canvas.Handle ,0 ,0 ,SrcCopy);
end;
procedure TMenuBtn.Draw;
var DC: HDC;
r,r2:Trect;
begin
DC := GetWindowDC(sf.hwnd);
sf.fcanvas.handle:=DC;
// menuitem.OnDrawItem:=nil;
r:=rect(bounds.left,sf.menu.bar.top,bounds.right,sf.menu.bar.bottom);
r2:=r;
offsetrect(r2,-sf.menu.bar.left,-sf.menu.bar.top);
sf.fcanvas.copyrect(r,sf.menu.map.canvas,r2);
if (state=3) or (state=2) then begin
sf.fcanvas.brush.color:=fsd.colors[csButtonHilight];
sf.fcanvas.FrameRect(bounds);
end;
sf.fcanvas.Font := Screen.MenuFont;
sf.fcanvas.Font.style := [];
if enabled then
sf.fcanvas.Font.color:= fsd.colors[csMenuBarText]
else
sf.fcanvas.Font.color:= fsd.colors[csbuttonshadow];
// sf.fcanvas.brush.style:= bsclear;
// SetBkMode(sf.fCanvas.Handle, TRANSPARENT);
r:=bounds;
{ if (menuitem.imageindex<>-1) and (sf.menu.menu.images<>nil) then
MyDrawImgCaption(sf.fcanvas,r,sf.menu.menu.images,menuitem.imageindex,
menuitem.caption,menuitem.enabled,false)
else }
MyDrawCaption(sf.fcanvas,r,caption,enabled,false);
ReleaseDC(sf.hwnd, DC);
end;
function TWinSkinMenu.FindBtn(p:Tpoint):TNcobject;
var i:integer;
begin
result:=nil;
for i:=0 to high(Buttons) do begin
if PtInRect(buttons[i].bounds, p) and (buttons[i].caption<>'') then begin
Result := buttons[i];
break;
end;
end;
end;
procedure TWinSkinMenu.MouseMove(p:Tpoint);
var i: integer;
begin
{ i := findbtn(p);
if i<>-1 then begin
buttons[i].mouseenter;
sf.done:=true;
end else
if sf.activebtn<>nil then begin
sf.activebtn.mouseleave;
end;}
end;
//menu hook
var
MenuHook: HHOOK;
InitDone: Boolean = False;
MenuBar : TWinSkinMenu;
Skinform : TWinSkinForm;
MenuButtonIndex: Integer;
LastMenuItem: TMenuItem;
LastMenuItemID: integer;
LastMousePos: TPoint;
StillModal: Boolean;
function ToolMenuGetMsgHook(Code: Integer; WParam: Longint; var Msg: TMsg): Longint; stdcall;
const
RightArrowKey: array[Boolean] of Word = (VK_LEFT, VK_RIGHT);
LeftArrowKey: array[Boolean] of Word = (VK_RIGHT, VK_LEFT);
var
P: TPoint;
Target: TMenuBtn;
Item: Integer;
FindKind: TFindItemKind;
ParentMenu: TMenu;
function FindButton(Forward: Boolean): TMenuBtn;
var
Bar: TWinSkinMenu;
I, J, Count: Integer;
begin
Bar := Skinform.menu; //MenuToolBar;
if Bar <> nil then begin
J := MenuButtonIndex;
I := J;
Count := Bar.Count;
if Forward then begin
if I = Count - 1 then
I := 0
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -