The Windows File Requester is horrible!

For everything that's not in any way related to PureBasic. General chat etc...
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

The Windows File Requester is horrible!

Post by RichardL »

Hi,

I want ALL file requesters in Windoze to ALWAYS open in 'Details' mode.

I hate needing to always switch from the stupid icon modes etc. (My view!)

Does anyone know how to make this a global feature on a PC?

RichardL
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

There is OpenWide but i haven't tried it:
http://lingo.atspace.com/openwide.html
Mat
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

Thanks MrMat... I will try it

Richard
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I found an easy way to fix this once, but I don't remember what I did. But I got it to always open in list view mode.

Edit:
http://www.winguides.com/forums/showfla ... sb=5&part=

Also, holding down Ctrl while clicking the X to close the window works with some kinds of windows like IE.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Afaik it has to do with your Explorer settings.
1) Close everthing!
2) Start ONE explorer task
3) Change to desired settings.
4) In folder options (menu) change for all windows (in english :) )
5) Close
6) Try again..

But.. my explorer is in details, the open dialog is in list mode, not details.
But also not in thumbs mode or so.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

Hi,
Thanks for the comments. I tried OpenWide and its very close to what I want... BUT (Isn't there always a 'but'?) it does not work consistently with a twin monitor installation.

Without OW the file requester opens on the correct screen, close by the program.

With OW the requester opens showing 'details' :D but not always on the same screen as the application :cry:

Now I'm being really greedy, in 'details' mode the columns should be no wider than necessary. Anyone else got any other ideas or tips?

I really need a permanent and global fix. Having got half way there with OW I can see how much time a good solution would save!

RichardL
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Did you try my link?
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

@Trond: I had a look but there seemed to be as much confusion about how to achieve the results as everywhere else.

I wish I had the time to sort this myself but I am too busy at work to get into the depths of how the common dialog boxes work. If I had the time this is the approach I would adopt:

First I would write the my own Pure Basic OpenFileRequester() function and make it dance to my tune; specifically finding the flags that determine the features of the layout. The documentation in the Win32 Programmer’s Reference describes the GetOpenFilename_() API call, which leads you on to dissecting and understanding the OPENFILENAME structure. On first inspection it’s not rocket science but neither is it a half-hour job.

The next challenge would be to find out how to intercept ALL Windoze’s calls to the function and modify the flags being passed to it. I’m out of my depth here; like many things it’s probably really easy… once you know how.

The third step might be to tackle any problems that occur with multiple screens; but XP Pro sorts this OK on my setup so the X and Y co-ordinates could be left alone.

It would be nice if Fred could put a flag in the Pure Basic OpenFileRequester to set the format. ‘List’ is better than ‘Icons’, but most of my application users would prefer ‘Details’ as the default.

Has anyone got any spare 48 Hours days?

RichardL
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I don't know if this will help you Richard but I posted the original code for this sometime last year. I have re-coded for PB4 Beta7 as well as added support for multi file selection. It's still a work in progress and only tested on WinXP. I'm not sure how well the Thumbnail and or Tile View will work on Win 2K, so let me know if you have any problems. I'm all ears for any improvements. ;)

This allows you to select your choice of view for the OpenFileRequester as well as allowing you to resize the Dialog Window. Other than displaying your selected file(s) there is no other funtionality to this code. It's main purpose is to show how to change the view and extract the filename(s) for further processing. ;)

Code: Select all

