⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgfiledialog.cpp

📁 一个完整的编辑器的代码(很值得参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	m_wndRecentList.InsertColumn (1, _T("Folder"));

	CRecentFileList* pMRUFiles = 
		((CBCGApp*) AfxGetApp ())->m_pRecentFileList;

	if (pMRUFiles != NULL)
	{
		TCHAR szCurDir [_MAX_PATH];
		::GetCurrentDirectory (_MAX_PATH, szCurDir);

		int nCurDir = lstrlen (szCurDir);
		ASSERT (nCurDir >= 0);

		szCurDir [nCurDir] = _T('\\');
		szCurDir [++ nCurDir] = _T('\0');

		//---------------
		// Add MRU files:
		//---------------
		int iNumOfFiles = 0;	// Actual added to menu
		for (int i = 0; i < pMRUFiles->GetSize (); i ++)
		{
			CString strFile = (*pMRUFiles) [i];
			if (!strFile.IsEmpty ())
			{
				CString strPath;
				CString strName;
				int iImage = -1;

				int iIndex = strFile.ReverseFind (_T('\\'));
				if (iIndex != -1)
				{
					strPath = strFile.Left (iIndex);
					strName = strFile.Mid (iIndex + 1);
				}
				else
				{
					strName = strFile;
				}

				SHFILEINFO  sfi;
				HIMAGELIST himlSmall = (HIMAGELIST) SHGetFileInfo (strFile,
                                       0,
                                       &sfi, 
                                       sizeof(SHFILEINFO), 
                                       SHGFI_SYSICONINDEX | SHGFI_SMALLICON);

				if (himlSmall != NULL)
				{
					CImageList* pImages = CImageList::FromHandle (himlSmall);
					ASSERT (pImages != NULL);

					iImage = m_ImagesRecent.Add (pImages->ExtractIcon (sfi.iIcon));
				}

				iIndex = m_wndRecentList.InsertItem (iNumOfFiles ++, strName, iImage);
				m_wndRecentList.SetItemText (iIndex, 1, strPath);

				int iPathWidth = m_wndRecentList.GetStringWidth (strPath) + 20;
				if (iPathWidth > m_wndRecentList.GetColumnWidth (1))
				{
					m_wndRecentList.SetColumnWidth (1, iPathWidth);
				}
			}
		}
	}

	//---------------------
	// Create tabs control:
	//---------------------
	CRect rectTabs;
	pFD->GetClientRect (rectTabs);
	rectTabs.DeflateRect (4, 4);
	rectTabs.top += iLogoAreaHeight;

	m_wndTab.Create (WS_TABSTOP | WS_CHILD | WS_VISIBLE, rectTabs, pFD, iTabCtrlId);
	m_wndTab.SetFont (GetFont ());
	m_wndTab.SetOwner (this);

	TC_ITEM tc;
	tc.mask = TCIF_TEXT;

	int iPage = 0;
	if (m_bNewPage)
	{
		tc.pszText = _T("New");
		m_wndTab.InsertItem (iPage ++, &tc);
	}

	tc.pszText = _T("Existing");
	m_wndTab.InsertItem (iPage ++, &tc);
	
	tc.pszText = _T("Recent");
	m_wndTab.InsertItem (iPage ++, &tc);

	pFD->CenterWindow ();
	pFD->SetWindowText (m_strCaption);

	//------------------
	// Set dilaog icons:
	//------------------
	if (m_hIconSmall != NULL)
	{
		pFD->SetIcon (m_hIconSmall, FALSE);
	}

	if (m_hIconBig != NULL)
	{
		pFD->SetIcon (m_hIconBig, TRUE);
	}

	//--------------------------
	// Setup parent window proc:
	//--------------------------
	m_wndProc = (WNDPROC)SetWindowLong(pFD->m_hWnd, GWL_WNDPROC, 
		(long)CBCGFileDialog::WindowProcNew);
}
//******************************************************************************************
void CBCGFileDialog::OnTabSelchange() 
{
	int nPage = m_wndTab.GetCurSel();
	if (!m_bNewPage)
	{
		nPage ++;
	}

	switch (nPage)
	{
	case 0:
		m_nPage = BCGFileNew;
		break;

	case 1:
		m_nPage = BCGFileOpen;
		break;

	case 2:
		m_nPage = BCGFileRecent;
		break;

	default:
		ASSERT (FALSE);
	}

	//---------------------
	// Show/hide file list:
	//---------------------
	CWnd* pWnd = GetParent();
	ASSERT (pWnd != NULL);

	CWnd* pWndChild = pWnd->GetWindow (GW_CHILD);
	while (pWndChild != NULL)
	{
		TCHAR szClass [256];
		::GetClassName (pWndChild->GetSafeHwnd (), szClass, 255);

		CString strClass = szClass;

		if (strClass.CompareNoCase (_T("SHELLDLL_DefView")) == 0)
		{
			pWndChild->ShowWindow (m_nPage == BCGFileOpen ? SW_SHOW : SW_HIDE);
			break;
		}

		pWndChild = pWndChild->GetNextWindow ();
	}

	//--------------------------
	// Show/hide other controls:
	//--------------------------
	for (POSITION pos = m_lstFDControls.GetHeadPosition (); pos != NULL;)
	{
		pWnd = CWnd::FromHandle (m_lstFDControls.GetNext (pos));
		ASSERT (pWnd != NULL);

		pWnd->ShowWindow (m_nPage == BCGFileOpen ? SW_SHOW : SW_HIDE);
	}

	m_wndNewList.ShowWindow (m_nPage == BCGFileNew ? SW_SHOW : SW_HIDE);
	m_wndRecentList.ShowWindow (m_nPage == BCGFileRecent ? SW_SHOW : SW_HIDE);
}
//***************************************************************************************
void CBCGFileDialog::OnItemDblClick ()
{
	ASSERT (m_nPage != BCGFileOpen);

	CListCtrl& list = (m_nPage == BCGFileRecent) ? m_wndRecentList : m_wndNewList;
	int iSelIndex = list.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);

	if (iSelIndex == -1)
	{
		return;
	}

	if (m_nPage == BCGFileRecent)
	{
		CString strPath = list.GetItemText (iSelIndex, 1);
		CString strName = list.GetItemText (iSelIndex, 0);

		if (strPath.IsEmpty ())
		{
			m_strRecentFilePath = strName;
		}
		else
		{
			m_strRecentFilePath = strPath;
			m_strRecentFilePath += _T('\\');
			m_strRecentFilePath += strName;
		}
	}
	else
	{
		ASSERT (m_nPage == BCGFileNew);
		m_iNewItemIndex = iSelIndex;
	}
	
	CDialog* pWnd = (CDialog*) GetParent();
	ASSERT (pWnd != NULL);

	pWnd->EndDialog (IDOK);
}
//****************************************************************************************
void CBCGFileDialog::CollectControls ()
{
	if (!m_lstFDControls.IsEmpty ())
	{
		return;
	}

	CWnd* pWnd = GetParent();
	ASSERT (pWnd != NULL);

	CRect rectList (0, 0, 0, 0);

	CWnd* pWndChild = pWnd->GetWindow (GW_CHILD);
	while (pWndChild != NULL)
	{
		BOOL bIsFileList = FALSE;

		UINT uiID = pWndChild->GetDlgCtrlID();
		TCHAR szClass [256];
		::GetClassName (pWndChild->GetSafeHwnd (), szClass, 255);

		CString strClass = szClass;

		CRect rectCtl;
		pWndChild->GetClientRect (rectCtl);
		pWndChild->MapWindowPoints (pWnd, rectCtl);

		if (strClass.CompareNoCase (_T("SHELLDLL_DefView")) == 0)
		{
			rectList.left = rectCtl.left;
			rectList.right = rectCtl.right;
			rectList.bottom = rectCtl.bottom - 10;

			bIsFileList = TRUE;
		}

		if (strClass.CompareNoCase (_T("ToolbarWindow32")) == 0)
		{
			rectList.top = rectCtl.top;
		}

		if ((((strClass.CompareNoCase (_T("BUTTON")) != 0) ||
			uiID != IDOK &&
			uiID != IDCANCEL &&
			uiID != IDHELP) &&
			pWndChild->GetStyle () & WS_VISIBLE) &&
			uiID != iTabCtrlId &&
			uiID != iNewListCtrlId &&
			uiID != iRecentListCtrlId &&
			!bIsFileList)
		{
			m_lstFDControls.AddTail (pWndChild->GetSafeHwnd ());
		}

		pWndChild = pWndChild->GetNextWindow ();
	}

	m_wndNewList.MoveWindow (rectList);
	m_wndRecentList.MoveWindow (rectList);

	OnTabSelchange();
}
//**************************************************************************************
void CBCGFileDialog::AddNewItem (LPCTSTR lpszName, int iIconIndex)
{
	m_lstNewItems.AddTail (new CNewItemInfo (lpszName, iIconIndex));
}
//**************************************************************************************
void CBCGFileDialog::SetDlgIcon (HICON hIconBig, HICON hIconSmall/* = NULL*/)
{
	m_hIconBig = hIconBig;
	m_hIconSmall = (hIconSmall == NULL) ? m_hIconBig : hIconSmall;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -