Seite 1 von 1

SHOpenWithDialog Function mit PB

Verfasst: 29.05.2015 02:32
von Marty2PB
Moin,
Da ich nicht das Standard Context Menu von Windows nutze aber nur den 'Öffne mit' Dialog benötige und SHOpenWithDialog_() so nicht unter PB aufrufen lässt
habe ich das mal so gemacht :)
Hoffe das ist richtig 'Konvertiert' habe. Bin noch nicht so bewandert mi PB :| aber Funktioniert :mrgreen:

Source: https://msdn.microsoft.com/de-de/librar ... 85%29.aspx
Source: https://msdn.microsoft.com/de-de/librar ... 85%29.aspx

Code: Alles auswählen

    #OAIF_ALLOW_REGISTRATION = $00000001 ; Enable the "always use this program" checkbox. If Not passed, it will be disabled.
    #OAIF_REGISTER_EXT       = $00000002 ; Do the registration after the user hits the OK button.
    #OAIF_EXEC               = $00000004 ; Execute file after registering.
    #OAIF_FORCE_REGISTRATION = $00000008 ; Force the Always use this program checkbox To be checked. Typically, you won't use the OAIF_ALLOW_REGISTRATION flag when you pass this value. 
    #OAIF_HIDE_REGISTRATION  = $00000020 ; Introduced IN Windows Vista. Hide the Always use this program checkbox. If this flag is specified, the OAIF_ALLOW_REGISTRATION And OAIF_FORCE_REGISTRATION flags will be ignored. 
    #OAIF_URL_PROTOCOL       = $00000040 ; Introduced IN Windows Vista. The value For the extension that is passed is actually a protocol, so the Open With dialog box should show applications that are registered As capable of handling that protocol.
    #OAIF_FILE_IS_URI        = $00000080 ; Introduced IN Windows 8. The location pointed To by the pcszFile parameter is given As a URI.
    
