求救CommonDialog的问题!多谢多谢!

Sandy 2000-04-13 09:12:00
为什么我在Win2000的VC6中使用使用CFileDialog生成的标准对话筐
与Win2000自身的打开文件的对话筐不同,并且仍然保持着Win9x系列
的风格!
请教各位大虾要生成Win2000风格的标准对话框应如何做!
小弟在此不胜感激!!
...全文
119 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
longx 2000-04-14
  • 打赏
  • 举报
回复
这里有关于Windoe 2000 Dialog用法的说明。
Introduction
If you've tried using the MFC common dialog class CFileDialog in Windows 2000 you'll notice that it will show the 'old' file dialog even with the OFN_EXPLORER flag set. The reason for this is that that Windows 2000 uses OFN_ENABLE_HOOK flag to determine which dialog to use. If the OFN_ENABLE_HOOK flag is set, Windows 2000 uses the old dialog, if not, it uses the new dialog. CFileDialog in MFC uses the OFN_ENABLE_HOOK flag which explains why all MFC applications display the old dialog and regular applications (not compiled with MFC) show the new dialog if run in Windows 2000. For a more detailed explanation look in April 2000 issue of MSDN pp.138,139. I've managed to get around this by overriding some of MFC's virtual functions and not allowing MFC to set the OFN_ENABLE_HOOK flag.

Step 1:
Insert CKSDialog into your MFC project. Add the following header file to your Apps implementation file.


#include "KSDialog.h"

Step 2:
Add the following function headers to you Apps header file.

virtual BOOL DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags,
BOOL bOpenFileDialog, CDocTemplate* pTemplate);

Then enter the functions body in the your Apps implementation file.

BOOL CMyAppApp::DoPromptFileName(CString& fileName, UINT nIDSTitle, DWORD lFlags,
BOOL bOpenFileDialog, CDocTemplate* pTemplate)
{
CKSFileDialog dlgFile(bOpenFileDialog);
dlgFile.SetAppPointer(this);
dlgFile.SetStringFilter("My File Format (*.mff) and *.mff and My File Format File (*.mff)");
return dlgFile.DoPromptFileName(fileName,nIDSTitle,lFlags,bOpenFileDialog, pTemplate);
}
Step 3:
You need to override your Apps CMyAppApp::OnFileOpen() function, this can be done easily through the class wizard. Enter the following code for OnFileOpen():

void CMyAppApp::OnFileOpen()
{
CString newName;
if (!DoPromptFileName(newName, AFX_IDS_OPENFILE,
OFN_HIDEREADONLY and OFN_FILEMUSTEXIST, TRUE, NULL))
return; // open cancelled

OpenDocumentFile(newName);
}

Step 4:
Now, you need to override a windows function in your document class. This will give you the ability to save using the new dialog. So in CMyAppDocument header class, override the DoSave() virtual function.

virtual BOOL DoSave(LPCTSTR lpszPathName, BOOL bReplace=TRUE );
And the Implementation of the function in you Documents Implementation file.

BOOL CMyAppDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
CKSFileDialog dlgFile(FALSE);
dlgFile.SetDocumentPointer(this);
dlgFile.SetAppPointer(AfxGetApp());
return dlgFile.DoSave(lpszPathName,bReplace);
}

You're done.

Now when you try to open or save a document the in Windows 2000 file dialog should pop up. See if you can make the dialog pop up in the center of your client window instead of the top left the first time it's called. I haven't been able to do this as of yet. if I try to hook into the messaging system of CFileDialog to override WM_INITDIALOG, Windows 2000 thinks that it has to show the old style dialog.

If you want the new file dialog to pop up generically meaning not through the standard windows Document/View Open,Save, Save As messaging system, just use the following code: (this is also shown in the demo project). You don't have to go through the above code, just use it like a regular CFileDialog.

For saving:
const char szFilters[]="Some Kind of Files (*.fn2) and *.fn2 and All Files (*.*) and *.* and and ";
CKSFileDialog dlg (FALSE, "fn2", NULL,OFN_OVERWRITEPROMPT and OFN_HIDEREADONLY, szFilters);
if (dlg.DoModal()==IDOK)
{
//some file writing code here
}

For reading:
const char szFilters[]="Some Kind of Files (*.fn2) and *.fn2 and All Files (*.*) and *.* and and ";
CKSFileDialog dlg (FALSE, "fn2", NULL,OFN_FILEMUSTEXIST and OFN_HIDEREADONLY, szFilters);
if (dlg.DoModal()==IDOK)
{
//some file reading code here
}

Sandy 2000-04-13
  • 打赏
  • 举报
回复
有什么api?
YuHao 2000-04-13
  • 打赏
  • 举报
回复
因为对话框资源好象是静态定义在commdlg LIB中的.建议用API函数试一下

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