;/============================================================= 
;/ Code      : Custom OpenFileRequester that allows view change
;/ Author    : Sparkie 
;/ Date      : 03/18/06 
;/ PB Version: PB 4.00 Beta7
;/ OS Support: Windows 2000/XP/Server 2003 
;/============================================================= 
If OSVersion() < #PB_OS_Windows_2000
  MessageRequester("Sorry", "This requires a minimum of Win 2000", #MB_ICONERROR)
  End
EndIf
;/=============================================== 
;/ Image plugins
;/=============================================== 
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()
;/=============================================== 
;/ Globals
;/=============================================== 
;...Ouyr custom message for resizing our OpenFileRequester
Global Dlg_Move = RegisterWindowMessage_(@"Dlg_Move")
;/=============================================== 
;/ Constants / Enumerations 
;/=============================================== 
;...OpenFileRequester constants
#CDN_INITDONE = #CDN_FIRST - 0
#CDN_SELCHANGE = #CDN_FIRST - 1
#CDN_FOLDERCHANGE = #CDN_FIRST - 2
#OFN_ENABLESIZING = $800000
#OFR_View_Report = $702C
#OFR_View_List = $702B
#OFR_View_Largeicon = $7029
#OFR_View_Thumbnail = $702D
#OFR_View_Thumbnail_2K = $7031
#OFR_View_Tile = $702E
;...Window Enumeration
Enumeration
  #Window_0 = 1
EndEnumeration
;...Menu Enumeration
Enumeration
  #Menu_Main
EndEnumeration
;...Menu Item Enumeration
Enumeration
  #Editor_0
  #Menu_Thumb
  #Menu_Report
  #Menu_List
  #Menu_Large
  #Menu_Tile
  #Menu_Exit
EndEnumeration
;/=============================================== 
;/ Procedure - Placeholder for view style
;/=============================================== 
Procedure GetView(viewStyle)
  Shared theView
  If viewStyle
    theView = viewStyle
  EndIf
  ProcedureReturn theView
EndProcedure
;/=============================================== 
;/ Procedure - Sets view on Dialog init
;/=============================================== 
Procedure OF_HookFunc(hDlg, msg, wParam, lParam)
  Select msg
    Case Dlg_Move
      ;...Let's resize the dialog window
      hwnd = GetParent_(hDlg)
      MoveWindow_(hwnd, 0, 0, wParam, lParam, 1)
    Case #WM_INITDIALOG
      PostMessage_(hDlg, Dlg_Move, 600, 500)
    Case #WM_NOTIFY
      *pnmhdr.NMHDR = lParam
      Select *pnmhdr\code
        Case #CDN_FOLDERCHANGE
          ;--> Set our view choice here
          openUsing = GetView(0)
          If OSVersion() = #PB_OS_Windows_2000 And openUsing = #OFR_View_Thumbnail
            openUsing  = #OFR_View_Thumbnail_2K
          EndIf
          hParent = FindWindowEx_(GetParent_(hDlg), 0, "SHELLDLL_DefView", #Null)
          SendMessage_(hParent, #WM_COMMAND, openUsing, 0)
      EndSelect
  EndSelect
  ProcedureReturn 0
EndProcedure
;/=============================================== 
;/ Procedure - Custom OopenFileRequester
;/=============================================== 
Procedure.s MyOpenFileRequester(title$, defaultDir$, pattern$, patternPosition, view, multiSelect)
  Shared *selectedFile
  ;...For filter to function properly, we need 
  ;...to replace | with null Chr(0) directly in memory 
  ;...Filter must end with 2 null chars
  pattern$ + "||"
  l = Len(pattern$)
  For n = 0 To l - 1
  If PeekB(@pattern$ + n) = Asc("|")
      PokeB(@pattern$ + n, $0)
  EndIf 
  Next n
  ;...Buffer to hold selected file name(s)
  buffSize = 1024
  If *selectedFile = 0
    *selectedFile = AllocateMemory(buffSize)
  Else
    ;...First byte must be null if no initial file name is to be displayed
    PokeB(*selectedFile, $0)
  EndIf
  ;...Fill in our OPENFILENAME structure
  myOpenDlg.OPENFILENAME
  myOpenDlg\hwndOwner = WindowID(GetActiveWindow())
  myOpenDlg\lStructSize = SizeOf(OPENFILENAME)
  myOpenDlg\hInstance = #Null
  myOpenDlg\lpstrFilter = @pattern$
  myOpenDlg\lpstrCustomFilter = #Null
  myOpenDlg\nMaxCustFilter = #Null
  myOpenDlg\nFilterIndex = patternPosition 
  myOpenDlg\lpstrFile = *selectedFile
  myOpenDlg\nMaxFile = buffSize
  myOpenDlg\lpstrFileTitle = #Null
  myOpenDlg\nMaxFileTitle = #Null
  myOpenDlg\lpstrInitialDir= @defaultDir$
  myOpenDlg\lpstrTitle = @title$
  myOpenDlg\flags = #OFN_ENABLESIZING | #OFN_EXPLORER | #OFN_ENABLEHOOK
  myOpenDlg\lpfnHook=@OF_HookFunc()
  ;...Allow multiselect
  If multiSelect
    myOpenDlg\flags = myOpenDlg\flags | #OFN_ALLOWMULTISELECT
  EndIf
  GetView(view)
  ;...Open the FileRequester
  GetOpenFileName_(@myOpenDlg)
  ;...Deal with multi selections which are null terminated within *selectedFile
  ;...With multi selections, the buffer null terminates folder and files
  ;...If the first string ends with the folder, we know we have multiple selections
  If multiSelect And FileSize(GetFilePart(PeekS(*selectedFile))) = -1
    ;...Using ";" for folder/files separator
    folder$ = PeekS(*selectedFile) + ";"
    For n = Len(folder$) To #MAX_PATH - 1
      nextFile$ = PeekS(*selectedFile + n)
      If nextFile$
        ;...Using "," for file separator
        files$ + nextFile$ + ","
        n + Len(nextFile$)
      EndIf
    Next n
    fileReturn$ = folder$ + files$
  Else
    ;...Only one file is selected
    fileReturn$ = PeekS(*selectedFile)
  EndIf
  ProcedureReturn fileReturn$
EndProcedure
;/=============================================== 
;/ Procedure - Extract multi filenames
;/=============================================== 
Procedure.s MyNextSelectedFileName(parseFile$, count)
  fileReturn$ = StringField(parseFile$, count, ",")
  ProcedureReturn fileReturn$
EndProcedure
;/=============================================== 
;/ Procedure - Display Selected Files
;/=============================================== 
Procedure DoFileOpenRequester()
  getFile$ = ""
  myPattern$ ="BMP|*.bmp|JPG|*.jpg;*.jpeg|TIF|*.tif;*.tiff|PNG|*.png" 
  getFile$ = MyOpenFileRequester("Choose Image", "C:\Documents And Settings\Owner\My Documents\My Pictures\", myPattern$, 0, openUsing, 1) 
  ;...Check for multiple files
  If FindString(getFile$, ";", 1)
    ClearGadgetItemList(#Editor_0)
    ;...Get the selected Folder
    theFolder$ = StringField(getFile$, folderFileSep, ";") + "\"
    ;...This is where the filenames begin
    folderFileSep = FindString(getFile$, ";", 1) + 1
    ;...Get the comma separated filenames
    theFiles$ = Mid(getFile$, folderFileSep, Len(getFile$) - folderFileSep + 1)
    ;...Count number of files selected
    filecount = CountString(theFiles$, ",")
    ;...Extract filenames
    For f = 1 To filecount
      nextFile$ = MyNextSelectedFileName(theFiles$, f) 
      AddGadgetItem(#Editor_0, -1, theFolder$ + nextFile$)
    Next f
  ElseIf getFile$ <> ""
    ;...Single file selected  
    ClearGadgetItemList(#Editor_0)
    AddGadgetItem(#Editor_0, -1, getFile$)
  EndIf
EndProcedure
;/=============================================== 
;/ Procedure - Main Window
;/=============================================== 
If OpenWindow(#Window_0, 0, 0, 520, 320, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar) And CreateGadgetList(WindowID(#Window_0))
  CreateMenu(#Menu_Main, WindowID(#Window_0))
  MenuTitle("&File")
  OpenSubMenu("&Open using...")
  MenuItem(#Menu_Thumb, "Thumbnails")
  MenuItem(#Menu_Report, "Report")
  MenuItem(#Menu_List, "List")
  MenuItem(#Menu_Large, "Large Icons")
  MenuItem(#Menu_Tile, "Tiles")
  CloseSubMenu()
  MenuBar()
  MenuItem(#Menu_Exit, "E&xit")
  EditorGadget(#Editor_0, 10, 10, 500, 270)
  quit = #False
  ;/=============================================== 
  ;/ Main Event Loop
  ;/=============================================== 
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_Event_Menu 
        openUsing = 0
        MenuID = EventMenu()
        Select MenuID
          Case #Menu_Thumb
            openUsing = #OFR_View_Thumbnail
          Case #Menu_Report
            openUsing = #OFR_View_Report
          Case #Menu_List
            openUsing = #OFR_View_List
          Case #Menu_Large
            openUsing = #OFR_View_Largeicon
          Case #Menu_Tile
            openUsing = #OFR_View_Tile
          Case #Menu_Exit
            quit = #True
        EndSelect
        If openUsing
          DoFileOpenRequester()
        EndIf
      Case #PB_Event_CloseWindow
        quit = #True
    EndSelect 
  Until quit
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

Hi Sparkie,

Thank you for the example code. :D

After a quick-try it did not work; the value of 'openUsing' either needs to be global or passed from 'MainEventLoop' to 'DoFileOpenRequester()'.

It would be good for the requester to open with a screen position that relates to the main application, which is particularly important when using multiple screens :wink:

Richard
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Sorry Richard. my bad. I didn't realize you were looking to make this a global thing. I was only thinking in terms of your PB apps. :D

(For some reason I thought this thread was in PB Windows section rather than Off Topic :? :oops: )
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

@Sparkie

I was hoping that somewhere in the depths of Windoze setup there was an option to set a default style; it was my choice to ask in 'off topic' because strictly its not a PB thing.

It seems that enough people want this feature because the author of OpenWide produced a utility, which I have tried and it does what I want, but it does not work in a multi-screen setup and fixes the position of the requester... OK for older machinary perhaps, but modern big screens make it more sensible to have the requester tied to the application.

Based on your example (and one I found in the forum for Power Basic, some time ago) I think the method of controlling the common dialog is not too much of a hurdle. Now, how does one intercept all calls to the requester, discover the location of the necessary structure/s and hack them?

Maybe its time to move this to the Winows area.

Richard
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

@Richard: See if this little app works for you...

The .exe IS the .exe, not an installer. ;) No registry hacks, no .dlls. It just sits in your SysTray and waits for an Open File Dialog to present itself. You can choose the view you desire and it will auto-size the columns in Detail (Report) View. It's a Beta and so far I was only able to test on XP, so let me know if you have any problems. :)

(Please excuse the cheesy icon. I'm working on a replacement. ;))
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post by RichardL »

@Sparkie

Sadly, no effect at all :cry:
I'm using Windoze XP Pro with all updates applied.

I'm wondering if the heavy virus/security system we use here (Sophos) is undoing any pointer changes you are making... just a thought. It would be a good idea to output some diagnostics that report operation, if they went to c:\temp\SparkDiag.txt I could PM it to you.

Best regards,
Richard
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Not working, hmmmm.... works perfectly here on XP Home SP2. :? I'm on my way to work so I will be back later tonight to see if we can sort this out. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply