How to get AssociatingFiles

Just starting out? Need help? Post your questions and find answers here.
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

How to get AssociatingFiles

Post by oryaaaaa »

I am using droppyLib, but I need get AssociatingFiles infomation.
coz I didn't understand associate manage registory.

Could you tell me about AssociatingFiles infomation?
1. own app associate by ".mp3"
2.chose ".mp3"
3.get Program path, and programfiles before
4. launch before associated app "abc.mp3"

I am making new audio player. but not support all function.
then my app reject, and before app run :D

Thank you
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: How to get AssociatingFiles

Post by eJan »

I'm not sure for PB code, but i can help with Registry:

Code: Select all

HKEY_CLASSES_ROOT\.mp3
hold information about mp3 extension, where:

Code: Select all

(Default)
value holds registered file type (mine is "QMP.audio" = Quintessential Player Audio File)
next step is to read "QMP.audio" = "QMP Audio File" information
where:

Code: Select all

HKEY_CLASSES_ROOT\QMP.audio\shell\open\command
give you the path of audio player which opens the mp3 file, on my comp it is:

Code: Select all

"C:\Program Files\Quintessential Media Player\QMPlayer.exe" /open "%1"
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: How to get AssociatingFiles

Post by ts-soft »

Code: Select all

Procedure.s FindAssociatedProgram(File.s)
  Protected Result.s = Space(#MAX_PATH)
  Protected Error
  
  Error = FindExecutable_(@File, 0, @Result)
  If Error <= 32
    Select Error
      Case #SE_ERR_FNF
        Debug "The specified file was not found"
      Case #SE_ERR_PNF
        Debug "The specified path is invalid"
      Case #SE_ERR_ACCESSDENIED
        Debug "The specified file cannot be accessed"
      Case #SE_ERR_OOM
        Debug "The system is out of memory or resources"
      Case #SE_ERR_NOASSOC
        Debug "There is no association for the specified file type with an executable file"
      Default
        Debug "Unknown error"
    EndSelect
    ProcedureReturn ""
  EndIf
  ProcedureReturn Result
EndProcedure

Define.s File = GetTemporaryDirectory() +"tmp.mp3"
Define FF = CreateFile(#PB_Any, File)
If FF
  CloseFile(FF)
  Debug FindAssociatedProgram(File)
  DeleteFile(File)
EndIf
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to get AssociatingFiles

Post by TI-994A »

oryaaaaa wrote:I am using droppyLib, but I need get AssociatingFiles infomation.
coz I didn't understand associate manage registory.

Could you tell me about AssociatingFiles infomation?
1. own app associate by ".mp3"
2.chose ".mp3"
3.get Program path, and programfiles before
4. launch before associated app "abc.mp3"

I am making new audio player. but not support all function.
then my app reject, and before app run :D

Thank you
Hello again, oryaaaaa. If I understand you correctly, this code should do the trick. It creates registry entries to associate the desired file type/extension with your application, and even changes the icons of the associated files to match your application icon:

Code: Select all

;=======================================
;
;   Creating registry entries for
;   application file association &
;   updating associated file icons
;   
;   by TI-994A  -  6th April, 2012
;
;=======================================

#SHCNE_ASSOCCHANGED = $8000000
#SHCNF_IDLIST = $0

Define.s keyName, keyValue
Define.i result, keyPtr

;creates an entry for your application
keyName = "MyApp"   ;short name of your app
keyValue = "My Application to do something"   ;long description of your app
result = RegCreateKey_(#HKEY_CLASSES_ROOT, keyName, @keyPtr)
result = RegSetValue_(keyPtr, "", #REG_SZ, @keyValue, 0)

;creates instructions for command-line launch
keyValue = "c:\MyAppFileName.exe %1"   ;replace with ProgramFilename() + " %1"
result = RegSetValue_(keyPtr, "Shell\Open\Command", #REG_SZ, @keyValue, #MAX_PATH)

;sets the associated file icons to match your application
;the icon keyValue can even be a direct icon, for eg: "c:\someIcon.ico"
keyValue = "c:\MyAppFileName.exe -1"   ;replace with ProgramFilename() + ",-1"
result = RegSetValue_(keyPtr, "DefaultIcon", #REG_SZ, @keyValue, #MAX_PATH)

;creates the actual file association for the specified extension
keyName = ".myp"   ;can be anything, for eg: ".mp3"
keyValue = "MyApp"
result = RegCreateKey_(#HKEY_CLASSES_ROOT, keyName, @keyPtr)
result = RegSetValue_(keyPtr, "", #REG_SZ, @keyValue, 0)

;effects a system-wide notification of the changes
SHChangeNotify_(#SHCNE_ASSOCCHANGED, #SHCNF_IDLIST, 0, 0)

End
Hope this is helpful for you, and good luck on your audio player project!
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: How to get AssociatingFiles

Post by utopiomania »

Thanks for the tip, ts-soft. :)
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: How to get AssociatingFiles

Post by flaith »

Code: Select all

Enumeration
  #ASSOCSTR_COMMAND              = 1
  #ASSOCSTR_EXECUTABLE
  #ASSOCSTR_FRIENDLYDOCNAME
  #ASSOCSTR_FRIENDLYAPPNAME
  #ASSOCSTR_NOOPEN
  #ASSOCSTR_SHELLNEWVALUE
  #ASSOCSTR_DDECOMMAND
  #ASSOCSTR_DDEIFEXEC
  #ASSOCSTR_DDEAPPLICATION
  #ASSOCSTR_DDETOPIC
  #ASSOCSTR_INFOTIP
  #ASSOCSTR_QUICKTIP
  #ASSOCSTR_TILEINFO
  #ASSOCSTR_CONTENTTYPE
  #ASSOCSTR_DEFAULTICON
  #ASSOCSTR_SHELLEXTENSION
  #ASSOCSTR_DROPTARGET
  #ASSOCSTR_DELEGATEEXECUTE
  #ASSOCSTR_MAX
EndEnumeration

Enumeration 
  #ASSOCF_INIT_NOREMAPCLSID      = $00000001
  #ASSOCF_INIT_BYEXENAME         = $00000002
  #ASSOCF_OPEN_BYEXENAME         = $00000002
  #ASSOCF_INIT_DEFAULTTOSTAR     = $00000004
  #ASSOCF_INIT_DEFAULTTOFOLDER   = $00000008
  #ASSOCF_NOUSERSETTINGS         = $00000010
  #ASSOCF_NOTRUNCATE             = $00000020
  #ASSOCF_VERIFY                 = $00000040
  #ASSOCF_REMAPRUNDLL            = $00000080
  #ASSOCF_NOFIXUPS               = $00000100
  #ASSOCF_IGNOREBASECLASS        = $00000200
  #ASSOCF_INIT_IGNOREUNKNOWN     = $00000400   
EndEnumeration

pcchOut.l   = #MAX_PATH
pszOut.s    = Space(255)
flags       = #ASSOCF_NOTRUNCATE | #ASSOCF_REMAPRUNDLL
pszAssoc.s  = ".xls"
pszExtra.s  = "open"

If OpenLibrary(0, "Shlwapi.dll")
  *AssocQueryString = GetFunction(0, "AssocQueryStringA")
  If *AssocQueryString
    hresult = CallFunctionFast(*AssocQueryString, flags, #ASSOCSTR_EXECUTABLE, @pszAssoc, @pszExtra, @pszOut, pcchOut)
    Select hresult
      Case #S_OK
        Debug "Executable name for '"+pszAssoc+"' : "+pszOut
      Case #S_FALSE
        Debug "pszOut is NULL. pcchOut contains the required buffer size"
      Case #E_POINTER
        Debug "The pszOut buffer is too small to hold the entire string"
      Default
        Debug "No association defined for extension '"+pszAssoc+"'"
    EndSelect
  EndIf
EndIf
“Fear is a reaction. Courage is a decision.” - WC
Post Reply