到目前为止,我尝试通过SendMessage和其他几个调用使用GetThemePartSize,GetThemeMetric,GetSystemMetrics,WM_GETTITLEBARINFOEX,但是没有任何内容甚至接近真实尺寸(启用了主题的Windows 7)。
基本上我的问题是:如何获得这些按钮的大小(和位置,理想情况下甚至处理)以及GetThemePartSize中检索到的值甚至意味着什么?它们有什么用处?
我已经查看了this answer和其他许多人,但他们根本无法工作。
谢谢
更新
汉斯:
[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
答案 0 :(得分:2)
在浏览Firefox 17.0.1源代码(即文件nsNativeThemeWin.cpp和nsUXThemeData.cpp)后,我能够为在Vista或更新版本上运行的桌面应用程序提供满足我需求的部分解决方案:
private const int DWMWA_CAPTION_BUTTON_BOUNDS = 5;
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport("dwmapi.dll")]
public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out RECT pvAttribute, int cbAttribute);
var windowHandle = new WindowInteropHelper(Main.Instance).Handle;
var buttonsRect = new RECT();
var sizeButtonsRect = Marshal.SizeOf(buttonsRect);
DwmGetWindowAttribute(windowHandle, DWMWA_CAPTION_BUTTON_BOUNDS, out buttonsRect, sizeButtonsRect);
存储在buttonsRect中的结果有些奇怪:宽度差异(右 - 左= = 105)完全符合实际边界,但是,高度差(29px)比按钮实际占用的区域大8个像素。
由于这并没有真正完整地回答任何问题,因此我将保留此主题以供进一步回复。
再次感谢汉斯的无价和深思熟虑的评论。正如您可以清楚地看到的那样,它完全与编程语言和代码片段有关。
答案 1 :(得分:1)
您可以将Microsoft.Windows.Shell.dll与自定义chrome窗口库结合使用来修改或寻址窗口按钮。我正在使用它来创建Windows 8 ui样式的应用程序
http://www.codeproject.com/Articles/131515/WPF-Custom-Chrome-Library