Page 1 of 1

"Explorer" subclassed/themed Listview and TreeView controls, draw explorer style focus rectangle

Posted: 19 Aug 2016, 15:46
by gwarble
Hey all,

I recently discovered that you can use some of Windows' own classes for things to get your own guis to look more like windows explorer windows:

Code: Select all

SetWindowTheme(hListView, "ItemsView") ;or "Explorer"
;...
SetWindowTheme(hwnd, str) {
 Return DllCall("uxtheme\SetWindowTheme", "Uint", hwnd, "Str", str, "Ptr", 0)
}
It looks great (triangles on the TreeViews instead of +'s, selection rectangle is "glass"ified, etc... but the selection/focus rectangle is showing the normal dotted line rectangle instead of the rounded solid rectangle that explorer uses

I found a thread about it:
https://groups.google.com/forum/#!topic ... Kg3t1GNiLo

that says to use class named "ItemsView" and draw the rectangle with DrawThemeBackground (on part id 3 and state id 1 or 2). I'm trying to make sense of this (and get DrawThemeBackground working to draw a uxThemed button, but thats another issue) and i think i have to OnMessage WM_NCPAINT and do the drawing there, but i'm in over my head.

If anyone has any tips or insight it would be greatly appreciated

Code: Select all

WM_NCPAINT( wP, lP, msg, hwnd ) { ;not working attempt
hDC    := DllCall("GetDC", "UInt", hwnd)
hTheme := DllCall("UxTheme.dll\OpenThemeData", uInt, hwnd, Str, "ItemsView" )
if(hTheme)
{
 VarSetCapacity(pRect, 16, 0) ;replace with getRect...
 NumPut(0,    pRect,  0, "Int")
 NumPut(0,    pRect,  4, "Int")
 NumPut(100,  pRect,  8, "Int")
 NumPut(100,  pRect, 12, "Int")
  DllRet := DllCall("UxTheme.dll\DrawThemeBackground", Ptr, hTheme, Ptr, hDC, uInt, PartID:=3, uInt, StateID:=1 , Ptr, pRect, Ptr, 0, uInt)
}
DllCall("ReleaseDC", "UInt", hwnd, "UInt", hDC)
Return 
}
"Explorer" or "ItemsView" subclassed:
Image

Normal:
Image

The focus rectangle I want:
Image

The focus rectangle I get:
Image

Re: "Explorer" subclassed/themed Listview and TreeView controls, draw explorer style focus rectangle

Posted: 19 Aug 2016, 16:00
by Helgef
You are using numput wrong.

Re: "Explorer" subclassed/themed Listview and TreeView controls, draw explorer style focus rectangle

Posted: 19 Aug 2016, 16:19
by gwarble
oops, thanks
fixed first post, same result

Re: "Explorer" subclassed/themed Listview and TreeView controls, draw explorer style focus rectangle

Posted: 19 Aug 2016, 17:39
by Helgef
Try this:

Code: Select all

DllRet := DllCall("UxTheme.dll\DrawThemeBackground", "Int", hTheme, "UInt", hDC, "Int", 3, "Int", 1 , "Uint", &pRect, "Uint", 0)

Re: "Explorer" subclassed/themed Listview and TreeView controls, draw explorer style focus rectangle

Posted: 19 Aug 2016, 18:06
by gwarble
thanks man! that works for the drawing the rectangle (and for buttons!)

now i think instead of drawing it on the window's DC i need to ownerdraw or customdraw the listview control, find the dc and rect where the rectangle would normally be drawn, prevent it, and DrawThemeBackground at that point

Image