Page 1 of 3

Register a file extension and asign it the ico of the execut

Posted: Wed May 28, 2014 8:49 pm
by ricardo
Hi,

I want to register some file extension and asign to this extension some ico (maybe the ico of an exe or dll).

Can anybody point me in the right direction please?

Re: Register a file extension and asign it the ico of the ex

Posted: Wed May 28, 2014 10:54 pm
by IdeasVacuum
It's not really a job for the App itself, but the Installer, and most installers make the registration of file extensions and associated icons pretty easy.

Re: Register a file extension and asign it the ico of the ex

Posted: Wed May 28, 2014 11:12 pm
by ricardo
Its on the registry but wirh my alzheimer (not really, but virtual alzheimer he he) i dont remember where do i have the code to set this on the registry.

Re: Register a file extension and asign it the ico of the ex

Posted: Thu May 29, 2014 5:04 am
by netmaestro
You could give this a try. I ripped it out of my QuickUpload application from 7 years ago:

Code: Select all

Procedure ContextMenuAddAll(programfriendlyname$, programpath$, state=1, includefolders=0)
  ; netmaestro November 2007 
  Protected key.l = #HKEY_CLASSES_ROOT 
  Protected path$ = "*\shell\"+programfriendlyname$+"\command" 
  Protected value$ = "" 
  Protected string$ = programpath$+" "+Chr(34)+"%1"+Chr(34)  
  Protected keyresult.l 
  If state 
    RegCreateKey_(key,@path$,@keyresult) 
    RegSetValueEx_(keyresult,@value$,0,#REG_SZ,@string$,Len(string$)) 
    If includefolders
      path2$ = "directory\shell\"+programfriendlyname$+"\command"
      RegCreateKey_(key, @path2$, @keyresult)
      If RegSetValueEx_(keyresult,@value$,0,#REG_SZ,@string$,Len(string$)) = #ERROR_SUCCESS 
        result = 1
      Else
        result = 0
      EndIf
    EndIf
  Else 
    path$ = "*\shell\"+programfriendlyname$+"\command" 
    RegDeleteKey_(key,@path$) 
    path$ = "*\shell\"+programfriendlyname$ 
    result1 = RegDeleteKey_(key,@path$) 
    If includefolders
      path2$ = "directory\shell\"+programfriendlyname$+"\command"
      RegDeleteKey_(key,@path2$)     
      path2$ = "directory\shell\"+programfriendlyname$
      result2 = RegDeleteKey_(key,@path2$) 
      If result1 =#ERROR_SUCCESS And result2 = #ERROR_SUCCESS
        result = 1
      Else
        result = 0
      EndIf
    Else
      If result1 = #ERROR_SUCCESS
        result = 1
      Else
        result = 0
      EndIf
    EndIf
  EndIf 
  RegCloseKey_(keyresult)
  ProcedureReturn result
EndProcedure 

Re: Register a file extension and asign it the ico of the ex

Posted: Fri May 30, 2014 12:33 am
by ricardo
I will test it, thanks :)

Re: Register a file extension and asign it the ico of the ex

Posted: Sun Jun 01, 2014 12:23 am
by ricardo
programfriendlyname is the extension?
What is state? And what is includefolders?

Im trying to fully understand...

Thanks in advance :)
netmaestro wrote:You could give this a try. I ripped it out of my QuickUpload application from 7 years ago:

Code: Select all

Procedure ContextMenuAddAll(programfriendlyname$, programpath$, state=1, includefolders=0)
  ; netmaestro November 2007 
  Protected key.l = #HKEY_CLASSES_ROOT 
  Protected path$ = "*\shell\"+programfriendlyname$+"\command" 
  Protected value$ = "" 
  Protected string$ = programpath$+" "+Chr(34)+"%1"+Chr(34)  
  Protected keyresult.l 
  If state 
    RegCreateKey_(key,@path$,@keyresult) 
    RegSetValueEx_(keyresult,@value$,0,#REG_SZ,@string$,Len(string$)) 
    If includefolders
      path2$ = "directory\shell\"+programfriendlyname$+"\command"
      RegCreateKey_(key, @path2$, @keyresult)
      If RegSetValueEx_(keyresult,@value$,0,#REG_SZ,@string$,Len(string$)) = #ERROR_SUCCESS 
        result = 1
      Else
        result = 0
      EndIf
    EndIf
  Else 
    path$ = "*\shell\"+programfriendlyname$+"\command" 
    RegDeleteKey_(key,@path$) 
    path$ = "*\shell\"+programfriendlyname$ 
    result1 = RegDeleteKey_(key,@path$) 
    If includefolders
      path2$ = "directory\shell\"+programfriendlyname$+"\command"
      RegDeleteKey_(key,@path2$)     
      path2$ = "directory\shell\"+programfriendlyname$
      result2 = RegDeleteKey_(key,@path2$) 
      If result1 =#ERROR_SUCCESS And result2 = #ERROR_SUCCESS
        result = 1
      Else
        result = 0
      EndIf
    Else
      If result1 = #ERROR_SUCCESS
        result = 1
      Else
        result = 0
      EndIf
    EndIf
  EndIf 
  RegCloseKey_(keyresult)
  ProcedureReturn result
EndProcedure 

Re: Register a file extension and asign it the ico of the ex

Posted: Sun Jun 01, 2014 12:49 am
by ricardo
I found this, but does not work with the icon part

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"
keyValue = "My Application to do something"
Result = RegCreateKey_(#HKEY_CLASSES_ROOT, keyName, @keyPtr)
Result = RegSetValue_(keyPtr, "", #REG_SZ, @keyValue, 0)

;creates instructions for command-line launch
keyValue = 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:\Users\user\Pictures\Iconos\Ico\konfabulator_icon.ico,-1"
Result = RegSetValue_(keyPtr, "DefaultIcon", #REG_SZ, @keyValue, #MAX_PATH)

;creates the actual file association for the specified extension
keyName = ".myp123"
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

Re: Register a file extension and asign it the ico of the ex

Posted: Sun Jun 01, 2014 4:23 am
by PB
> It's not really a job for the App itself

What? Plenty of apps have an option to set file associations.
Mainly image/video viewers, and even PureBasic itself does it.

Re: Register a file extension and asign it the ico of the ex

Posted: Sun Jun 01, 2014 5:17 am
by Kuron
PB wrote:What? Plenty of apps have an option to set file associations.
Mainly image/video viewers, and even PureBasic itself does it.
Very common in compression programs and audio programs, too.

Re: Register a file extension and asign it the ico of the ex

Posted: Fri Jul 04, 2014 6:19 pm
by ricardo
I think its common to register a file extension and make that it shows the icon of the app.

Re: Register a file extension and asign it the ico of the ex

Posted: Tue Jul 08, 2014 12:15 am
by ricardo
This works fine for me:

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:\Test.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 = ProgramFilename() 
Result = RegSetValue_(keyPtr, "DefaultIcon", #REG_SZ, @keyValue, #MAX_PATH)

;creates the actual file association for the specified extension
keyName = ".myext" ;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)


Re: Register a file extension and asign it the ico of the execut

Posted: Fri Jun 02, 2023 10:22 am
by aston
I know that this is old topic
but i try to compile and seems fine
but file icon is not changed
I am interested only in icon chenge
so i am asking what is wrong ?
or maybe some of you have tiny app with this program i mean GUI app.

thanks in advance !

Re: Register a file extension and asign it the ico of the execut

Posted: Fri Jun 02, 2023 10:33 am
by AZJIO
ClearIconCache()
viewtopic.php?t=78505

Re: Register a file extension and asign it the ico of the execut

Posted: Fri Jun 02, 2023 10:40 am
by jacdelad
aston wrote: Fri Jun 02, 2023 10:22 am I know that this is old topic
but i try to compile and seems fine
but file icon is not changed
I am interested only in icon chenge
so i am asking what is wrong ?
or maybe some of you have tiny app with this program i mean GUI app.

thanks in advance !

Code: Select all

RunProgram("ie4uinit -show")

Re: Register a file extension and asign it the ico of the execut

Posted: Fri Jun 02, 2023 2:33 pm
by aston
Thank you but i don't understand both answers

how to clearIconCache() ?

is that function or something else?

what is RunProgram() ?

I never see such a commands before .

Is here anyone who can confirm that above program can change icon of file with
specified extension ?

I know that old DLib IDE can do that programmed by author i guess.