[WINDOWS ONLY] Launch Windows "File properties" dialog

Share your advanced PureBasic knowledge/code with the community.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

[WINDOWS ONLY] Launch Windows "File properties" dialog

Post by boddhi »

I searched the forum for similar code but couldn't find it.
So, hoping it's not redundant and for all intents and purposes.

Note: Closing the PB application closes all open "File Properties" dialogs.

Tested on PB 6.12 x64 - Win10 x64

Code: Select all

EnableExplicit
;
Procedure   ShowFileProperties(filename.s)
  Protected.SHELLEXECUTEINFO SHEX
  
  With SHEX
    \cbSize = SizeOf(SHELLEXECUTEINFO)
    \fMask = #SEE_MASK_INVOKEIDLIST
    \hwnd = 0
    \lpVerb = @"properties"
    \lpFile = @fileName
    \lpParameters = 0
    \lpDirectory = 0
    \nShow = #SW_SHOWNORMAL
    \hInstApp = 0
    \lpIDList = 0
    \lpClass = 0
    \hkeyClass = 0
    \dwHotKey = 0
    \hIcon = 0
    \hProcess = 0
  EndWith
    
  If ShellExecuteEx_(@SHEX) = 0
    MessageRequester("File properties","Error "+Str(GetLastError_()) + Chr(10) + "Unable to open file properties")
  EndIf
