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:
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
CHAR lpClassName[15];
GetClassName(hwnd, lpClassName, 15);
if(strcmp(lpClassName, "ExploreWClass") == 0)
EnumChildWindows(hwnd, EnumChildWindowsProc, lParam);
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:
BOOL CALLBACK EnumChildWindowsProc(HWND hwnd, LPARAM lParam)
{
CHAR lpClassName[15];
GetClassName(hwnd, lpClassName, 15);
if(strcmp(lpClassName, "SysListView32") == 0)
{
LRESULT style = SendMessage(hwnd, (UINT)
LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
if((style & LVS_EX_GRIDLINES) == 0)
{
style |= LVS_EX_GRIDLINES;
SendMessage(hwnd, (UINT) LVM_SETEXTENDEDLISTVIEWSTYLE, 0, style);
}
}
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.