Procedure SH_OpenWithDialog_(File$,OPEN_AS_INFO_FLAGS.l)
    
    Protected LibraryID
    
    Structure OPENASINFO
        pcszFile.i
        pcszClass.i
        oaifInFlags.l
    EndStructure  
  
    LibraryID = OpenLibrary(#PB_Any, "shell32.dll")
    If LibraryID
        
        Define OWD.OPENASINFO
        
        OWD\pcszFile = @File$
        OWD\pcszClass = #Null
        OWD\oaifInFlags = OPEN_AS_INFO_FLAGS
        
        CallFunction(LibraryID, "SHOpenWithDialog", hwnd,@OWD.OPENASINFO)
        CloseLibrary(LibraryID)
    EndIf
EndProcedure

File$ = #PB_Compiler_Home + "SDK\VisualC\Readme.txt"
SH_OpenWithDialog_(File$,#OAIF_ALLOW_REGISTRATION|#OAIF_EXEC)
__________________________________________________
MSDN-Links angepasst
29.05.2015
RSBasic

Re: SHOpenWithDialog Function mit PB

Verfasst: 29.05.2015 02:40
von NicTheQuick
Besser du öffnest die Library nur einmal am Anfang, anstatt sie jedes mal neu zu öffnen.

Re: SHOpenWithDialog Function mit PB

Verfasst: 29.05.2015 03:29
von Marty2PB
NicTheQuick hat geschrieben:Besser du öffnest die Library nur einmal am Anfang, anstatt sie jedes mal neu zu öffnen.
So ?

Code: Alles auswählen

    #OAIF_ALLOW_REGISTRATION = $00000001 ; Enable the "always use this program" checkbox. If Not passed, it will be disabled.
    #OAIF_REGISTER_EXT       = $00000002 ; Do the registration after the user hits the OK button.
    #OAIF_EXEC               = $00000004 ; Execute file after registering.
    #OAIF_FORCE_REGISTRATION = $00000008 ; Force the Always use this program checkbox To be checked. Typically, you won't use the OAIF_ALLOW_REGISTRATION flag when you pass this value. 
    #OAIF_HIDE_REGISTRATION  = $00000020 ; Introduced IN Windows Vista. Hide the Always use this program checkbox. If this flag is specified, the OAIF_ALLOW_REGISTRATION And OAIF_FORCE_REGISTRATION flags will be ignored. 
    #OAIF_URL_PROTOCOL       = $00000040 ; Introduced IN Windows Vista. The value For the extension that is passed is actually a protocol, so the Open With dialog box should show applications that are registered As capable of handling that protocol.
    #OAIF_FILE_IS_URI        = $00000080 ; Introduced IN Windows 8. The location pointed To by the pcszFile parameter is given As a URI.
    
    Structure OPENASINFO
        pcszFile.i
        pcszClass.i
        oaifInFlags.l
    EndStructure 
           
    Prototype SH_OpenWithDialog_(HWND,*poainfo)
    If OpenLibrary(0, "SHELL32.DLL")
        Global SH_OpenWithDialog_.SH_OpenWithDialog_ = GetFunction(0, "SHOpenWithDialog")
        CloseLibrary(0)
    EndIf    
        
 Procedure SH_OpenWithDialog(File$,OPEN_AS_INFO_FLAGS.l)
    
    Define OWD.OPENASINFO
    
    OWD\pcszFile = @File$
    OWD\pcszClass = #Null
    OWD\oaifInFlags = OPEN_AS_INFO_FLAGS
      
    Result = SH_OpenWithDialog_(hwnd,@OWD.OPENASINFO)
    ProcedureReturn Result 
 EndProcedure    
 
File$ = #PB_Compiler_Home + "SDK\VisualC\Readme.txt"
Debug SH_OpenWithDialog(File$,#OAIF_ALLOW_REGISTRATION|#OAIF_EXEC)

Re: SHOpenWithDialog Function mit PB

Verfasst: 29.05.2015 08:51
von edel
Du darfst sie nicht schliessen. Solange du auf die Funktionen der DLL zugreifen moechtest, muss die DLL auch geladen bleiben. Es spricht auch nichts dagegen, sie bis zum Ende geladen zu haben. PB gibt sie dann automatisch frei.

Re: SHOpenWithDialog Function mit PB

Verfasst: 29.05.2015 09:30
von _JON_
Pass aber auch immer auf ob die Funktion überhaupt verfügbar ist.

Code: Alles auswählen

EnableExplicit

#OAIF_ALLOW_REGISTRATION = $00000001 ; Enable the "always use this program" checkbox. If Not passed, it will be disabled.
#OAIF_REGISTER_EXT       = $00000002 ; Do the registration after the user hits the OK button.
#OAIF_EXEC               = $00000004 ; Execute file after registering.
#OAIF_FORCE_REGISTRATION = $00000008 ; Force the Always use this program checkbox To be checked. Typically, you won't use the OAIF_ALLOW_REGISTRATION flag when you pass this value. 
#OAIF_HIDE_REGISTRATION  = $00000020 ; Introduced IN Windows Vista. Hide the Always use this program checkbox. If this flag is specified, the OAIF_ALLOW_REGISTRATION And OAIF_FORCE_REGISTRATION flags will be ignored. 
#OAIF_URL_PROTOCOL       = $00000040 ; Introduced IN Windows Vista. The value For the extension that is passed is actually a protocol, so the Open With dialog box should show applications that are registered As capable of handling that protocol.
#OAIF_FILE_IS_URI        = $00000080 ; Introduced IN Windows 8. The location pointed To by the pcszFile parameter is given As a URI.

Structure OPENASINFO
  pcszFile.i
  pcszClass.i
  oaifInFlags.l
EndStructure 

Prototype pSH_OpenWithDialog(HWND, *poainfo)

Procedure.l OpenWithDialog(File$, OPEN_AS_INFO_FLAGS.l = 0, hwnd.i = 0)
  
  Protected OWD.OPENASINFO, hShell32, SH_OpenWithDialog_.pSH_OpenWithDialog, Result
  
  hShell32 = OpenLibrary(#PB_Any, "SHELL32")
  If hShell32
    SH_OpenWithDialog_ = GetFunction(hShell32, "SHOpenWithDialog")
    If SH_OpenWithDialog_
      OWD\pcszFile = @File$
      OWD\pcszClass = #Null
      OWD\oaifInFlags = OPEN_AS_INFO_FLAGS
      Result = SH_OpenWithDialog_(hwnd, @OWD.OPENASINFO)
    Else
      Result = OpenAs_RunDLL_(hwnd, 0, File$, 0)
    EndIf
    CloseLibrary(hShell32)
  EndIf   
  
  ProcedureReturn Result 
EndProcedure    

Define File$ = #PB_Compiler_Home + "SDK\VisualC\Readme.txt"
Debug OpenWithDialog(File$,#OAIF_ALLOW_REGISTRATION|#OAIF_EXEC)

Re: SHOpenWithDialog Function mit PB

Verfasst: 29.05.2015 18:49
von Marty2PB
Ah Ok, ich hatte das so verstanden das 'OpenLibrary' nicht in eine Procdure sollte. Danke für das korrigieren @all :)

Re: SHOpenWithDialog Function mit PB

Verfasst: 30.05.2015 12:57
von NicTheQuick
Damit es kein Missverständnis gibt:
Natürlich darf 'OpenLibrary()' in eine Procedure, aber ein ständiges Öffnen und Schließen der Library kostet Zeit und Resourcen, weswegen es schlauer ist, sie nur einmalig zu öffnen.
Mit einem "Static" kann man auch erreichen, dass sie nur einmal geöffnet wird.

Code: Alles auswählen

EnableExplicit

#OAIF_ALLOW_REGISTRATION = $00000001 ; Enable the "always use this program" checkbox. If Not passed, it will be disabled.
#OAIF_REGISTER_EXT       = $00000002 ; Do the registration after the user hits the OK button.
#OAIF_EXEC               = $00000004 ; Execute file after registering.
#OAIF_FORCE_REGISTRATION = $00000008 ; Force the Always use this program checkbox To be checked. Typically, you won't use the OAIF_ALLOW_REGISTRATION flag when you pass this value.
#OAIF_HIDE_REGISTRATION  = $00000020 ; Introduced IN Windows Vista. Hide the Always use this program checkbox. If this flag is specified, the OAIF_ALLOW_REGISTRATION And OAIF_FORCE_REGISTRATION flags will be ignored.
#OAIF_URL_PROTOCOL       = $00000040 ; Introduced IN Windows Vista. The value For the extension that is passed is actually a protocol, so the Open With dialog box should show applications that are registered As capable of handling that protocol.
#OAIF_FILE_IS_URI        = $00000080 ; Introduced IN Windows 8. The location pointed To by the pcszFile parameter is given As a URI.

Structure OPENASINFO
	pcszFile.i
	pcszClass.i
	oaifInFlags.l
EndStructure

Prototype pSH_OpenWithDialog(HWND, *poainfo)

Procedure.l OpenWithDialog(File$, OPEN_AS_INFO_FLAGS.l = 0, hwnd.i = 0)
	Static hShell32 = #False
	Protected OWD.OPENASINFO, SH_OpenWithDialog_.pSH_OpenWithDialog, Result = #False
	
	If (Not hShell32)
		hShell32 = OpenLibrary(#PB_Any, "SHELL32")
	EndIf
	
	If hShell32
		SH_OpenWithDialog_ = GetFunction(hShell32, "SHOpenWithDialog")
		If SH_OpenWithDialog_
			OWD\pcszFile = @File$
			OWD\pcszClass = #Null
			OWD\oaifInFlags = OPEN_AS_INFO_FLAGS
			Result = SH_OpenWithDialog_(hwnd, @OWD.OPENASINFO)
		Else
			Result = OpenAs_RunDLL_(hwnd, 0, File$, 0)
		EndIf
	EndIf   
	
	ProcedureReturn Result
EndProcedure   

Define File$ = #PB_Compiler_Home + "SDK\VisualC\Readme.txt"
Debug OpenWithDialog(File$,#OAIF_ALLOW_REGISTRATION|#OAIF_EXEC)