15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Setting the correct file extension when using CFileDialog

Chet Murphy -- cmurphy@modelworks.com
Sunday, November 03, 1996

Environment:  VC++ 4.2b, Windows95, NT 4.0

I need to be able set correct default file extension when the
extension is longer than 3 characters (e.g., java).  The problem is
that while the default extension string can be any length in an
OPENFILENAME structure, only the first three characters are appended
by the control.  This problem only occurs when the user clicks Save
for that file that has no extension.

I have tried a number of solutions, but none of them work completely
(e.g., checking for an extension of "jav" after the dialog returns
from DoModal() and overriding OnFileNameOK() work only part of the
time). The OnFileNameOK solution fails if the user tries to save a
file that already exists with the correct extension (e.g., if file
"x.java" exists then the test for an existing file succeeds if user
just saves the file as "x" because the control tests for the
existence of the file "x.jav" rather than "x.java");   

I have also looked at trapping messages in my OFNHookSaveProc for the
file name edit control, but so far I have not been successful with
that approach ( I suspect that I don't have the right id - 1152 - for
file name edit control.)  

BTW: The filter specified in my string resource for the template is
the full extension and the save dialog opens with the correct
extension.

Chet Murphy
ModelWorks Software - Editors for Java, JavaScript, VBScript, HTML
and VRML
cmurphy@modelworks.com
http://www.modelworks.com/express




Ronnie Turrentine -- rturrentine@aegisrc.com
Tuesday, November 05, 1996

Try subclassing from CFileDialog and the override some of the virtual =
methods to do what you want.  Sorry I am not specific, but I do not have =
MSVC in front of me.  Find the definition of CFileDialog in the MFC =
headers to find the virtual methods.

BTW, you will need to override OnSaveAs or whatever other document =
methods you want to use your new CFileDialog.

----------
From: 	Chet Murphy[SMTP:cmurphy@modelworks.com]
Sent: 	Sunday, November 03, 1996 3:56 PM
To: 	mfc-l@netcom.com
Subject: 	Setting the correct file extension when using CFileDialog

Environment:  VC++ 4.2b, Windows95, NT 4.0

I need to be able set correct default file extension when the
extension is longer than 3 characters (e.g., java).  The problem is
that while the default extension string can be any length in an
OPENFILENAME structure, only the first three characters are appended
by the control.  This problem only occurs when the user clicks Save
for that file that has no extension.

I have tried a number of solutions, but none of them work completely
(e.g., checking for an extension of "jav" after the dialog returns
from DoModal() and overriding OnFileNameOK() work only part of the
time). The OnFileNameOK solution fails if the user tries to save a
file that already exists with the correct extension (e.g., if file
"x.java" exists then the test for an existing file succeeds if user
just saves the file as "x" because the control tests for the
existence of the file "x.jav" rather than "x.java");  =20

I have also looked at trapping messages in my OFNHookSaveProc for the
file name edit control, but so far I have not been successful with
that approach ( I suspect that I don't have the right id - 1152 - for
file name edit control.) =20

BTW: The filter specified in my string resource for the template is
the full extension and the save dialog opens with the correct
extension.

Chet Murphy
ModelWorks Software - Editors for Java, JavaScript, VBScript, HTML
and VRML
cmurphy@modelworks.com
http://www.modelworks.com/express





| Вернуться в корень Архива |