Ouvrir un fichier avec une extension précise
-
- Messages : 264
- Inscription : ven. 28/oct./2005 8:20
- Localisation : Mayotte ( 976 ), Océan Indien, France
Ouvrir un fichier avec une extension précise
Voilà j'aimerais que mon programme devienne celui par défaut d'un certain type d'extension fichier, mais je ne sais pas comment faire.....
Quelqu'un pourrait-il m'aiguiller ?
Quelqu'un pourrait-il m'aiguiller ?
La vie est une rose dont il faut accepter les épines, mais la mienne est fannée, arrosée par le goût de mes larmes. (Soprano)
Trouvé dans CodeArchiv.
Code : Tout sélectionner
; English forum: http://purebasic.myforums.net/viewtopic.php?t=6763&highlight=
; Author: GPI (updated for PB3.92+ by Lars)
; Date: 29. June 2003
;
;- ATTENTION
; This code changes your standard program to open pb files and creates
; an right-click.menu item for pb files. You have to undo these changes
; yourself.
Procedure SetKey(fold,Key$,Subkey$,Type,Adr,len)
If RegCreateKeyEx_(fold, Key$, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS
RegSetValueEx_(NewKey, Subkey$, 0, Type, Adr, len)
RegCloseKey_(NewKey)
EndIf
EndProcedure
Procedure AssociateFileEx(ext$,ext_description$,programm$,Icon$,prgkey$,cmd_description$,cmd_key$)
cmd$=Chr(34)+programm$+Chr(34)+" "+Chr(34)+"%1"+Chr(34)
If GetVersion_() & $FF0000 ; Windows NT/XP
SetKey(#HKEY_CLASSES_ROOT, "Applications\"+prgkey$+"\shell\"+cmd_description$+"\command","",#REG_SZ ,@cmd$,Len(cmd$)+1)
If ext_description$
Key$=ext$+"_auto_file"
SetKey(#HKEY_CLASSES_ROOT ,"."+ext$ ,"",#REG_SZ,@Key$,Len(Key$)+1)
SetKey(#HKEY_CLASSES_ROOT ,Key$ ,"",#REG_SZ,@ext_description$,Len(ext_description$)+1)
If Icon$
SetKey(#HKEY_CLASSES_ROOT,Key$+"\DefaultIcon","",#REG_SZ,@Icon$,Len(Icon$)+1)
EndIf
EndIf
SetKey(#HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"Application",#REG_SZ,@prgkey$ ,Len(prgkey$)+1)
Else ;Windows 9x
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\."+ext$ ,"",#REG_SZ,@prgkey$ ,Len(prgkey$)+1)
If ext_description$
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$ ,"",#REG_SZ,@ext_description$,Len(ext_description$)+1)
EndIf
If Icon$
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\DefaultIcon" ,"",#REG_SZ,@Icon$ ,Len(Icon$)+1)
EndIf
If cmd_description$<>cmd_key$
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$,"",#REG_SZ,@cmd_description$,Len(cmd_description$)+1)
EndIf
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$+"\command","",#REG_SZ,@cmd$ ,Len(cmd$)+1)
EndIf
EndProcedure
Procedure AssociateFile(ext$,ext_description$,programm$,Icon$)
AssociateFileEx(ext$,ext_description$,programm$,Icon$,GetFilePart(programm$),"open","open")
EndProcedure
;and now an addition context-item
AssociateFileEx("txt","","C:\WINDOWS\notepad.exe","","Notepad.exe","Ouvrir avec Bloc-Notes de Windows","open_with_notepad")
-
- Messages : 264
- Inscription : ven. 28/oct./2005 8:20
- Localisation : Mayotte ( 976 ), Océan Indien, France
Vu que je ne possède toujours pas la version complète de PureBasic
j'ai essayé de remplacer ton code par un code qui fonctionnerait sous ma démo.
J'ai donc fait ceci :
Mais lorsque je compile le programme j'ai un erreur invalid memory access..
Où ai-je fais une erreur ??

j'ai essayé de remplacer ton code par un code qui fonctionnerait sous ma démo.
J'ai donc fait ceci :
Code : Tout sélectionner
Procedure setkey(dossier, key$, subkey$, type, Adr, len)
OpenLibrary(0, "advapi32.dll")
If CallFunction(0, "RegCreateKeyEx", dossier, key$, 0, 0, 0, 44, 0, @newkey, @keyinfo) = 0
CallFunction(0, "RegSetValueEx", newkey, subkey$, 1, Adr, len)
CallFunction(0, "RegCloseKey", newkey)
EndIf
CloseLibrary(0)
EndProcedure
Procedure associatefileex(extension$, ext_description$, programme$, icon$, prgkey$, cmd_description$, cmd_key$)
cmd$ = Chr(34) + programme$ + Chr(34) + " " + Chr(34) + "%1" + Chr(34)
SetKey(-2147483648, "Applications\" + prgkey$ + "\shell\" + cmd_description$ + "\command", "", 1, @cmd$, Len(cmd$) + 1)
If ext_description$
key$ = extension$ + "_auto_file"
SetKey(-2147483648, "." + extension$ , "", 1, @Key$, Len(Key$) + 1)
SetKey(-2147483648, Key$,"", 1, @ext_description$, Len(ext_description$) + 1)
If Icon$
SetKey(-2147483648, Key$ + "\DefaultIcon", "", 1, @Icon$, Len(Icon$) + 1)
EndIf
EndIf
SetKey(-2147483647, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." + ext$, "Application", 1, @prgkey$, Len(prgkey$) + 1)
EndProcedure
AssociateFileEx("txt","","C:\WINDOWS\notepad.exe","","Notepad.exe","Ouvrir avec Bloc-Notes de Windows","open_with_notepad")
Où ai-je fais une erreur ??
La vie est une rose dont il faut accepter les épines, mais la mienne est fannée, arrosée par le goût de mes larmes. (Soprano)
Essaie ça.
Code : Tout sélectionner
Procedure SetKey(dossier, Key$, Subkey$, Type, Adr, len)
If OpenLibrary(0, "advapi32.dll")
If CallFunction(0, "RegCreateKeyExA", dossier, Key$, 0, 0, 0, 983103 , 0, @NewKey, @KeyInfo) <> 0
CallFunction(0, "RegSetValueExA", NewKey, Subkey$, 1, Adr, len)
CallFunction(0, "RegCloseKey", NewKey)
EndIf
CloseLibrary(0)
EndIf
EndProcedure
Procedure AssociateFileEx(extension$, ext_description$, programme$, Icon$, prgkey$, cmd_description$, cmd_key$)
cmd$ = Chr(34) + programme$ + Chr(34) + " " + Chr(34) + "%1" + Chr(34)
SetKey(-2147483648, "Applications\" + prgkey$ + "\shell\" + cmd_description$ + "\command", "", 1, @cmd$, Len(cmd$) + 1)
If ext_description$
Key$ = extension$ + "_auto_file"
SetKey(-2147483648, "." + extension$ , "", 1, @Key$, Len(Key$) + 1)
SetKey(-2147483648, Key$,"", 1, @ext_description$, Len(ext_description$) + 1)
If Icon$
SetKey(-2147483648, Key$ + "\DefaultIcon", "", 1, @Icon$, Len(Icon$) + 1)
EndIf
EndIf
SetKey(-2147483647, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." + ext$, "Application", 1, @prgkey$, Len(prgkey$) + 1)
EndProcedure
AssociateFileEx("txt","","C:\WINDOWS\notepad.exe","","Notepad.exe","Ouvrir avec le bloc-notes de Windows","open_with_notepad")
-
- Messages : 264
- Inscription : ven. 28/oct./2005 8:20
- Localisation : Mayotte ( 976 ), Océan Indien, France
Tu es sur Chris parce que si tu mets :
la fonction ne fera rien de plus si RegCreateKeyA renvoi un succes.. 
Code : Tout sélectionner
If CallFunction(0, "RegCreateKeyExA", dossier, Key$, 0, 0, 0, 983103 , 0, @NewKey, @KeyInfo) <> 0

La vie est une rose dont il faut accepter les épines, mais la mienne est fannée, arrosée par le goût de mes larmes. (Soprano)