EndProcedure
;
Define.l Event
If OpenWindow(0, 0, 0, 222, 70, "File properties", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  ButtonGadget(0, 10,  10, 200, 20, "File #1 properties")
  ButtonGadget(1, 10,  40, 200, 20, "File #2 properties")
  Repeat 
    Event=WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow : Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0 : ShowFileProperties(#PB_Compiler_Home+"Examples\Sources\Data\PureBasic.bmp")
          Case 1 : ShowFileProperties(#PB_Compiler_Home+"Examples\Sources\Data\PureBasicLogo.bmp")
        EndSelect
    EndSelect
  ForEver
EndIf

If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Axolotl
Addict
Addict
Posts: 802
Joined: Wed Dec 31, 2008 3:36 pm

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by Axolotl »

@boddhi,
thanks for sharing.
BTW: What do you use for searching?
I used my favorite way and tried this: SHELLEXECUTEINFO site:purebasic.fr/english
and found that:
Show file Properties/Info dialog?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by boddhi »

Hello Axolotl,

I tried with keywords "windows file properties dialog site:www.purebasic.fr".
I never specify (perhaps wrongly) the language of the forum in order to retrieve results from the French (I'm French) and German forums.

My searches have returned many pages of results and I didn't see the post you've mentioned. :?
I finally try in other way, found a source in other language coding and adapted it.

Sorry for the redundant post and this less complete code.

Happy holidays to you, PB team and all. :wink:
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by Shardik »

There were also at least two other examples posted which display the "File properties" dialog:
- German forum by PBZecke from 2006
- English forum by nco2k from 2011

I only had to search for them in my huge collection of examples from the English and German PureBasic forums. I collected interesting examples for Linux, MacOS, Windows and Cross-platform from 2005 to 2013. After 2013 I unfortunately didn't have the time anymore to test and save every interesting example code in both forums.
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by blueb »

Shardik..

I have a pretty big collection also. :mrgreen:

My 'Handy Stuff' folders property box says:
Size on Disk: 10.0 GB
Contains: 90,163 files and 10,274 folders
I'm sure a lot of it may be outdated... but still very, very handy.
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by BarryG »

@boddhi: The only problem is the Properties window closes if your app closes. Any way to prevent that?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by Kwai chang caine »

Works here
Interesting, thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Quin
Addict
Addict
Posts: 1124
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by Quin »

Tested and working on Windows 10 21H2. Thanks for sharing!
User avatar
Jacobus
Enthusiast
Enthusiast
Posts: 139
Joined: Wed Nov 16, 2005 7:51 pm
Location: France
Contact:

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by Jacobus »

Another possibility

Code: Select all

Procedure FileProperty(File$)
  verb$ = "properties" 
  SEI.SHELLEXECUTEINFO 
  SEI\cbSize = SizeOf(SHELLEXECUTEINFO) 
  SEI\fMask = #SEE_MASK_NOCLOSEPROCESS | #SEE_MASK_INVOKEIDLIST | #SEE_MASK_FLAG_NO_UI 
  SEI\lpVerb = @verb$ 
  SEI\lpFile = @File$ 
  ShellExecuteEx_(@SEI)
EndProcedure

Define.l Event
If OpenWindow(0, 0, 0, 222, 70, "File properties", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)   
  ButtonGadget(0,10,10,200,50,"Select a file to know its properties")
  Repeat 
    Event=WaitWindowEvent()
    Select Event
      Case #PB_Event_CloseWindow : Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            File$ = OpenFileRequester("Select a file","c:\","*.*",WindowID(0))
            If File$ 
              FileProperty(File$)
            EndIf            
        EndSelect
    EndSelect
  ForEver
EndIf
PureBasicien tu es, PureBasicien tu resteras.
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by boddhi »

Hello everybody,

Happy New Year to all and lots of programming fun!
BarryG wrote: @boddhi: The only problem is the Properties window closes if your app closes. Any way to prevent that?
boddhi wrote: Note: Closing the PB application closes all open "File Properties" dialogs.
I had clarified this point on my post and, alas, I don't have a solution. I'm not an API expert and I've tried every possible constant... always with the same result. (To tell the truth, personally, I don't mind as long as I run this code in one of my applications and there's no need for the ‘Properties’ windows to remain open when this app is closed).

I have, however, tested all the other codes whose links were provided by our friends, and they all behave in the same way. Once again, I'm not a specialist, but I can suppose that all instances created are fundamentally attached to the application that launched them, and that closing it necessarily means closing said instances. But maybe I'm wrong...
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
robertfern
User
User
Posts: 38
Joined: Fri Feb 02, 2018 10:33 pm
Location: New Jersey

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by robertfern »

I do have the Macintosh version to open file info windows, if you are interested?
Mac OSX Ventura & Windows 10, PB 6.12
Quin
Addict
Addict
Posts: 1124
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by Quin »

robertfern wrote: Wed Jan 15, 2025 9:21 pm I do have the Macintosh version to open file info windows, if you are interested?
I would definitely be interested, I was wondering how to do this just a week or so ago..
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by Shardik »

Quin wrote: Thu Jan 16, 2025 10:49 pm
robertfern wrote: Wed Jan 15, 2025 9:21 pm I do have the Macintosh version to open file info windows, if you are interested?
I would definitely be interested, I was wondering how to do this just a week or so ago..
I already posted two examples about 10 years ago.
User avatar
robertfern
User
User
Posts: 38
Joined: Fri Feb 02, 2018 10:33 pm
Location: New Jersey

Re: [WINDOWS ONLY] Launch Windows "File properties" dialog

Post by robertfern »

Shardik had already had a version for mac on this topic
viewtopic.php?p=467833#p467833
it is the second example in his post.

It can also be done by running an AppleScript
Code is from Piero.

Code: Select all

EnableExplicit

Structure daResults : Out.s : Err.s : ExC.w : EndStructure
Global Sh.daResults

Procedure shShell(ShellCommand$, AddLF = #False)
   Protected Err$, tmper$, Output$, shell, Exc.w =-1 ; exit code -1 on failed launch
   shell = RunProgram("/bin/sh","","",
      #PB_Program_Open | #PB_Program_Write | #PB_Program_Read | #PB_Program_Error)
   If shell
      WriteProgramStringN(shell,ShellCommand$)
      WriteProgramData(shell,#PB_Program_Eof,0)
      While ProgramRunning(shell)
         If AvailableProgramOutput(shell)
            Output$ + ReadProgramString(shell)
            If AddLF : Output$ + "\n" : EndIf
         EndIf
         tmper$ = ReadProgramError(shell)
         If tmper$ : Err$ + tmper$ + "\n" : EndIf
      Wend
      Exc = ProgramExitCode(shell) : CloseProgram(shell)
   EndIf
   Sh\Out = Output$ : Sh\Err = Err$ : Sh\ExC = Exc
EndProcedure

; Translates AppleScript code on clipboard to obtain a PB string like below
; AppleScript MUST use TABS to indent. Better compile your AppleScript code, before copying it…
Define MyAScr.s = ~"osascript\n"+
                  ~"tell application \"Finder\"\n"+
                  ~"set mySelection to selection\n"+
                  ~"repeat with i in mySelection\n"+
                  ~"set i to contents of i\n"+
                  ~"open information window of i\n"+
                  ~"end repeat\n"+
                  ~"end tell\n"+
                  ~"return"
shShell(MyAScr, #True) ; Eventual AppleScript returned output will be in Sh\Out
Debug Sh\Out
Debug Sh\ExC
Mac OSX Ventura & Windows 10, PB 6.12
Post Reply