[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MFC: File Association

Posted on 2011-05-12
9
Medium Priority
?
628 Views
Last Modified: 2012-08-13
Dear experts,

I have an MFC application. The user can check for update, then (if an update is needed)  a new executable with a different name is downloaded. I want now to associate documents that the application opens, with the new executable. I found a web site that provides an example how to reset file association:
http://www.codeproject.com/KB/shell/cgfiletype.aspx
But though a new entry is added in the registry, nothing changes, and the document is still opened with an old version of the program, and the icon in the Windows Explorer looks like before.
I use Windows XP, but of course I want the program to work also in the higher versions.
Could you  please tell what I am missing?
Thanks.
0
Comment
Question by:tantormedia
  • 5
  • 2
  • 2
9 Comments
 
LVL 30

Expert Comment

by:flubbster
ID: 35746318
Try this

Open any folder
Click on Tools
Select Folder Options
Select File Types
Scroll down and file the extension that you want to associate with the new peogram
Click on Change
Click on Browse
Using the Browse window that opened, find the executable that you want to use to open that extension
Double-click the program to select it
Make sure that "Always use this program...." is checked
Click on ok/apply to back out
Test
0
 

Author Comment

by:tantormedia
ID: 35746338
Thank you very much for your answer. But I need the file association to be updated automatically, I don't want the user to do it every time an update is downloaded.
0
 

Author Comment

by:tantormedia
ID: 35746574
I found solution for changing icons:
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);

But when I click on a document icon in the explorer, it is still opened with the old version of the program.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 30

Expert Comment

by:flubbster
ID: 35747005
Can you paste exactly what code you used?
0
 
LVL 35

Expert Comment

by:sarabande
ID: 35747297
you could find out your filetype with the command line

  assoc .yourtype

it will prompt like

.yourtype=yourfiletype

then you could change or add an 'open' command for that filetype by

 ftype yourfiletype=path_to_your_exe %1

Sara
0
 

Author Comment

by:tantormedia
ID: 35747337
Thank you Sara,

This is what my program does automatically on update:

// Update file association
	CGCFileTypeAccess TheFTA;

	// get full file path to program executable file
	//TCHAR	szProgPath[MAX_PATH * 2];
	//::GetModuleFileName(NULL, szProgPath, sizeof(szProgPath)/sizeof(TCHAR));

	CString csTempText;

	TheFTA.SetExtension("bok");

	// just pass file path in quotes on command line
	csTempText.Format("\"%s\" %s", executable, "\"%1\"");

	TheFTA.SetShellOpenCommand(csTempText);
	TheFTA.SetDocumentShellOpenCommand(csTempText);

	TheFTA.SetDocumentClassName("CGFileType.Document");

	// use first icon in program
	csTempText  = executable;
	csTempText += ",0";
	TheFTA.SetDocumentDefaultIcon(csTempText);

	SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); 

	// set the necessary registry entries	
	TheFTA.RegSetAllInfo();

Open in new window

0
 

Accepted Solution

by:
tantormedia earned 0 total points
ID: 35747400
Never mind, I figured it out: I had to remove Application entry in HKCU\Software\Microsoft\Windows\Current Version\Explorer\FileExts\.myext.
Thanks.
0
 
LVL 35

Expert Comment

by:sarabande
ID: 35747504
you might check on return codes and errors in your code.

the user must be local admin to have the rights for your code, and i wonder whether you could make updates with the code.

Sara
0
 

Author Closing Comment

by:tantormedia
ID: 35775476
The solution is in my previous message.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question