CheckTree.rar

  • foot1313
    了解作者
  • Visual C++
    开发工具
  • 1.8MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2017-01-04 10:58
    上传日期
windows 32控件CheckBox Tree编程例子,需要的下载看看
CheckTree.rar
  • CheckTree
  • src
  • Debug
  • CheckTree.pch
    5.3MB
  • vc60.pdb
    356KB
  • vc60.idb
    209KB
  • StdAfx.obj
    105.8KB
  • CheckTreeDlg.obj
    22.4KB
  • CheckTree.ilk
    184.9KB
  • CheckTree.exe
    108.1KB
  • CheckTree.pdb
    265KB
  • CheckTree.obj
    14KB
  • CheckTree.res
    3.3KB
  • res
  • CheckTree.ico
    1.1KB
  • CheckTree.rc2
    401B
  • stateimg.bmp
    630B
  • treeimg.bmp
    374B
  • CheckTree.h
    1.2KB
  • CheckTree.dsw
    541B
  • CheckTreeDlg.h
    1.6KB
  • CheckTree.rc
    4.9KB
  • CheckTree.opt
    47.5KB
  • CheckTreeDlg.cpp
    4KB
  • CheckTree.ncb
    41KB
  • CheckTree.cpp
    1.3KB
  • CheckTree.dsp
    4.2KB
  • Resource.h
    685B
  • StdAfx.cpp
    211B
  • CheckTree.plg
    1.7KB
  • StdAfx.h
    1002B
  • CheckTree.aps
    21.1KB
  • checktree.html
    10KB
内容介绍
// CheckTreeDlg.cpp : implementation file // #include "stdafx.h" #include "CheckTree.h" #include "CheckTreeDlg.h" #include <windowsx.h> #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCheckTreeDlg dialog CCheckTreeDlg::CCheckTreeDlg(CWnd* pParent /*=NULL*/) : CDialog(CCheckTreeDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCheckTreeDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCheckTreeDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCheckTreeDlg) DDX_Control(pDX, IDC_TREE1, m_tree); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCheckTreeDlg, CDialog) //{{AFX_MSG_MAP(CCheckTreeDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_NOTIFY(NM_CLICK, IDC_TREE1, OnClickTree1) ON_NOTIFY(TVN_KEYDOWN, IDC_TREE1, OnKeydownTree1) //}}AFX_MSG_MAP ON_MESSAGE(UWM_TV_CHECKBOX, OnTvCheckbox) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCheckTreeDlg message handlers BOOL CCheckTreeDlg::OnInitDialog() { CDialog::OnInitDialog(); SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // ================ // ----- Init Image Lists, and attach to tree ctrl m_ilNormal.Create(IDB_TREEIMG, 16, 0, RGB(255,255,255)); m_ilState.Create(IDB_STATEIMG, 16, 0, RGB(255,255,255)); m_tree.SetImageList(&m_ilNormal, TVSIL_NORMAL); // attach the normal image list m_tree.SetImageList(&m_ilState, TVSIL_STATE); // attach the state image list // ----- Insert items into tree m_tree.InsertItem("One", 0, 1); m_tree.InsertItem("Two", 0, 1); return TRUE; } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CCheckTreeDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } HCURSOR CCheckTreeDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CCheckTreeDlg::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult) { DWORD dw = GetMessagePos(); CPoint p(GET_X_LPARAM(dw), GET_Y_LPARAM(dw)); m_tree.ScreenToClient(&p); UINT htFlags = 0; HTREEITEM it = m_tree.HitTest(p, &htFlags); if (it != NULL && (htFlags & TVHT_ONITEMSTATEICON)) { // the check box was hit. // we post a message, and evaluate the new state in the Message Handler fopr the 'user defined' WM_APP message PostMessage(UWM_TV_CHECKBOX, pNMHDR->idFrom, (LPARAM) it); } *pResult = 0; } void CCheckTreeDlg::OnKeydownTree1(NMHDR* pNMHDR, LRESULT* pResult) { TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR; if (pTVKeyDown->wVKey==VK_SPACE) { HTREEITEM it = m_tree.GetSelectedItem(); PostMessage(UWM_TV_CHECKBOX, pNMHDR->idFrom, (LPARAM) it); } *pResult = 0; } LRESULT CCheckTreeDlg::OnTvCheckbox(WPARAM wp, LPARAM lp) { // CTreeCtrl & tree = GetDlgItem(wp); -- if we have multiple trees HTREEITEM hitem = (HTREEITEM) lp; CString s = m_tree.GetItemText(hitem); int checked = (m_tree.GetItemState(hitem, TVIS_STATEIMAGEMASK) >> 12) - 1; if (checked==0) s += " unchecked"; else if (checked==1) s+= " checked"; else if (checked==2) s+= " dunno"; else s+= " ???"; SetDlgItemText(IDC_INFO, s); return 0; }
评论
    相关推荐