MFC and file extensions

Started by
5 comments, last by DirectAndy8 21 years, 11 months ago
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.
Advertisement
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.
MacPro 2.66 GHz QuadCore, OS X 10.5, 5GB, Radeon x1900 and no more gray hair.http://www.spexlab.org
Oh yes run regedit.exe and browse a little the HKEY_CLASSES_ROOT
to find out more =) (Don''t show your fear to the registry)
MacPro 2.66 GHz QuadCore, OS X 10.5, 5GB, Radeon x1900 and no more gray hair.http://www.spexlab.org
For your second question: CFileDialog constructor takes lpszDefExt parameter.
---visit #directxdev on afternet <- not just for directx, despite the name
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.
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.
Sorted now, thanks everyone, especially cgoat who made things nice and easy for me. :D

This topic is closed to new replies.

Advertisement