Archived

This topic is now archived and is closed to further replies.

MFC and file extensions

This topic is 5697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m creating an app in MFC and have now got to the stage where I want to serialize my documents. This is not a problem, I''m working on it. However I want all the documents that my app creates to have the extension ".cpa". 1. How do I inform the Windows registry that all ".cpa" files should be associated with my application (that is, which settings need I change)? I know this should be done on install, but because my app is reasonably simple and won''t need a seperate installer, I''m thinking I might ensure that such an association exists on program startup instead; how much of a bad idea is this? 2. How do I tell the "Save" and "Load" dialogs to default to ".cpa" files? I couldn''t find much about this in the help files. Thanks for any help you can give.

Share this post


Link to post
Share on other sites
Hi! I don''t know solution to your problem, but I think that when you want to register your file extension you must add the following stuff to the registry:

Path: HKEY_CLASSES_ROOT
Add New: .cpa
Type: REG_SZ (in the reg edit)
Data: Your.Application

Path: HKEY_CLASSES_ROOT
Add New: Your.Application
(No values)

Path: HKEY_CLASSES_ROOT\Your.Application
Add New: shell
(No values)

Path: HKEY_CLASSES_ROOT\Your.Application\shell
Add New: Open
(No values needed)

Path: HKEY_CLASSES_ROOT\Your.Application\shell\open
Add New: command
Type: REG_SZ
Data: Your\Application\Path\YouApp.EXE "%1"

I figured this by browsing the registry so I''m not sure that thiss will be enough. The registry might need more information, but I hope this will get you started.

Share this post


Link to post
Share on other sites
Using the MFC framework, he''s not calling Open or Save in his code, it''s handled by the MFC framework. So there''s not lpszDefaultExt to pass.

What you need to do is go into the resource editor, String Table, and edit the IDR_???TYPE where the ??? is your application name, in my case IDR_TESTTYPE. It has 7 fields that describe your document, and includes the default extension, description and other things. I''ll have to look up the fields, but it''s in the MSDN library somewhere. If I get a chance I''ll post a sample string for you.

Share this post


Link to post
Share on other sites
Here''s the example string from the MSDN library (CSingleDocTemplate::CSingleDocTemplate page):

IDR_SHEETTYPE "\nSheet\nWorksheet\nWorksheets (*.myc)\n.myc\n MyCalcSheet\nMyCalc Worksheet"

Basically, you can copy that and change it to fit your file. Each field is separated by \n and describes what MFC needs to know to display the dialog properly.

Share this post


Link to post
Share on other sites