【VC开源代码栏目提醒】:网学会员--在 VC开源代码编辑为广大网友搜集整理了:TLFRAME.CPP绩等信息,祝愿广大网友取得需要的信息,参考学习。
// TLFrame.cpp : implementation file
//
#include "stdafx.h"
#include "TLView.h"
#include "TLFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ID_EDIT_FIELD 333
#define ID_TREE_LIST_HEADER 337
#define ID_TREE_LIST_CTRL 373
#define ID_TREE_LIST_SCROLLBAR 377
/////////////////////////////////////////////////////////////////////////////
// CTLFrame
CTLFrame::CTLFrame()
{
m_RTL = FALSE;
}
CTLFrame::~CTLFrame()
{
}
BEGIN_MESSAGE_MAP(CTLFrame, CWnd)
//{{AFX_MSG_MAP(CTLFrame)
ON_WM_HSCROLL()
ON_WM_CONTEXTMENU()
ON_WM_SIZE()
ON_WM_MOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTLFrame message handlers
LONG FAR PASCAL CTLFrame::DummyWndProc(HWND h, UINT u, WPARAM w, LPARAM l)
{
return ::DefWindowProc(h, u, w, l);
}
void CTLFrame::RegisterClass()
{
WNDCLASS wc;
memset(&wc, 0, sizeof(wc));
wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_GLOBALCLASS;
wc.lpfnWndProc = DummyWndProc;
wc.hInstance = AfxGetInstanceHandle();
wc.hCursor = 0;
wc.lpszClassName = "LANTIVTREELISTCTRL";
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
if (!::RegisterClass(&wc))
{
ASSERT(FALSE);
}
}
BOOL CTLFrame::SubclassDlgItem(UINT nID, CWnd* parent)
{
if (!CWnd::SubclassDlgItem(nID, parent)) return FALSE;
Initialize();
return TRUE;
}
void CTLFrame::Initialize()
{
// creates all the objects in frame -
// header, tree, horizontal scroll bar
CRect m_wndRect;
GetWindowRect(&m_wndRect);
CRect m_headerRect;
// create the header
{
m_headerRect.left = m_headerRect.top = -1;
m_headerRect.right = m_wndRect.Width();
m_tree.m_wndHeader.Create(WS_CHILD | WS_VISIBLE | HDS_BUTTONS | HDS_HORZ, m_headerRect, this, ID_TREE_LIST_HEADER);
}
CSize textSize;
// set header's pos, dimensions and image list
{
LOGFONT logfont;
CFont *pFont = GetParent()->GetFont();
pFont->GetLogFont( &logfont );
m_tree.m_headerFont.CreateFontIndirect( &logfont );
m_tree.m_wndHeader.SetFont(&m_tree.m_headerFont);
CDC *pDC = m_tree.m_wndHeader.GetDC();
pDC->SelectObject(&m_tree.m_headerFont);
textSize = pDC->GetTextExtent("A");
m_tree.m_wndHeader.SetWindowPos(&wndTop, -1, -1, m_headerRect.Width(), textSize.cy+4, SWP_SHOWWINDOW);
m_tree.m_cImageList.Create(IDB_HEADER, 16, 10, 0);
m_tree.m_wndHeader.SetImageList(&m_tree.m_cImageList);
}
CRect m_treeRect;
// create the tree itself
{
GetWindowRect(&m_wndRect);
m_treeRect.left=0;
m_treeRect.top = textSize.cy+4;
m_treeRect.right = m_headerRect.Width()-5;
m_treeRect.bottom = m_wndRect.Height()-GetSystemMetrics(SM_CYHSCROLL)-4;
m_tree.Create(WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS, m_treeRect, this, ID_TREE_LIST_CTRL);
}
// finally, create the horizontal scroll bar
{
CRect m_scrollRect;
m_scrollRect.left=0;
m_scrollRect.top = m_treeRect.bottom;
m_scrollRect.right = m_treeRect.Width()-GetSystemMetrics(SM_CXVSCROLL);
m_scrollRect.bottom = m_wndRect.bottom;
m_horScrollBar.Create(WS_CHILD | WS_VISIBLE | WS_DISABLED | SBS_HORZ | SBS_TOPALIGN, m_scrollRect, this, ID_TREE_LIST_SCROLLBAR);
}
SortTree(0, TRUE, m_tree.GetRootItem());
}
BOOL CTLFrame::VerticalScrollVisible()
{
int sMin, sMax;
m_tree.GetScrollRange(SB_VERT, &sMin, &sMax);
return sMax!=0;
}
BOOL CTLFrame::HorizontalScrollVisible()
{
int sMin, sMax;
m_horScrollBar.GetScrollRange(&sMin, &sMax);
return sMax!=0;
}
int CTLFrame::StretchWidth(int m_nWidth, int m_nMeasure)
{
return ((m_nWidth/m_nMeasure)+1)*m_nMeasure;
}
void CTLFrame::ResetScrollBar()
{
// resetting the horizontal scroll bar
int m_nTotalWidth=0, m_nPageWidth;
CRect m_treeRect;
m_tree.GetClientRect(&m_treeRect);
CRect m_wndRect;
GetClientRect(&m_wndRect);
CRect m_headerRect;
m_tree.m_wndHeader.GetClientRect(&m_headerRect);
CRect m_barRect;
m_horScrollBar.GetClientRect(m_barRect);
m_nPageWidth = m_treeRect.Width();
m_nTotalWidth = m_tree.GetColumnsWidth();
if(m_nTotalWidth > m_nPageWidth)
{
// show the scroll bar and adju