PDA

View Full Version : Anyone familiar with file associations?



element78
08-30-2003, 07:59 PM
I want a button where when you click on it, it sets a certain file extension to open with a certain program.

Any ideas? I got it to where it adds the program to the "recommended applications to open with this extension" list, but I can't get it to physically make the program the default to run that extension.

Any help would be great.

TJ_Tigger
08-30-2003, 09:20 PM
I believe those associations are controlled by registry entries. You should be able to set the default associations there. BUT I am one of those people that does not like it when a program changes my file associations. I actually Hate it. But that is me. I will look in the registry to see if I can find the entries.

element78
08-30-2003, 09:29 PM
Well thats the whole deal, i'm making it an OPTION in my AMS application. if they click a button, it will associate the program with that extension.. if they click another button, it will de-associate it and renew the previous configuration

Worm
08-30-2003, 09:39 PM
Here is some VB Code that I've used for file associations. I know its VB, but you should be able to break it down fairly easy.

'See if our file extension already exists:
If GetString(HKEY_CLASSES_ROOT, ".i01", "Content Type") = "" Then
'Nope - not added yet. Register the file type:

'create an entry in the class key
Call SaveString(HKEY_CLASSES_ROOT, ".i01", "", "Mini Estimate")
'content type
Call SaveString(HKEY_CLASSES_ROOT, ".i01", "Content Type", "text/plain")
'name
Call SaveString(HKEY_CLASSES_ROOT, "Mini Estimate", "", "Intec Mini Estimate file")
'edit flags
Call SaveDWord(HKEY_CLASSES_ROOT, "Mini Estimate", "EditFlags", "0000")
'file's icon (can be an icon file, or an icon located within a dll file)
'in this example, I am using a resource icon in this exe, 0 (app icon).
Call SaveString(HKEY_CLASSES_ROOT, "Mini Estimate\DefaultIcon", "", App.Path & "\" & App.EXEName & ".exe,0")
'Shell
Call SaveString(HKEY_CLASSES_ROOT, "Mini Estimate\Shell", "", "")
'Shell Open
Call SaveString(HKEY_CLASSES_ROOT, "Mini Estimate\Shell\Open", "", "")
'Shell open command
Call SaveString(HKEY_CLASSES_ROOT, "Mini Estimate\Shell\Open\Command", "", App.Path & "\" & App.EXEName & ".exe %1")
'Update the Windows Icon Cache to see our icon right away:
SHChangeNotify SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0

End If

element78
08-30-2003, 09:41 PM
Worm, is there anything you CAN'T do? /ubbthreads/images/icons/smile.gif

Thanks so much

element78
08-30-2003, 09:43 PM
what dll does the SHChangeNotify function need to be called from? user32?

Worm
08-30-2003, 09:44 PM
Can't seem to get an Application's button to NOT appear in the taskbar. It's driving me nuts. And OH So many other things.

Worm
08-30-2003, 09:48 PM
Shell32.dll

element78
08-30-2003, 09:49 PM
Worm, this might be of some help:




Managing Taskbar Buttons
The Shell creates a button on the taskbar whenever an application creates a window that isn't owned. To ensure that the window button is placed on the taskbar, create an unowned window with the WS_EX_APPWINDOW extended style. To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window.

The Shell will remove a window's button from the taskbar only if the window's style supports visible taskbar buttons. If you want to dynamically change a window's style to one that doesn't support visible taskbar buttons, you must hide the window first (by calling ShowWindow with SW_HIDE), change the window style, and then show the window.

The window button typically contains the application icon and title. However, if the application does not contain a system menu, the window button is created without the icon.

If you want your application to get the user's attention when the window is not active, use the FlashWindow function to let the user know that a message is waiting. This function flashes the window button. Once the user clicks the window button to activate the window, your application can display the message.

Modifying the Contents of the Taskbar
Version 4.71 and later of Shell32.dll adds the capability to modify the contents of the taskbar. From an application, you can now add, remove, and activate taskbar buttons. Activating the item does not activate the window; it shows the item as pressed on the taskbar.

The taskbar modification capabilities are implemented in a Component Object Model (COM) object (CLSID_TaskbarList ) that exposes the ITaskbarList interface (IID_ITaskbarList ). You must call the HrInit method to initialize the object. You can then use the methods of the ITaskbarList interface to modify the contents of the taskbar.





The actual link (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_int/shell_int_programming/taskbar.asp)

that might help... read the last sentence i bolded

Worm
08-30-2003, 09:52 PM
Been down that road. Seems that when the window gets focus the button magically reappears. Thanks for the info though.