"Explorer" subclassed/themed Listview and TreeView controls, draw explorer style focus rectangle
Posted: 19 Aug 2016, 15:46
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:
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
"Explorer" or "ItemsView" subclassed:
![Image](http://www.gwarble.com/ahk/Screenshots/Explorer.png)
Normal:
![Image](http://www.gwarble.com/ahk/Screenshots/Regular.png)
The focus rectangle I want:
![Image](http://www.gwarble.com/ahk/Screenshots/FocusRect.png)
The focus rectangle I get:
![Image](http://www.gwarble.com/ahk/Screenshots/badFocusRect.png)
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)
}
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
}
![Image](http://www.gwarble.com/ahk/Screenshots/Explorer.png)
Normal:
![Image](http://www.gwarble.com/ahk/Screenshots/Regular.png)
The focus rectangle I want:
![Image](http://www.gwarble.com/ahk/Screenshots/FocusRect.png)
The focus rectangle I get:
![Image](http://www.gwarble.com/ahk/Screenshots/badFocusRect.png)