Click here to Skip to main content
15,890,973 members
Articles / Programming Languages / C++
Article

Windows Magics - Grid-lined Explorer Windows

Rate me:
Please Sign up or sign in to vote.
3.57/5 (22 votes)
14 Sep 20062 min read 76K   2.1K   51   25
Change the way your Explorer windows present their contents.

Sample Image - GridExplorers.jpg

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionAny chance? Pin
myyr23-Apr-14 8:06
myyr23-Apr-14 8:06 
QuestionFull row selection Pin
Soham Dasgupta1-Sep-11 0:33
Soham Dasgupta1-Sep-11 0:33 
QuestionGrid-lined Explorer Windows + hilite? Pin
Kurt@K-K-Kanada15-Sep-10 20:50
Kurt@K-K-Kanada15-Sep-10 20:50 
QuestionPossible as Profile's Explorer Default? Pin
barryc_mailbox28-Jan-09 6:40
barryc_mailbox28-Jan-09 6:40 
AnswerRe: Possible as Profile's Explorer Default? Pin
barryc_mailbox28-Jan-09 6:53
barryc_mailbox28-Jan-09 6:53 
GeneralNice job, makes you think... Pin
AlexEvans27-Sep-06 19:39
AlexEvans27-Sep-06 19:39 
GeneralThis is no magic! [modified] Pin
SoftS17-Sep-06 8:42
SoftS17-Sep-06 8:42 
GeneralRe: This is no magic! Pin
Ven Nat18-Sep-06 0:23
Ven Nat18-Sep-06 0:23 
QuestionAchieve the same effect with registry? Pin
tkdmaster14-Sep-06 13:17
tkdmaster14-Sep-06 13:17 
AnswerRe: Achieve the same effect with registry? Pin
Ven Nat18-Sep-06 0:30
Ven Nat18-Sep-06 0:30 
GeneralExceptionally Impressed with your Name Pin
kackermann12-Sep-06 3:49
kackermann12-Sep-06 3:49 
GeneralRe: Exceptionally Impressed with your Name Pin
Dieter Hammer14-Sep-06 20:01
Dieter Hammer14-Sep-06 20:01 
JokeRe: Exceptionally Impressed with your Name Pin
Ralph Wetzel15-Sep-06 10:27
Ralph Wetzel15-Sep-06 10:27 
GeneralRe: Exceptionally Impressed with your Name Pin
Dieter Hammer18-Sep-06 20:01
Dieter Hammer18-Sep-06 20:01 
GeneralNice feature... Pin
Hogfather12-Sep-06 2:50
Hogfather12-Sep-06 2:50 
GeneralNice, but only for real Explorer Windows ... Pin
Martin08157-Sep-06 23:32
professionalMartin08157-Sep-06 23:32 
GeneralRe: Nice, but only for real Explorer Windows ... Pin
Ven Nat7-Sep-06 23:38
Ven Nat7-Sep-06 23:38 
GeneralRe: Nice, but only for real Explorer Windows ... Pin
Martin08158-Sep-06 0:08
professionalMartin08158-Sep-06 0:08 
GeneralRe: Nice, but only for real Explorer Windows ... Pin
Ven Nat8-Sep-06 0:31
Ven Nat8-Sep-06 0:31 
GeneralRe: Nice, but only for real Explorer Windows ... Pin
Martin08158-Sep-06 0:44
professionalMartin08158-Sep-06 0:44 
Generalnice customization of Windows explorer... Pin
joshidipesh7-Sep-06 19:28
joshidipesh7-Sep-06 19:28 
GeneralExcellent thinking Pin
sivas_v7-Sep-06 18:49
sivas_v7-Sep-06 18:49 
GeneralFormatting of snippets Pin
Ed.Poore7-Sep-06 3:16
Ed.Poore7-Sep-06 3:16 
JokeRe: Formatting of snippets Pin
barryc_mailbox28-Jan-09 6:35
barryc_mailbox28-Jan-09 6:35 
GeneralRe: Formatting of snippets Pin
Shuwen He4-Aug-12 6:23
Shuwen He4-Aug-12 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.