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

📄 headerwnd.cpp

📁 VC源代码大全(精华版)
💻 CPP
字号:
// HeaderWnd.cpp : implementation file
//

#include "stdafx.h"
#include "Controls.h"
#include "HeaderWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHeaderWnd

CHeaderWnd::CHeaderWnd()
{
}

CHeaderWnd::~CHeaderWnd()
{
}


BEGIN_MESSAGE_MAP(CHeaderWnd, CWnd)
	//{{AFX_MSG_MAP(CHeaderWnd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CHeaderWnd message handlers

bool CHeaderWnd::Initialize()
{
	CRect rc;
	::GetWindowRect (this->m_hWnd, &rc);
//	ScreenToClient (&rc);
	CFont *font = GetParent()->GetFont();
	LOGFONT lf;
	font->GetLogFont (&lf);
	CRect rcHeader;
	rcHeader.top = 0;
	rcHeader.left = 2;
	rcHeader.bottom = 3 * lf.lfHeight / 2;
	if (rcHeader.bottom < 0)
		rcHeader.bottom *= -1;
	rcHeader.right = rc.right - rc.left - 2;
	m_Header.CreateEx (0, WC_HEADER, NULL,
			 WS_VISIBLE | WS_CHILD | HDS_HORZ,
			 rcHeader, this,
			 IDC_HEADER_LISTHEADER);
	m_Header.ShowWindow (SW_SHOWNORMAL);
	m_Header.SetFont (font);

	CRect rcList (rcHeader);
	rcList.top = rcList.bottom;
	rcList.bottom = rc.bottom - rc.top;
	m_List.Create (LBS_OWNERDRAWFIXED | WS_VSCROLL | WS_VISIBLE | LBS_NOINTEGRALHEIGHT | WS_CHILD, rcList, this, IDC_HEADER_LISTBOX);
	m_List.ShowWindow (SW_SHOWNORMAL);
	m_List.SetFont (font);

	m_imageOneTwoThree.Create (IDB_ONETWOTHREE, 16, 2, RGB(0x00, 0x80, 0x80));
	m_Header.SetImageList (&m_imageOneTwoThree);

	HDITEM hi;
	memset (&hi, '\0', sizeof (HDITEM));
	hi.mask = HDI_WIDTH | HDI_TEXT
			 | HDI_ORDER | HDI_LPARAM
			 | HDI_IMAGE | HDI_FORMAT;
	hi.iOrder = 0;
	hi.lParam = 0;
	hi.iImage = 0;
	hi.fmt = HDF_IMAGE | HDF_STRING;
	hi.cxy = rcHeader.right / 3;
	hi.pszText = "File";
	m_Header.InsertItem (0, &hi);
	hi.pszText = "Size";
	hi.iOrder = 1;
	hi.lParam = 1;
	hi.iImage = 1;
	m_Header.InsertItem (1, &hi);
	hi.cxy -= 2;
	hi.pszText = "Created";
	hi.iOrder = 2;
	hi.lParam = 2;
	hi.iImage = 2;
	m_Header.InsertItem (2, &hi);

	return (true);
}

BOOL CHeaderWnd::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
{
	if (wParam == IDC_HEADER_LISTHEADER)
	{
		NMHDR *pNMHDR = (NMHDR *) lParam;
		switch (pNMHDR->code)
		{
			case HDN_ENDDRAG:
			case HDN_ENDTRACK:
				m_List.Invalidate ();
				*pResult = 0;
				return (TRUE);
			default:
				break;
		}
	}
	return CWnd::OnNotify(wParam, lParam, pResult);
}

CHeaderCtrl * CHeaderWnd::GetHeaderCtrl()
{
	return (&m_Header);
}

//
//	HDS_HIDDEN appears to be a style engineered
//	for the list control. You can set the style and
//	the control will disappear, but removing the
//	style won't make the control reappear.
//
void CHeaderWnd::HideHeader(bool bHide)
{
	CRect rcHeader, rcList;
	m_List.GetWindowRect (&rcList);
	m_Header.GetWindowRect (&rcHeader);
	if (bHide)
	{
		m_Header.ShowWindow (SW_HIDE);
		rcList.right = rcList.right - rcList.left;
		rcList.bottom = rcList.bottom - rcList.top + rcHeader.bottom - rcHeader.top;
		rcList.left = rcList.top = 0;
		m_List.MoveWindow (rcList);
	}
	else
	{
		rcList.right = rcList.right - rcList.left;
		rcList.bottom = rcList.bottom - rcList.top;
		rcList.left = 0;
		rcList.top = rcHeader.bottom - rcHeader.top;
		m_List.MoveWindow (rcList);
		m_Header.ShowWindow (SW_SHOWNORMAL);
	}

}

void CHeaderWnd::AddListItem(WIN32_FIND_DATA &fd)
{
	m_List.AddListItem (fd);
	return;
}

int CHeaderWnd::SetSelection(int nSel)
{
	int nCur = m_List.GetCurSel ();
	m_List.SetCurSel (nSel);
	return (nCur);
}

⌨️ 快捷键说明

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