首 页
┆
源码下载
┆
IT学院
┆
字体下载
┆
模板下载
┆
源码发布
┆
广告合作
┆
网站地图
┆
虚拟主机
┆
中文域名
►
设为首页
►
加入收藏
►
联系我们
源码下载
>>
ASP源码
|
PHP源码
|
ASP.net源码
|
JSP源码
|
CGI源码
|
VC/C++源码
|
VB源码
|
Delphi源码
|
Flash源码
文章学院
>>
网络编程
|
网页设计
|
图形图象
|
数据库
|
服务器
|
网络媒体
|
网络安全
|
操作系统
|
办公软件
|
软件开发
|
黑客知识
字体下载
>>
精制字体
|
非英字体
|
艺术字体
|
著名字体
|
哥特式
|
简单字体
|
手写体
|
节假日
|
图案字体
|
精度像素
|
中文字体
模板下载
>>
企业门户
|
数码网络
|
休闲娱乐
|
影视音乐
|
旅游名胜
|
文化艺术
|
电子商务
|
个性展示
|
登陆导航
|
Flash模板
源码搜索
文章搜索
字体搜索
模板搜索
►►
您当前的位置:
源码园
→
IT学院
→
软件开发
→
VC编程
→ 文章内容
再谈 Windows 2000 “打开”文件对话框
作者:佚名 来源:网上收集 发布时间:2007-3-27 10:18:50
/////////// CFileDialogEx: 封装 Windows-2000 风格的"打开"对话框.// class CFileDialogEx : public CFileDialog { DECLARE_DYNAMIC(CFileDialogEx)public: CFileDialogEx(BOOL bOpenFileDialog, // TRUE 为"打开", // FALSE 为 "另存为" LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL); // 重载 virtual int DoModal();protected: OPENFILENAMEEX m_ofnEx; // 新的 OPENFILENAME Windows 2000 版本 virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); // 处理不同通知消息的虚拟函数 virtual BOOL OnFileNameOK(); virtual void OnInitDone(); virtual void OnFileNameChange(); virtual void OnFolderChange(); virtual void OnTypeChange(); DECLARE_MESSAGE_MAP() //{{AFX_MSG(CFileDialogEx) //}}AFX_MSG};/////////////////////////////////////////////////////////////// FileDialogEx.cpp // #include "stdafx.h"#include #include "FileDialogEx.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifstatic BOOL IsWin2000();///////////////////////////////////////////////////////////////////////////// CFileDialogExIMPLEMENT_DYNAMIC(CFileDialogEx, CFileDialog)CFileDialogEx::CFileDialogEx(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName, DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) : CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd){}BEGIN_MESSAGE_MAP(CFileDialogEx, CFileDialog) //{{AFX_MSG_MAP(CFileDialogEx) //}}AFX_MSG_MAPEND_MESSAGE_MAP()BOOL IsWin2000() { OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; // 尝试调用 GetVersionEx 函数,使用 OSVERSIONINFOEX 结构, // 它被Windows 2000支持. // // 如果调用失败, 尝试使用 OSVERSIONINFO 结构. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) { // 如果 OSVERSIONINFOEX 不行, 就用 OSVERSIONINFO. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return FALSE; } switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: if ( osvi.dwMajorVersion >= 5 ) return TRUE; break; } return FALSE; }int CFileDialogEx::DoModal(){ ASSERT_VALID(this); ASSERT(m_ofn.Flags & OFN_ENABLEHOOK); ASSERT(m_ofn.lpfnHook != NULL); // 仍然是个用户钩 // 文件缓冲初始化 ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile)); DWORD nOffset = lstrlen(m_ofn.lpstrFile)+1; ASSERT(nOffset <= m_ofn.nMaxFile); memset(m_ofn.lpstrFile+nOffset, 0, (m_ofn.nMaxFile-nOffset)*sizeof(TCHAR)); // WINBUG: 这是一种"打开/保存"对话框的特殊情况, // 在它disable主窗口之前是需要处理的. // HWND hWndFocus = ::GetFocus(); BOOL bEnableParent = FALSE; m_ofn.hwndOwner = PreModal(); AfxUnhookWindowCreate(); if (m_ofn.hwndOwner != NULL && ::IsWindowEnabled(m_ofn.hwndOwner)) { bEnableParent = TRUE; ::EnableWindow(m_ofn.hwndOwner, FALSE); } _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); ASSERT(pThreadState->m_pAlternateWndInit == NULL); if (m_ofn.Flags & OFN_EXPLORER) pThreadState->m_pAlternateWndInit = this; else AfxHookWindowCreate(this); memset(&m_ofnEx, 0, sizeof(m_ofnEx)); memcpy(&m_ofnEx, &m_ofn, sizeof(m_ofn)); if (IsWin2000()) m_ofnEx.lStructSize = sizeof(m_ofnEx); int nResult; if (m_bOpenFileDialog) nResult = ::GetOpenFileName((OPENFILENAME*)&m_ofnEx); else nResult = ::GetSaveFileName((OPENFILENAME*)&m_ofnEx); memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn)); m_ofn.lStructSize = sizeof(m_ofn); if (nResult) ASSERT(pThreadState->m_pAlternateWndInit == NULL); pThreadState->m_pAlternateWndInit = NULL; // WINBUG: "打开/保存"对话框的特殊情况的第二部分. if (bEnableParent) ::EnableWindow(m_ofnEx.hwndOwner, TRUE); if (::IsWindow(hWndFocus)) ::SetFocus(hWndFocus); PostModal(); return nResult ? nResult : IDCANCEL;}BOOL CFileDialogEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult){ memcpy(&m_ofn, &m_ofnEx, sizeof(m_ofn)); m_ofn.lStructSize = sizeof(m_ofn); return CFileDialog::OnNotify( wParam, lParam, pResult);}////////////////////////////////////////////////////////////////////// 下列函数只是用来说明他们获得了调用,实际上,类库(MFC)内部的对话框// 过程是被挂钩的;如果你愿意的话,可以删除他们.//BOOL CFileDialogEx::OnFileNameOK(){ TRACE(_T("CFileDialogEx::OnFileNameOK\n")); return CFileDialog::OnFileNameOK();}void CFileDialogEx::OnInitDone(){ TRACE(_T("CFileDialogEx::OnInitDone\n")); CFileDialog::OnInitDone();}void CFileDialogEx::OnFileNameChange(){ TRACE(_T("CFileDialogEx::OnFileNameChange\n")); CFileDialog::OnFileNameChange();}void CFileDialogEx::OnFolderChange(){ TRACE(_T("CFileDialogEx::OnFolderChange\n")); CFileDialog::OnFolderChange();}void CFileDialogEx::OnTyp
上一页
[1]
[2]
[3]
下一页
[] [
返回上一页
] [
打 印
]
上一篇文章:
VC6中使用CHtmlView在对话框控制中显示HTML文件
下一篇文章:
Windows2000新型Open对话框的使用
相关文章:
[图文]
再谈 Windows 2000 “打开”文件对话框
[组图]
Windows 文件对话框使用技巧集锦
关于本站
-
网站帮助
-
广告合作
-
下载声明
-
友情连接
-
网站地图
-
源码发布
Copyright © 2003-2009
Ymyasp
.Com
. All Rights Reserved .
备案序号:粤ICP备07029071号