Set folder view?

Windows specific forum
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Set folder view?

Post by BarryG »

Anyone know how to make a Windows folder display in a specific view? I want to open in "Medium icons" view (like below) for a specific folder, but it would be good to be able to switch to the other views as well. Thanks!

Note: I can probably do it with keystrokes as though the user did it, but that's just an ugly hack. I'd prefer a clean SendMessage (or however it's done) method, if possible.

Image
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Set folder view?

Post by BarryG »

Bump in case this got overlooked. (If not, all good, but just reminding).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Set folder view?

Post by RASHAD »

Not exactly the same but at least it works
Adapt it for your needs

Code: Select all

;#LARGE_ICON   = 28713
#MEDIUM_ICON  = 28714
#LIST         = 28715
#DETAILS      = 28716
;#THUMBS       = 28717
#TILES        = 28718
#DETALS4DETAILS = 28723

Procedure hookCB(hWnd, uMsg, wParam, lParam)
  Protected *NMHdr.NMHDR

  If uMsg = #WM_NOTIFY
    *NMHdr = LParam

    If *NMHdr\code = #CDN_FOLDERCHANGE
      hWnd = FindWindowEx_(GetParent_(hWnd), 0, "ShellDll_DefView", 0)
     
      If hWnd
        SendMessage_(hWnd, #WM_COMMAND, #MEDIUM_ICON, 0)
      EndIf
    EndIf
  EndIf
EndProcedure

Define Filename.S{#MAX_PATH}
Define OFN.OPENFILENAME

OFN\lStructSize = SizeOf(OPENFILENAME)
OFN\lpstrFile = @"C:\users\mmras\*.*"
OFN\nMaxFile = #MAX_PATH
OFN\Flags = #OFN_EXPLORER | #OFN_ENABLESIZING | #OFN_FILEMUSTEXIST | #OFN_ENABLEHOOK
OFN\lpfnHook = @hookCB()

GetOpenFileName_(OFN)
Repeat 

ForEver
Egypt my love
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Set folder view?

Post by BarryG »

Hi Rashad! Your code works for prompts, but I can't make it work with an existing open folder in Explorer?

Code: Select all

#MEDIUM_ICON=28714
Sleep_(2000) ; So I can click an existing Explorer window.
fg=GetForegroundWindow_()
hWnd=FindWindowEx_(GetParent_(fg),0,"ShellDll_DefView",0)
SendMessage_(hWnd,#WM_COMMAND,#MEDIUM_ICON,0) ; No change. :(
Post Reply