📄 winskinform.pas
字号:
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];
if not btn.visible then begin
btn.bounds:=rect(0,0,0,0);
continue;
end;
r := r1;
Tnt_DrawTextW(bg.Canvas.Handle, btn.caption,r,DT_Left or DT_CALCRECT or DT_NOCLIP);
w:= r.Right-r.left;
//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 TWinSkinMenu.SetMenuRect;
var i,w,h,x: integer;
r,r1:Trect;
item:Tmenuitem;
btn:Tmenubtn;
rc:Trect;
begin
rc:=rect(sf.bw.left,sf.bw.top,
sf.fwidth-sf.bw.right,sf.bw.top+sf.menuheight) ;
r1:=rc;
offsetrect(rc,-rc.left,-rc.top);
if (rc.Right<=0) or (rc.Bottom<=0) then exit;
bg.width:=rc.right;
bg.height:=rc.bottom;
if fsd.menubar=nil then begin
x:=6;
end else begin
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;
bg.canvas.Font := Screen.MenuFont;
if Menu.IsRightToLeft then begin
//bidi righttoleft
x:= rc.Right-x;
for i:= 0 to high(buttons) do begin
btn:=buttons[i];
if not btn.visible then begin
btn.bounds:=rect(0,0,0,0);
continue;
end;
r := r1;
Tnt_DrawTextW(bg.Canvas.Handle, btn.caption,r,DT_Left or DT_CALCRECT or DT_NOCLIP);
w:= r.Right-r.Left;
if w>0 then w:=w+10;
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];
if not btn.visible then begin
btn.bounds:=rect(0,0,0,0);
continue;
end;
r := r1;
Tnt_DrawTextW(bg.Canvas.Handle, btn.caption,r,DT_Left or DT_CALCRECT or DT_NOCLIP);
w:= r.Right-r.Left;
//w:= bg.canvas.TextWidth(btn.caption);
if w>0 then w:=w+10;
r:= rect(r1.left+x,r1.top,r1.left+x+w,r1.bottom-1);
btn.bounds:=r;
x:=x+w;
end;
end;
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.bkmap.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);
sf.fCanvas.Handle:=0;
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;
lastselect:boolean = false;
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;
Count := high(Bar.buttons)+1;
if Forward then begin
if I = Count - 1 then
I := 0
else
Inc(I);
Result := Bar.Buttons[I];
end else begin
if I = 0 then
I := Count - 1
else
Dec(I);
Result := Bar.Buttons[I];
end;
end else Result := nil;
end;
begin
if LastMenuItem <> nil then begin
ParentMenu := LastMenuItem.GetParentMenu;
if ParentMenu <> nil then begin
if ParentMenu.IsRightToLeft then
if Msg.WParam = VK_LEFT then
Msg.WParam := VK_RIGHT
else if Msg.WParam = VK_RIGHT then
Msg.WParam := VK_LEFT;
end;
end;
Result := CallNextHookEx(MenuHook, Code, WParam, Longint(@Msg));
if Result <> 0 then Exit;
if (Code = MSGF_MENU) then begin
Target := nil;
if not InitDone then begin
InitDone := True;
PostMessage(Msg.Hwnd, WM_KEYDOWN, VK_DOWN, 0);
end;
case Msg.Message of
WM_MENUSELECT:
begin
if (HiWord(Msg.WParam) = $FFFF) and (Msg.LParam = 0) then begin
if not StillModal then Skinform.CancelMenu;
Exit;
end else StillModal := False;
FindKind := fkCommand;
if HiWord(Msg.WParam) and MF_POPUP <> 0 then FindKind := fkHandle;
if FindKind = fkHandle then
Item := GetSubMenu(Msg.LParam, LoWord(Msg.WParam))
else
Item := LoWord(Msg.WParam);
if skinform.menu.menu<>nil then
LastMenuItem := Skinform.menu.menu.FindItem(Item, FindKind);
end;
WM_SYSKEYDOWN:
if Msg.WParam = VK_MENU then begin
SkinForm.CancelMenu;
Exit;
end;
WM_KEYDOWN:begin
if Msg.WParam = VK_RETURN then
// Skinform.FMenuResult := True
StillModal := false
else if Msg.WParam = VK_ESCAPE then
StillModal := false
else if (Msg.WParam = VK_RIGHT) then begin
if (LastMenuItem = nil) or (LastMenuItem.Count = 0) then
Target := FindButton(True);
end else if (Msg.WParam = VK_LEFT) then begin
if (LastMenuItem = nil) then
Target := FindButton(False)
else if ((LastMenuItem.Parent.handle=skinform.activemenu)
or (LastMenuItem.handle=skinform.activemenu)) then
Target := FindButton(False);
end else Target := nil;
if Target <> nil then
P := Point(Target.Bounds.left+1,Target.Bounds.top+1);
end;
WM_MOUSEMOVE:
begin
P := Msg.pt;
if (P.X <> LastMousePos.X) or (P.Y <> LastMousePos.Y) then begin
p:= SkinForm.GetWinxy(p.x,p.y);
Target := Tmenubtn(SKinForm.Menu.findbtn(P));
LastMousePos := P;
end;
end;
end;
if (Target <> nil) and (Target is TMenuBtn) and
(Target.Index <> MenuButtonIndex) then begin
StillModal := True;
// SkinForm.FCaptureChangeCancels := False;
// SkinForm.ClickButton(Target);
SkinForm.ClickButton(Target);
lastselect:=true;
// skinform.fsd.DoDebug('do click true '+TMenuBtn(Target).caption)
end;
end;
end;
procedure InitMenuHooks;
begin
StillModal := False;
InitDone := False;
GetCursorPos(LastMousePos);
if MenuHook = 0 then
MenuHook := SetWindowsHookEx(WH_MSGFILTER, @ToolMenuGetMsgHook, 0,
GetCurrentThreadID);
end;
procedure ReleaseMenuHooks;
begin
if MenuHook <> 0 then UnhookWindowsHookEx(MenuHook);
MenuHook := 0;
LastMenuItem := nil;
MenuBar := nil;
MenuButtonIndex := -1;
InitDone := False;
end;
{procedure TWinSkinForm.ClearTempMenu;
var
I: Integer;
Item: TMenuItem;
begin
if (FTempMenu <> nil) and (FButtonMenu<>nil) then begin
for I := FTempMenu.Items.Count - 1 downto 0 do
begin
Item := FTempMenu.Items[I];
FTempMenu.Items.Delete(I);
if item.tag<>c_windowid then
FButtonMenu.Insert(0, Item);
end;
FTempMenu.Free;
FTempMenu := nil;
FButtonMenu := nil;
end;
end;}
procedure TWinSkinForm.ClickButton(Button: TMenuBtn);
var
P: TPoint;
begin
// FCaptureChangeCancels := False;
GetWindowRect(hwnd, WTR);
P := Point(Button.bounds.left+1+wtr.left,
Button.bounds.top+1+wtr.top);
// timer.enabled:=true;
PostMessage(hwnd, WM_NCLBUTTONDOWN, MK_LBUTTON, Longint(PointToSmallPoint(P)));
// PostMessage(hwnd, CN_MenuSelect, 0, Longint(PointToSmallPoint(P)));
end;
procedure TWinSkinForm.MenuSelect(var Msg:TMessage);
var P: TPoint;
btn:TNCobject;
b:boolean;
begin
// if not fwindowactive then exit;
P := GetWinXY(msg.LParamLo,msg.LParamhi);
btn := findbtn(p);
if (btn=nil) and (menu<>nil) then btn := menu.findbtn(p);
b:=false;
if (btn<>nil) and (btn is TMenuBtn) then begin
CheckMenu(TMenuBtn(Btn));
end;
Msg.Result := 0;
Msg.Msg := WM_NULL;
end;
function TWinSkinForm.FindButtonFromAccel(Accel: Word): TMenuBtn;
var
I: Integer;
begin
result:=nil;
if menu=nil then exit;
for I := 0 to high(menu.buttons) do begin
Result :=Menu.Buttons[I];
if Result.Enabled and Result.visible and
IsAccel(Accel, Result.Caption) then
Exit;
end;
Result := nil;
end;
procedure TWinSkinForm.CancelMenu;
begin
if FInMenu then begin
// ReleaseMenuKeyHooks;
// MouseCapture := False;
end;
FInMenu := False;
// FCaptureChangeCancels := False;
end;
procedure TWinSkinForm.SelectMDIform(Sender: TObject);
var s:string;
j:integer;
b:boolean;
WS: TWindowState;
begin
if not Assigned(Application.MainForm) then exit;
s:= Tmenuitem(sender).caption;
s:= StringReplace(s,'&','',[]);
with Application.MainForm do
if (FormStyle = fsMDIForm) and (MDIChildCount>0) then begin
for j:= 0 to MDIChildCount-1 do begin
if MDIChildren[j].caption=s then begin
WS:=Application.MainForm.ActiveMDIChild.WindowState;
// b:=MDIChildren[j].windowstate=wsmaximized;
// MDIChildren[j].show;
SendMessage(ClientHandle,WM_MDIACTIVATE ,MDIChildren[j].handle,0);
MDIChildren[j].windowstate:=ws;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -