到目前为止,我尝试使用GetThemePartSize、GetThemeMetric、GetSystemMetrics、WM_GETTITLEBARINFOEX通过SendMessage和其他几个调用,但是没有一个能够接近真实的尺寸(启用主题的Windows 7)。
基本上我的问题是:如何获取这些按钮的大小(和位置,最好还有句柄),以及从GetThemePartSize检索到的值是什么意思?它们有什么用处?
我已经查看了这个答案和许多其他答案,但它们根本不起作用。
谢谢
更新
对于汉斯:
[DllImport("uxtheme", ExactSpelling=true)]
private extern static Int32 GetThemePartSize(IntPtr hTheme, IntPtr hdc, WindowPart part, WindowPartState state, ref RECT pRect, ThemeSize eSize, out SIZE size);
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
private struct SIZE
{
public int cx;
public int cy;
}
private const int TS_TRUE = 1;
private const int CBS_NORMAL = 1;
private const int WP_CLOSEBUTTON = 18;
private const string VSCLASS_WINDOW = "WINDOW";
/* inside a method */
var rect = new RECT {left = 0, right = 200, top = 0, bottom = 200};
var size = new SIZE();
var windowHandle = new WindowInteropHelper({MyWindow}).Handle;
var theme = OpenThemeData(windowHandle, VSCLASS_WINDOW);
GetThemePartSize(theme, null, WP_CLOSEBUTTON, CBS_NORMAL, ref rect, TS_TRUE, ref size);
// result on w7 with default theme -> size.cx == 28, size.cy == 17