到目前为止,我尝试通过 SendMessage 和其他几个调用使用 GetThemePartSize、GetThemeMetric、GetSystemMetrics、WM_GETTITLEBARINFOEX,但没有任何东西接近实际尺寸(启用了主题的 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