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

📄 bcgppropertysheet.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
							rectNavigator.left, rectNavigator.top,
							rectNavigator.Width (), 
							rectNavigator.Height (),
							SWP_NOACTIVATE);

		SetActivePage (GetActivePage ());

		int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP	};

		int nTotalButtonsWidth = 0;

		for (int iStep = 0; iStep < 2; iStep++)
		{
			for (int i = 0; i < sizeof (ids) / sizeof (ids [0]); i++)
			{
				CWnd* pButton = GetDlgItem (ids[i]);

				if (pButton != NULL)
				{
					if (ids [i] == IDHELP && (m_psh.dwFlags & PSH_HASHELP) == 0)
					{
						continue;
					}

					if (ids [i] == ID_APPLY_NOW && (m_psh.dwFlags & PSH_NOAPPLYNOW))
					{
						continue;
					}

					CRect rectButton;
					pButton->GetWindowRect (rectButton);
					ScreenToClient (rectButton);

					if (iStep == 0)
					{
						// Align buttons at the bottom
						pButton->SetWindowPos (&wndTop, rectButton.left, 
							rectClient.bottom - rectButton.Height () - nVertMargin, 
							-1, -1, SWP_NOSIZE | SWP_NOACTIVATE);

						nTotalButtonsWidth = rectButton.right;
					}
					else
					{
						// Right align the buttons
						pButton->SetWindowPos (&wndTop, 
							rectButton.left + rectClient.right - nTotalButtonsWidth - nHorzMargin,
							rectButton.top,
							-1, -1, SWP_NOSIZE | SWP_NOACTIVATE);
					}
				}
			}
		}
	}

	return bResult;
}
//***************************************************************************************
CWnd* CBCGPPropertySheet::InitNavigationControl ()
{
	ASSERT_VALID (this);

	CTabCtrl* pTab = GetTabControl ();
	ASSERT_VALID (pTab);

	if (m_look == PropSheetLook_OutlookBar)
	{
		DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_ALIGN_LEFT;
		DWORD dwBCGStyle = 0;
		m_wndOutlookBar.Create (_T(""), this, CRect (0, 0, 100, 100), 
			AFX_IDW_TOOLBAR, dwStyle, dwBCGStyle);

		CBCGPBaseTabWnd* pWndTab = m_wndOutlookBar.GetUnderlinedWindow ();

		ASSERT_VALID (pWndTab);

		pWndTab->HideSingleTab ();

		m_wndPane1.Create (&m_wndOutlookBar, dwDefaultToolbarStyle, 1);
		m_wndPane1.m_pParent = this;
		m_wndOutlookBar.AddTab (&m_wndPane1);

		m_wndPane1.EnableTextLabels (TRUE);
		m_wndPane1.SetOwner (this);

		ASSERT (m_Icons.GetSafeHandle () != NULL);
		ASSERT (m_Icons.GetImageCount () == pTab->GetItemCount ());

		for (int nTab = 0; nTab < pTab->GetItemCount (); nTab++)
		{
			InternalAddPage (nTab);
		}

		return &m_wndOutlookBar;
	}

	if (m_look == PropSheetLook_Tree)
	{
		CRect rectDummy (0, 0, 0, 0);
		const DWORD dwTreeStyle =	WS_CHILD | WS_VISIBLE;
		m_wndTree.Create (dwTreeStyle, rectDummy, this, (UINT) idTree);

		m_wndTree.ModifyStyleEx (0, WS_EX_CLIENTEDGE);

		if (m_Icons.GetSafeHandle () != NULL)
		{
			m_wndTree.SetImageList (&m_Icons, TVSIL_NORMAL);
			m_wndTree.SetImageList (&m_Icons, TVSIL_STATE);
		}

		//----------------
		// Add categories:
		//----------------
		for (POSITION pos = m_lstTreeCategories.GetHeadPosition (); pos != NULL;)
		{
			AddCategoryToTree (m_lstTreeCategories.GetNext (pos));
		}

		//-----------
		// Add pages:
		//-----------
		for (int nTab = 0; nTab < pTab->GetItemCount (); nTab++)
		{
			InternalAddPage (nTab);
		}

		return &m_wndTree;
	}

	if (m_look == PropSheetLook_OneNoteTabs)
	{
		CRect rectDummy (0, 0, 0, 0);

		m_wndTab.Create (CBCGPTabWnd::STYLE_3D_ONENOTE, rectDummy, this, 
			(UINT) idTab, CBCGPTabWnd::LOCATION_TOP, FALSE);

		m_wndTab.m_pParent = this;
		m_wndTab.EnableTabSwap (FALSE);

		if (m_Icons.GetSafeHandle () != NULL)
		{
			ASSERT (m_Icons.GetImageCount () == pTab->GetItemCount ());
			m_wndTab.SetImageList (m_Icons.GetSafeHandle ());
		}

		for (int nTab = 0; nTab < pTab->GetItemCount (); nTab++)
		{
			InternalAddPage (nTab);
		}

		return &m_wndTab;
	}

	return NULL;
}
//****************************************************************************************
void CBCGPPropertySheet::SetIconsList (HIMAGELIST hIcons)
{
	ASSERT_VALID(this);
	ASSERT (hIcons != NULL);
	ASSERT (m_Icons.GetSafeHandle () == NULL);

	m_Icons.Create (CImageList::FromHandle (hIcons));
}
//******************************************************************************************
void CBCGPPropertySheet::AddCategoryToTree (CBCGPPropSheetCategory* pCategory)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pCategory);
	ASSERT (m_look == PropSheetLook_Tree);

	HTREEITEM hParent = NULL;
	if (pCategory->m_pParentCategory != NULL)
	{
		hParent = pCategory->m_pParentCategory->m_hTreeItem;
	}

	pCategory->m_hTreeItem = m_wndTree.InsertItem (pCategory->m_strName, 
		I_IMAGECALLBACK, I_IMAGECALLBACK, hParent);
	m_wndTree.SetItemData (pCategory->m_hTreeItem, (DWORD) pCategory);

	for (POSITION pos = pCategory->m_lstSubCategories.GetHeadPosition (); pos != NULL;)
	{
		AddCategoryToTree (pCategory->m_lstSubCategories.GetNext (pos));
	}
}
//***************************************************************************************
BOOL CBCGPPropertySheet::SetIconsList (UINT uiImageListResID, int cx,
							  COLORREF clrTransparent)
{
	ASSERT_VALID(this);

	CBitmap bmp;
	if (!bmp.LoadBitmap (uiImageListResID))
	{
		TRACE(_T("Can't load bitmap: %x\n"), uiImageListResID);
		return FALSE;
	}

	CImageList icons;

	BITMAP bmpObj;
	bmp.GetBitmap (&bmpObj);

	UINT nFlags = (clrTransparent == (COLORREF) -1) ? 0 : ILC_MASK;

	switch (bmpObj.bmBitsPixel)
	{
	case 4:
	default:
		nFlags |= ILC_COLOR4;
		break;

	case 8:
		nFlags |= ILC_COLOR8;
		break;

	case 16:
		nFlags |= ILC_COLOR16;
		break;

	case 24:
		nFlags |= ILC_COLOR24;
		break;

	case 32:
		nFlags |= ILC_COLOR32;
		break;
	}

	icons.Create (cx, bmpObj.bmHeight, nFlags, 0, 0);
	icons.Add (&bmp, clrTransparent);

	SetIconsList (icons);
	return TRUE;
}
//***************************************************************************************
void CBCGPPropertySheet::OnActivatePage (CPropertyPage* pPage)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pPage);

	if (m_wndPane1.GetSafeHwnd () != NULL)
	{
		if (m_nActivePage >= 0)
		{
			m_wndPane1.SetButtonStyle (m_nActivePage, 0);
		}

		int nPage = GetPageIndex (pPage);
		ASSERT (nPage >= 0);

		m_nActivePage = nPage;

		PostMessage (UM_AFTERACTIVATEPAGE);
	}

	if (m_wndTree.GetSafeHwnd () != NULL)
	{
		CBCGPPropertyPage* pBCGPropPage = DYNAMIC_DOWNCAST (CBCGPPropertyPage, pPage);
		if (pBCGPropPage != NULL)
		{
			if (!m_bIsInSelectTree)
			{
				m_wndTree.SelectItem (pBCGPropPage->m_hTreeNode);
			}

			m_wndTree.EnsureVisible (pBCGPropPage->m_hTreeNode);
		}
	}

	if (m_wndTab.GetSafeHwnd () != NULL)
	{
		const int nTab = GetPageIndex (pPage);

		m_wndTab.SetActiveTab (nTab);
		m_wndTab.EnsureVisible (nTab);
	}
}
//****************************************************************************************
LRESULT CBCGPPropertySheet::OnAfterActivatePage(WPARAM,LPARAM)
{
	ASSERT_VALID (this);

	if (m_nActivePage >= 0)
	{
		if (m_wndPane1.GetSafeHwnd () != NULL)
		{
			m_wndPane1.SetButtonStyle (m_nActivePage, TBBS_CHECKED);
			m_wndPane1.EnsureVisible (m_nActivePage);
		}
	}

	return 0;
}
//************************************************************************************
void CBCGPPropertySheet::OnSelectTree(NMHDR* /*pNMHDR*/, LRESULT* pResult) 
{
	*pResult = 0;

	HTREEITEM hTreeItem = m_wndTree.GetSelectedItem ();
	if (hTreeItem == NULL)
	{
		return;
	}

	CBCGPPropSheetCategory* pNewCategory = NULL;
	CBCGPPropSheetCategory* pOldCategory = NULL;

	CBCGPPropertyPage* pCurrPage = DYNAMIC_DOWNCAST (CBCGPPropertyPage,
		GetActivePage ());
	if (pCurrPage != NULL)
	{
		ASSERT_VALID (pCurrPage);
		pOldCategory = pCurrPage->m_pCategory;
	}

	m_bIsInSelectTree = TRUE;

	CBCGPPropertyPage* pPage = DYNAMIC_DOWNCAST (CBCGPPropertyPage,
		(CObject*) m_wndTree.GetItemData (hTreeItem));

	if (pPage == pCurrPage)
	{
		m_bIsInSelectTree = FALSE;
		return;
	}

	if (pPage != NULL)
	{
		CBCGPPropertyPage* pPrevPage = DYNAMIC_DOWNCAST (CBCGPPropertyPage, GetActivePage ());

		ASSERT_VALID (pPage);
		if (!SetActivePage (pPage))
		{
		   m_wndTree.SendMessage (TVM_SELECTITEM, (WPARAM)TVGN_CARET,  (LPARAM)pCurrPage->m_hTreeNode);
		   m_bIsInSelectTree = FALSE;
		   return;
		}

		pNewCategory = pPage->m_pCategory;

		if (pPrevPage != NULL)
		{
			ASSERT_VALID (pPrevPage);

			CRect rectItem;
			m_wndTree.GetItemRect (pPrevPage->m_hTreeNode, rectItem, FALSE);
			m_wndTree.InvalidateRect (rectItem);
		}
	}
	else
	{
		CBCGPPropSheetCategory* pCategory = DYNAMIC_DOWNCAST (CBCGPPropSheetCategory,
			(CObject*) m_wndTree.GetItemData (hTreeItem));
		if (pCategory != NULL)
		{
			ASSERT_VALID (pCategory);

			while (!pCategory->m_lstSubCategories.IsEmpty ())
			{
				pCategory = pCategory->m_lstSubCategories.GetHead ();
				ASSERT_VALID (pCategory);
			}

			if (!pCategory->m_lstPages.IsEmpty ())
			{
				pPage = pCategory->m_lstPages.GetHead ();
				ASSERT_VALID (pPage);

				SetActivePage (pPage);

				CRect rectItem;
				m_wndTree.GetItemRect (pPage->m_hTreeNode, rectItem, FALSE);
				m_wndTree.InvalidateRect (rectItem);
			}

			pNewCategory = pCategory;
		}
	}

	if (pNewCategory != pOldCategory)
	{
		if (pOldCategory != NULL)
		{
			ASSERT_VALID (pOldCategory);
			HTREEITEM hItem = pOldCategory->m_hTreeItem;

			do
			{
				m_wndTree.Expand (hItem, TVE_COLLAPSE);
				hItem = m_wndTree.GetParentItem (hItem);
			}
			while (hItem != NULL);
		}

		if (pNewCategory != NULL)
		{
			ASSERT_VALID (pNewCategory);
			HTREEITEM hItem = pNewCategory->m_hTreeItem;

			do
			{
				m_wndTree.Expand (hItem, TVE_EXPAND);
				hItem = m_wndTree.GetParentItem (hItem);
			}
			while (hItem != NULL);
		}
	}

	m_bIsInSelectTree = FALSE;
}
//***************************************************************************************
void CBCGPPropertySheet::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
	LPNMTVDISPINFO lptvdi = (LPNMTVDISPINFO) pNMHDR;

	CBCGPPropertyPage* pPage = DYNAMIC_DOWNCAST (CBCGPPropertyPage,
		(CObject*) m_wndTree.GetItemData (lptvdi->item.hItem));
	if (pPage != NULL)
	{
		ASSERT_VALID (pPage);

		if (pPage == GetActivePage ())
		{
			lptvdi->item.iImage = pPage->m_nSelIconNum;
			lptvdi->item.iSelectedImage = pPage->m_nSelIconNum;
		}
		else
		{
			lptvdi->item.iImage = pPage->m_nIcon;
			lptvdi->item.iSelectedImage = pPage->m_nIcon;
		}
	}

	CBCGPPropSheetCategory* pCategory = DYNAMIC_DOWNCAST (CBCGPPropSheetCategory,
		(CObject*) m_wndTree.GetItemData (lptvdi->item.hItem));
	if (pCategory != NULL)
	{
		ASSERT_VALID (pCategory);

		if (lptvdi->item.state & TVIS_EXPANDED)
		{
			lptvdi->item.iImage = pCategory->m_nSelectedIcon;
			lptvdi->item.iSelectedImage = pCategory->m_nSelectedIcon;
		}
		else
		{
			lptvdi->item.iImage = pCategory->m_nIcon;
			lptvdi->item.iSelectedImage = pCategory->m_nIcon;
		}
	}

	*pResult = 0;
}
//********************************************************************************
CBCGPTabWnd& CBCGPPropertySheet::GetTab () const
{
	ASSERT_VALID (this);
	ASSERT (m_look == PropSheetLook_OneNoteTabs);

	return (CBCGPTabWnd&) m_wndTab;
}
//********************************************************************************
BOOL CBCGPPropertySheet::PreTranslateMessage(MSG* pMsg) 
{
	if (m_Impl.PreTranslateMessage (pMsg))
	{
		return TRUE;
	}

	return CPropertySheet::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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