📄 bxfiledialog.cpp
字号:
//////////////////////////////////////////////////////////////////////////
// BXFileDialog.cpp : implementation file
//
// Windows 2000 / Office 2000 style file dialog.
//
// This WILL work on Win 95 / 98 / NT 4 / NT 5 (2000) / WinME
//
// Original code by Norm Almond []
// David Wulff [dwulff@battleaxesoftware.com]
//
// Update History:
// 07 Sep 2000 - David Wulff, Opps, I lost the previous update history.
// 08 Sep 2000 - David Wulff, Lots of changes, most significant is the
// .. addition of an optional preview panel, allowing you
// .. to preview bitmap images before opening/saving.
// 14 Oct 2000 - Joel Bernard, Provided a better CenterWindow function.
// David Wulff, Fixed memory leaks, added support for
// .. previewing non-bitmap images. (code by Wes Rogers)
// Other misc. changes.
// Anatoly Danekin, Shortcut path resolution.
// 13 Dec 2000 - David Wulff, Added Visual Studio .NET look
// 24 Mar 2001 - David Wulff, miscellaneous drawing updates
// Tak^Shoran, working sizing support for Win 98/2000
// Identified very bad flickering problem
// 31 Mar 2001 - David Wulff, Fixed resizing so it will work for dialogs
// .. with preview panels. Tidied up all of the code (it
// .. was a big mess) and added standard function headers.
// .. Removed compile-time only modification of sizing
// .. support and VS.NET style
//
//////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BXFileDialog_Priv.h"
#include "BXFileDialog.h"
#include "BXFileDialog_Res.h"
#include <dlgs.h>
//#define _USE_HTMLHELP // uncomment to have context help for the sidebar.
#define CONTROL_GAP 5 // the default 'gap' between controls
#ifdef _USE_HTMLHELP
#include <htmlhelp.h>
#pragma comment ( lib, "htmlhelp.lib" )
#pragma message (" NOTE: HTMLHelp support is included.")
#endif
#define ID_SHOW_PREVIEW 34225
BOOL BXFileDialog::m_bClear = FALSE;
TCHAR BXFileDialog::m_szFile[] = {"\0"};
BOOL bDotNetUI = FALSE;
/////////////////////////////////////////////////////////////////////////////
// BXFileDialog
IMPLEMENT_DYNAMIC(BXFileDialog, CFileDialog)
BEGIN_MESSAGE_MAP(BXFileDialog, CFileDialog)
//{{AFX_MSG_MAP(BXFileDialog)
ON_WM_SIZE()
ON_WM_HELPINFO()
ON_WM_MEASUREITEM()
ON_BN_CLICKED(IDC_CHECK_PREVIEW, OnClickedPreview)
ON_BN_CLICKED(ID_SHOW_PREVIEW, OnShowPreview)
ON_WM_PAINT()
//}}AFX_MSG_MAP
ON_COMMAND(ID_BTN_HISTORY, OnHistoryClicked)
ON_COMMAND(ID_BTN_PERSONAL, OnPersonalClicked)
ON_COMMAND(ID_BTN_DESKTOP, OnDesktopClicked)
ON_COMMAND(ID_BTN_FAVORITES, OnFavoritesClicked)
ON_COMMAND(ID_BTN_WEBFOLDERS, OnWebFoldersClicked)
ON_COMMAND_RANGE(ID_START, ID_END, OnMyOk)
ON_COMMAND(IDOK, OnOk)
END_MESSAGE_MAP()
/************************************************************************/
/* BXFileDialog */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff, Norm Almond */
/* Description: Class constructor */
/* Revisions: */
/************************************************************************/
BXFileDialog::BXFileDialog(BOOL bOpenFileDialog, BOOL bPreview, BOOL bSizing,
LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter,
CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags,
lpszFilter, pParentWnd)
{
m_IsOpen = bOpenFileDialog;
m_bShowPreview = m_bPreview = bPreview;
m_bChanged = FALSE;
m_bFirst = TRUE;
//m_ofn.hInstance = AfxGetInstanceHandle();
m_ofn.hInstance = GetBXFileDialogDll()->hModule;
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_WIN2K_FILEDIALOG);
m_ofn.Flags = dwFlags | OFN_EXPLORER | OFN_ENABLETEMPLATE |
OFN_ENABLEHOOK | OFN_HIDEREADONLY |
(bSizing ? OFN_ENABLESIZING : 0);
}
/************************************************************************/
/* ~BXFileDialog */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff, Norm Almond */
/* Description: Class destructor */
/* Revisions: */
/************************************************************************/
BXFileDialog::~BXFileDialog()
{
}
/************************************************************************/
/* OnInitDialog */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff, Norm Almond */
/* Description: WM_INITDIALOG handler */
/* Revisions: */
/************************************************************************/
BOOL BXFileDialog::OnInitDialog()
{
CFileDialog::OnInitDialog();
m_IL.Create(IDB_ICONS, 32, 1, RGB(255, 0, 255));
// Center this dialog on the main window
CWnd* pMainWnd = AfxGetMainWnd();
CenterWindowOnOwner(pMainWnd);
CWnd* pWndOutLookBar = GetDlgItem(IDC_OUTLOOK_BAR_PLACEHOLDER);
CRect rcOLBClient;
pWndOutLookBar->GetClientRect(rcOLBClient);
m_SBWidth = rcOLBClient.Width();
return TRUE;
}
/************************************************************************/
/* OnNotify */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff, Norm Almond */
/* Description: WM_NOTIFY handler */
/* Revisions: */
/************************************************************************/
BOOL BXFileDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
OFNOTIFY* pNotify = (OFNOTIFY*)lParam;
switch(pNotify->hdr.code)
{
case CDN_INITDONE:
// Set initial selection
SetActiveButton(&m_btnPersonal);
m_edtFile.SubclassDlgItem(edt1,GetParent());
return TRUE;
case CDN_SELCHANGE:
OnFileNameChange();
return TRUE;
case CDN_FOLDERCHANGE:
OnFolderChange();
return TRUE;
}
return FALSE;
}
/************************************************************************/
/* OnFileNameChange */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the file name is changed or a new file is */
/* .. selected. */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnFileNameChange()
{
CString strFilePath = (LPCSTR)GetPathName();
SHFILEINFO shfi;
if (!GetFileName().IsEmpty())
{
if (SHGetFileInfo((LPCSTR)strFilePath, 0, &shfi, sizeof(shfi),
SHGFI_DISPLAYNAME | SHGFI_TYPENAME) &&
!lstrcmp(shfi.szTypeName, "Shortcut"))
{
ResolveShortcut(strFilePath);
}
if(!m_bChanged && m_bPreview)
m_strPreviewPath = strFilePath;
InvalidateRect(PreviewRect);
}
m_bChanged = FALSE;
}
/************************************************************************/
/* OnFolderChange */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the folder is changed */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnFolderChange()
{
m_bChanged = TRUE;
}
/************************************************************************/
/* OnClickedPreview */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the '&Preview' checkbox is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnClickedPreview()
{
m_bPreview = checkBox.GetCheck() == 1 ? TRUE : FALSE;
}
/************************************************************************/
/* OnPaint */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: WM_PAINT handler */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnPaint()
{
CPaintDC dc(this);
if (m_bShowPreview)
{
CRect rect(PreviewRect.left + 1, PreviewRect.top + 1,
PreviewRect.right - 1, PreviewRect.bottom - 1);
dc.Draw3dRect(&PreviewRect,::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHILIGHT));
if(m_bPreview)
DrawImage(&dc, m_strPreviewPath, PreviewRect.CenterPoint(),
GetParent()->m_hWnd, rect);
}
if (!bDotNetUI)
{
CRect rcWnd;
CWnd* pWndOutLookBar = GetDlgItem(IDC_OUTLOOK_BAR_PLACEHOLDER);
pWndOutLookBar->GetWindowRect(&rcWnd);
ScreenToClient(&rcWnd);
rcWnd.top += (m_btnHeight * 5);
dc.Draw3dRect(&rcWnd, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHILIGHT));
dc.FillRect(&rcWnd, &CBrush(::GetSysColor(COLOR_APPWORKSPACE)));
}
}
/************************************************************************/
/* OnHistoryClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnHistoryClicked()
{
SetSpecialDirectory(CSIDL_RECENT);
SetActiveButton(&m_btnHistory);
}
/************************************************************************/
/* OnPersonalClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnPersonalClicked()
{
SetSpecialDirectory(CSIDL_PERSONAL);
SetActiveButton(&m_btnPersonal);
}
/************************************************************************/
/* OnDesktopClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnDesktopClicked()
{
SetSpecialDirectory(CSIDL_DESKTOP);
SetActiveButton(&m_btnDeskTop);
}
/************************************************************************/
/* OnFavoritesClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnFavoritesClicked()
{
SetSpecialDirectory(CSIDL_FAVORITES);
SetActiveButton(&m_btnFavourites);
}
/************************************************************************/
/* OnWebFoldersClicked */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Called when the specified side bar button is clicked */
/* Revisions: */
/************************************************************************/
void BXFileDialog::OnWebFoldersClicked()
{
SetSpecialDirectory(CSIDL_NETHOOD);
SetActiveButton(&m_btnWebFolders);
}
/************************************************************************/
/* SetSpecialDirectory */
/* */
/* Created: 31:3:2001 */
/* Author: David Wulff */
/* Description: Navigates to a passed shell director based on the side */
/* .. bar button pressed. */
/* Revisions: */
/************************************************************************/
void BXFileDialog::SetSpecialDirectory(int nFolder)
{
LPITEMIDLIST lpIDList;
SHGetSpecialFolderLocation(0, nFolder, &lpIDList);
SHGetPathFromIDList(lpIDList, m_szFile);
CWnd* pWnd = GetParent()->GetDlgItem(edt1);
CListCtrl* pLCtrl = (CListCtrl*)GetParent()->GetDlgItem(lst1);
// Simulate a refersh to clear file name
// .. this can take a LONG time if the history folder is selected!
//
// If you find a better way of doing this, please let me know.
pLCtrl->PostMessage(WM_KEYDOWN,VK_F5,0x0020001);
pLCtrl->PostMessage(WM_KEYUP,VK_F5,0xC0020001);
// Add selection to edit box
pWnd->SetWindowText(m_szFile);
// Simulate a 'Return' key to make selection
m_bClear = TRUE;
pWnd->PostMessage(WM_KEYDOWN,VK_RETURN,0x0020001);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -