Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
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
#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)
#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)
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.
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)
PureBasic 5.46 LTS (Windows x86/x64) | windows 10 x64 Oktober failure
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.
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)