So far I tried using GetThemePartSize, GetThemeMetric, GetSystemMetrics, WM_GETTITLEBARINFOEX via SendMessage and a couple of other calls, but nothing comes even close to the real dimensions (Windows 7 with themes enabled).
Basically my questions are: How to get the size (and location, ideally even handle) of these buttons and what do the retrieved values from GetThemePartSize even mean? What are they good for?
I already looked at this answer and many others, but they simply don't work.
Thank you
Update
For Hans:
[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