It is currently Wed May 22, 2013 9:30 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to get AssociatingFiles
PostPosted: Thu Apr 05, 2012 4:28 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 671
Location: Okazaki, JAPAN
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

_________________
My general site & PureBasic Forum in Japan
My facebook page, The friend is being recruited.


Top
 Profile  
 
 Post subject: Re: How to get AssociatingFiles
PostPosted: Thu Apr 05, 2012 6:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun May 21, 2006 11:22 pm
Posts: 338
Location: Sankt Veit am Flaum
I'm not sure for PB code, but i can help with Registry:
Code:
HKEY_CLASSES_ROOT\.mp3
hold information about mp3 extension, where:
Code:
(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:
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:
"C:\Program Files\Quintessential Media Player\QMPlayer.exe" /open "%1"

_________________
Image


Top
 Profile  
 
 Post subject: Re: How to get AssociatingFiles
PostPosted: Thu Apr 05, 2012 6:42 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4715
Location: Berlin - Germany
Code:
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.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: How to get AssociatingFiles
PostPosted: Fri Apr 06, 2012 9:04 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 384
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:
;=======================================
;
;   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 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!


Top
 Profile  
 
 Post subject: Re: How to get AssociatingFiles
PostPosted: Sun Apr 08, 2012 7:54 pm 
Offline
Addict
Addict
User avatar

Joined: Tue May 10, 2005 10:00 pm
Posts: 1621
Location: Norway
Thanks for the tip, ts-soft. :)


Top
 Profile  
 
 Post subject: Re: How to get AssociatingFiles
PostPosted: Sun Apr 08, 2012 9:54 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Apr 25, 2005 9:28 pm
Posts: 552
Location: $300:20 58 FC 60 - Vietnam
Code:
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye