调整主菜单的高DPI /字体大小 [英] Resizing main menu for high DPI/font size
问题描述
在标准主菜单/弹出式菜单中包含图像时,遇到字体高度问题。看起来像这样。
当没有图像时,没有上面显示的问题。主菜单使用 TImageList
,图像的宽度/高度设置为16。所以我想保留16x16的图像大小并居中,得到像这样的东西:
如何读取主菜单的字体高度并相应地调整 TImageList
中的图像?我有一个想法是复制图像从一个 TImageList
到另一个较大的图像宽度/高度,但我仍然需要从字体大小确定正确的大小。我该怎么做?
更新 p 我通过检查 SystemParametersInfo
- SPI_GETNONCLIENTMETRICS
值,并使用 iMenuHeight
c $ c> TImageList 宽度/高度。当改变宽度/高度后图像被删除,我复制另一个 TImageList
。按照应有的方式工作。感谢大家提供最有帮助的答案。
$ b
更新2
问题进一步的解决方案,我标记为正确的在那里给予更好的结果,所以我切换到了那个。在Win7和XP上测试,似乎工作正常。
您可以获得屏幕的高度.MenuFont
通过选择它临时DC:
函数GetMenuFontHeight:Integer;
var
DC:HDC;
SaveObj:HGDIOBJ;
尺寸:TSize;
begin
DC:= GetDC(HWND_DESKTOP);
尝试
SaveObj:= SelectObject(DC,Screen.MenuFont.Handle);
GetTextExtentPoint32(DC,'|',1,Size); //字符并不重要
结果:= Size.cy;
SelectObject(DC,SaveObj);
终于
ReleaseDC(HWND_DESKTOP,DC);
end;
end;
I have an issue with font height in standard main menu/popup menu when it contains images. Looks like this.
When there are no images, there are no problems as displayed above. Main menu uses TImageList
with image width/height set to 16.
So I want to preserve image size at 16x16 and center it, to get something like this:
How can I read the font height of the main menu and adjust images in TImageList
accordingly? One idea I have is to copy images from one TImageList
to another with larger image width/height but I still need to determine proper size from the font size. How do I do that?
UPDATE
I solved this by examining SystemParametersInfo
- SPI_GETNONCLIENTMETRICS
value and using the iMenuHeight
value for TImageList
Width/Height. As images are deleted after changing Width/Height, I copied another to another TImageList
. Works exactly as it should. Thank you everyone for your most helpful answers.
UPDATE 2
After examining the problem futher the solution which I marked as correct down there is giving better result so I switched to that one instead. Tested on Win7 and XP, appears to be working properly.
You can get the height of Screen.MenuFont
by selecting it to a temporary DC:
function GetMenuFontHeight: Integer;
var
DC: HDC;
SaveObj: HGDIOBJ;
Size: TSize;
begin
DC := GetDC(HWND_DESKTOP);
try
SaveObj := SelectObject(DC, Screen.MenuFont.Handle);
GetTextExtentPoint32(DC, '|', 1, Size); // the character doesn't really matter
Result := Size.cy;
SelectObject(DC, SaveObj);
finally
ReleaseDC(HWND_DESKTOP, DC);
end;
end;
这篇关于调整主菜单的高DPI /字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!