📄 bcgpfiledialog.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a part of the BCGControlBar Library
// Copyright (C) 1998-2000 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions
// of the accompanying license agreement.
//*******************************************************************************
// BCGFileDialog.cpp : implementation file
//
#include "stdafx.h"
#include "bcgprores.h"
#include "BCGPLocalResource.h"
#include "BCGPFileDialog.h"
#include "BCGGlobals.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CNewItemInfo : public CObject
{
friend class CBCGPFileDialog;
CNewItemInfo (LPCTSTR lpszName, int iIconIndex)
{
m_strName = lpszName;
m_iIconIndex = iIconIndex;
}
CString m_strName;
int m_iIconIndex;
};
/////////////////////////////////////////////////////////////////////////////
// CBCGPFileDialog
const int iTabCtrlId = 200;
const int iNewListCtrlId = 201;
const int iRecentListCtrlId = 202;
WNDPROC CBCGPFileDialog::m_wndProc;
IMPLEMENT_DYNAMIC(CBCGPFileDialog, CFileDialog)
CBCGPFileDialog::CBCGPFileDialog (LPCTSTR lpszCaption, BOOL bNewPage, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog (TRUE /*bOpenFileDialog*/, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd),
m_pImagesNew (NULL),
m_bNewPage (bNewPage),
m_strCaption (lpszCaption),
m_hIconBig (NULL),
m_hIconSmall (NULL),
m_iLogoAreaHeight (0),
m_iExtraWidth (0),
m_iExtraHeight (0)
{
m_iNewItemIndex = -1;
m_pBmpLogo = NULL;
CDocManager* pDocManager = AfxGetApp ()->m_pDocManager;
if (pDocManager != NULL && lpszFilter == NULL)
{
static CString strFilter;
static CString strDefault;
BOOL bFirst = TRUE;
for (POSITION pos = pDocManager->GetFirstDocTemplatePosition (); pos != NULL;)
{
CDocTemplate* pTemplate = pDocManager->GetNextDocTemplate (pos);
ASSERT_VALID (pTemplate);
CString strFilterExt, strFilterName;
if (pTemplate->GetDocString (strFilterExt, CDocTemplate::filterExt) &&
!strFilterExt.IsEmpty() &&
pTemplate->GetDocString(strFilterName, CDocTemplate::filterName) &&
!strFilterName.IsEmpty())
{
// a file based document template - add to filter list
ASSERT(strFilterExt[0] == '.');
if (bFirst)
{
strDefault = ((LPCTSTR)strFilterExt) + 1; // skip the '.'
m_ofn.lpstrDefExt = strDefault;
m_ofn.nFilterIndex = m_ofn.nMaxCustFilter + 1; // 1 based number
}
// add to filter
strFilter += strFilterName;
ASSERT(!strFilter.IsEmpty()); // must have a file type name
strFilter += (TCHAR)'\0'; // next string please
strFilter += (TCHAR)'*';
strFilter += strFilterExt;
strFilter += (TCHAR)'\0'; // next string please
m_ofn.nMaxCustFilter++;
}
bFirst = FALSE;
}
CString allFilter;
VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
strFilter += allFilter;
strFilter += (TCHAR)'\0'; // next string please
strFilter += _T("*.*");
strFilter += (TCHAR)'\0'; // last string
m_ofn.nMaxCustFilter++;
m_ofn.lpstrFilter = strFilter;
}
}
//***************************************************************************************
CBCGPFileDialog::~CBCGPFileDialog ()
{
while (!m_lstNewItems.IsEmpty ())
{
delete m_lstNewItems.RemoveHead ();
}
}
//***************************************************************************************
static CBCGPFileDialog* GetBCGFileDlg (HWND hwdParent)
{
CFileDialog* pDlg = (CFileDialog*)CWnd::FromHandle (hwdParent);
ASSERT (pDlg != NULL);
CBCGPFileDialog* pFD = (CBCGPFileDialog*) pDlg->GetDlgItem(0);
ASSERT (pFD != NULL);
return pFD;
}
//***************************************************************************************
LRESULT CALLBACK CBCGPFileDialog::WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_NOTIFY:
{
CBCGPFileDialog* pFD = GetBCGFileDlg (hwnd);
LPNMHDR pHdr = (LPNMHDR) lParam;
ASSERT (pHdr != NULL);
if (wParam == iTabCtrlId && pHdr->code == TCN_SELCHANGE)
{
pFD->OnTabSelchange();
}
else if ((wParam == iNewListCtrlId || wParam == iRecentListCtrlId)
&& pHdr->code == NM_DBLCLK)
{
pFD->OnItemDblClick();
}
}
break;
case WM_COMMAND:
{
if ((int) LOWORD(wParam) == IDOK)
{
CBCGPFileDialog* pFD = GetBCGFileDlg (hwnd);
if (pFD->GetPage () != CBCGPFileDialog::BCGFileOpen)
{
pFD->OnItemDblClick();
return 0;
}
}
}
break;
case WM_PAINT:
{
CBCGPFileDialog* pFD = GetBCGFileDlg (hwnd);
pFD->CollectControls ();
if (pFD->m_pBmpLogo != NULL)
{
ASSERT_VALID (pFD->m_pBmpLogo);
CFileDialog* pDlg = (CFileDialog*)CWnd::FromHandle (hwnd);
ASSERT (pDlg != NULL);
CPaintDC dc (pDlg); // device context for painting
dc.DrawState (pFD->m_rectLogo.TopLeft (),
pFD->m_rectLogo.Size (), pFD->m_pBmpLogo,
DSS_NORMAL);
CRect rectFrame = pFD->m_rectLogo;
rectFrame.InflateRect (1, 1);
dc.Draw3dRect (rectFrame, globalData.clrBtnShadow, globalData.clrBtnLight);
}
}
break;
case WM_SIZE:
{
LRESULT lRes = CallWindowProc(CBCGPFileDialog::m_wndProc, hwnd, message, wParam, lParam);
CBCGPFileDialog* pFD = GetBCGFileDlg (hwnd);
ASSERT_VALID (pFD);
CWnd* pFDParent = pFD->GetParent();
ASSERT (pFDParent != NULL);
CRect rectTabs;
pFDParent->GetClientRect (rectTabs);
rectTabs.DeflateRect (4, 4);
rectTabs.top += pFD->m_iLogoAreaHeight;
pFD->m_wndTab.SetWindowPos (NULL, -1, -1,
rectTabs.Width (), rectTabs.Height (),
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
pFD->m_lstFDControls.RemoveAll ();
pFD->CollectControls ();
return lRes;
}
}
return CallWindowProc(CBCGPFileDialog::m_wndProc, hwnd, message, wParam, lParam);
}
BEGIN_MESSAGE_MAP(CBCGPFileDialog, CFileDialog)
//{{AFX_MSG_MAP(CBCGPFileDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------
// My "classic " trick - how I can access to protected
// member m_pRecentFileList?
//-----------------------------------------------------
class CBCGApp : public CWinApp
{
friend class CBCGPFileDialog;
};
void CBCGPFileDialog::OnInitDone()
{
const int iBorderWidth = 20;
const int iBorderHeight = 40;
CWnd* pFD = GetParent();
ASSERT (pFD != NULL);
CRect rectClient;
pFD->GetClientRect (rectClient);
int nNewDlgWidth = rectClient.Width () + iBorderWidth * 2 + m_iExtraWidth;
if (m_pBmpLogo != NULL)
{
BITMAP bmp;
m_pBmpLogo->GetBitmap (&bmp);
m_rectLogo = CRect (CPoint ((nNewDlgWidth - bmp.bmWidth) / 2, 8),
CSize (bmp.bmWidth, bmp.bmHeight));
m_iLogoAreaHeight = bmp.bmHeight + 20;
}
//---------------------------
// Adjust parent window size:
//---------------------------
pFD->ModifyStyle (WS_THICKFRAME, WS_DLGFRAME | WS_BORDER);
pFD->ModifyStyleEx (WS_EX_WINDOWEDGE, 0);
pFD->SetWindowPos (NULL, -1, -1, nNewDlgWidth,
rectClient.Height () + iBorderHeight * 2 + m_iLogoAreaHeight + m_iExtraHeight,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
//-------------------
// Move all controls:
//-------------------
CWnd* pWndChild = pFD->GetWindow (GW_CHILD);
while (pWndChild != NULL)
{
CRect rectCtl;
pWndChild->GetClientRect (rectCtl);
pWndChild->MapWindowPoints (pFD, rectCtl);
pWndChild->SetWindowPos (NULL,
rectCtl.left + iBorderWidth,
rectCtl.top + iBorderHeight + m_iLogoAreaHeight,
rectCtl.Width (), rectCtl.Height (),
SWP_NOZORDER | SWP_NOACTIVATE);
pWndChild = pWndChild->GetNextWindow ();
}
//------------------------------------------
// Create new and recent file list controls:
//------------------------------------------
CRect rectList (0, 0, 0, 0);
m_wndNewList.Create (WS_BORDER | WS_TABSTOP | WS_CHILD | LVS_ICON | LVS_SINGLESEL,
rectList, pFD, iNewListCtrlId);
m_wndNewList.ModifyStyleEx (0, WS_EX_CLIENTEDGE);
if (m_pImagesNew != NULL)
{
m_wndNewList.SetImageList (m_pImagesNew, LVSIL_NORMAL);
}
int i = 0;
for (POSITION pos = m_lstNewItems.GetHeadPosition (); pos != NULL; i ++)
{
CNewItemInfo* pInfo = (CNewItemInfo*) m_lstNewItems.GetNext (pos);
ASSERT_VALID (pInfo);
m_wndNewList.InsertItem (i, pInfo->m_strName, pInfo->m_iIconIndex);
}
m_wndRecentList.Create (WS_TABSTOP | WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT,
rectList, pFD, iRecentListCtrlId);
m_wndRecentList.ModifyStyleEx (0, WS_EX_CLIENTEDGE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -