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

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

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

Post 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?
ARGENTINA WORLD CHAMPION
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

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

Post 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.
ARGENTINA WORLD CHAMPION
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post 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 
BERESHEIT
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

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

Post by ricardo »

I will test it, thanks :)
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

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

Post 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 
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

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

Post 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
ARGENTINA WORLD CHAMPION
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

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

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

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

Post 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.
Best wishes to the PB community. Thank you for the memories. ♥️
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

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

Post by ricardo »

I think its common to register a file extension and make that it shows the icon of the app.
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

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

Post 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)

ARGENTINA WORLD CHAMPION
User avatar
aston
User
User
Posts: 64
Joined: Wed Nov 18, 2009 11:18 pm

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

Post 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 !
AZJIO
Addict
Addict
Posts: 1318
Joined: Sun May 14, 2017 1:48 am

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

Post by AZJIO »

ClearIconCache()
viewtopic.php?t=78505
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

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

Post 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")
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
aston
User
User
Posts: 64
Joined: Wed Nov 18, 2009 11:18 pm

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

Post 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.
Post Reply