日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi 获取菜单高度、标题栏高度、边框高度函数GetSystemMetrics

發布時間:2023/12/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi 获取菜单高度、标题栏高度、边框高度函数GetSystemMetrics 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

項目中需要獲取不同分辨率德菜單高度,必應搜索了一下,可以用GetSystemMetrics函數實現,代碼如下:歡迎加入Delphi知識局QQ群:32422310

unit Unit1;interfaceusesWinapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Menus;typeTForm1 = class(TForm)MainMenu1: TMainMenu;N11: TMenuItem;N2221: TMenuItem;Button1: TButton;procedure Button1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); varMenuItemHeight:integer; beginMenuItemHeight:= GetSystemMetrics(SM_CYMENUCHECK); end;end.

如果菜單折疊,可用以下代碼:

typeTMenuBarInfo = recordcbSize: DWORD;rcBar: TRect;hMenu: HMENU;hwndMenu: HWND;fBarFocused: Byte;fFocused: Byte;end;{$EXTERNALSYM GetMenuBarInfo} function GetMenuBarInfo(hend: HWND; idObject, idItem: ULONG;var pmbi: TMenuBarInfo): BOOL; stdcall;implementationfunction GetMenuBarInfo; external user32 name 'GetMenuBarInfo';procedure TForm1.Button1Click(Sender: TObject); varMenuHeight: Integer;MenuBarInfo: TMenuBarInfo; beginMenuBarInfo.cbSize := SizeOf(MenuBarInfo);if GetMenuBarInfo(Handle, OBJID_MENU, 0, MenuBarInfo) thenMenuHeight := MenuBarInfo.rcBar.Bottom - MenuBarInfo.rcBar.Topelse......end;

或者

procedure TForm1.Button1Click(Sender: TObject);
var
? pm : TTPMParams;
? DisplayPoint : TPoint;
? r: TRect;
begin
? Systemparametersinfo( spi_getworkarea, 0, @r, 0 );
? r.top := r.bottom + 1;
? r.bottom := screen.height;

? DisplayPoint := Point( 699, r.top );
? with pm, pm.rcexclude do
? begin
? ? ?Top ? ?:= r.top;
? ? ?Bottom := r.bottom;
? ? ?Left ? := 0;
? ? ?Right ?:= screen.width;
? ? ?cbSize := SizeOf(pm);
? end;
? TrackPopupMenuEx( PopupMenu1.Handle, TPM_VERTICAL or TPM_HORIZONTAL, ?
? ? ? ? ? ? ? ? ? ? DisplayPoint.x, DisplayPoint.y, Handle, @pm );
end;

該函數也可以用于獲取屏幕分辨率

GetSystemMetrics(
? nIndex:?Integer?{參數,?詳見下表}
?):?Integer;
?
舉例?-?獲取屏幕分辨率:var
? cx,cy:?Integer;
?begin
? {通過?GetSystemMetrics?函數獲取屏幕分辨率}
? cx?:=?GetSystemMetrics(SM_CXSCREEN);
? cy?:=?GetSystemMetrics(SM_CYSCREEN);
? ShowMessageFmt('Width:%d;?Height:%d',?[cx,cy]);
? {通過?Screen?對象獲取屏幕分辨率}
? cx?:=?Screen.Width;
? cy?:=?Screen.Height;
? ShowMessageFmt('Width:%d;?Height:%d',?[cx,cy]);
?end;

procedure TForm1.Button9Click(Sender: TObject); varframeh,captionh,menuh: Integer;str:string; begin //邊框高frameh := GetSystemMetrics(SM_CXFRAME); //標題高captionh := GetSystemMetrics(SM_CYCAPTION); //菜單高menuh:=GetSystemMetrics(SM_CYMENU);str:= ?inttostr( frameh)+' '+inttostr(captionh)+' '+inttostr(menuh) ;memo1.text:=str;end;

?

總結

以上是生活随笔為你收集整理的Delphi 获取菜单高度、标题栏高度、边框高度函数GetSystemMetrics的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。