Windows Magics - Grid-lined Explorer Windows






3.57/5 (22 votes)
Sep 7, 2006
2 min read

77680

2054
Change the way your Explorer windows present their contents.
Overview
This article demonstrates how we can change system windows' properties, styles, etc. using Windows core functions. For example, take a scenario - whenever we open the Explorer windows in Details view, we want to enable grid lines as you see in the above screenshot.
WNDCLASS background
If you have a background knowledge of the platform Windows API and its functionalities, then you know very well that every window we create or the system creates are child windows to the desktop window. Every window has some styles and properties (please refer to the WNDCLASS
structure) associated with it. So by changing these properties or styles, we can achieve our desired look and feel and behaviors. By altering these properties, we can play around even with the system windows such as Explorer windows.
How to identify Explorer windows programmatically?
Whenever we start a Windows Explorer instance, it creates a parent window, and its class name (of WNDCLASS
structure) would be ExploreWClass
. We can use a Windows API named EnumWindows()
to enumerate all top level windows. This API will give us each window handle, one by one. Then, we can use the GetClassName()
API to get the class name. If the class name is ExploreWClass
, then we can conclude that this window is an Explorer instance, as shown below:
// To enumerate all top level windows BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { //Get the class name of the current window //Truncates if the class name is more //than 15 (don't want more than 15) CHAR lpClassName[15]; GetClassName(hwnd, lpClassName, 15); //If the class name is "ExploreWClass" //then this window is Explorer's main window //Then, reterive all its child windows if(strcmp(lpClassName, "ExploreWClass") == 0) EnumChildWindows(hwnd, EnumChildWindowsProc, lParam); //Continue the Enumeration for all top level windows return TRUE; }
How to identify the DetailView windows of Explorer windows?
Once we get the Explorer window handle, we can use the API EnumChildWindows()
in order to get all the child window handles. The Explorer program uses the common control listview for its right pan. As like above, we can check the class name of all the child windows. If it matches with SysListView32
, then it is a window that we are looking for.
Change the window's style
As you know about the Windows architecture, all communication between Windows and processes occur using messages. So simply send a message to the target window to add the grid lines style, as you see in the code snippet below:
//To enumerate the explorer windows's child windows BOOL CALLBACK EnumChildWindowsProc(HWND hwnd, LPARAM lParam) { //Get the class name of the current window CHAR lpClassName[15]; //Truncates if the class name is more than 15 GetClassName(hwnd, lpClassName, 15); //If the class name is "SysListView32" //then this window is we are looking for if(strcmp(lpClassName, "SysListView32") == 0) { //First, get the current style LRESULT style = SendMessage(hwnd, (UINT) LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); //Apply only if the grid lines not set if((style & LVS_EX_GRIDLINES) == 0) { // append the gridlines style style |= LVS_EX_GRIDLINES; SendMessage(hwnd, (UINT) LVM_SETEXTENDEDLISTVIEWSTYLE, 0, style); } } //Continue the Enumeration for all its child windows return TRUE; }
Conclusion
Hope you enjoyed playing with the system classes. In this way, you can change system windows, and application styles and behaviors. You can simply execute and place this EXE in the Startup, and enjoy the gridlines style until the future versions of Windows give an option to enable this in the display settings.