树形控件的节点图标显示问题(实现每个子节点的图标不一样) 5
程序如下:一运行就停止了,哪里有问题?(一部分代码,超出限度了)CKFCApptheApp;HICONhIcon[10];//图标句柄数组HTREEITEMhItem;/...
程序如下:一运行就停止了,哪里有问题?(一部分代码,超出限度了)
CKFCApp theApp;
HICON hIcon[10]; // 图标句柄数组
HTREEITEM hItem; // 树的根节点的句柄
HTREEITEM hSubItem; // 可表示任一分类节点的句柄
// 加载三个图标,并将它们的句柄保存到数组
hIcon[0] = theApp.LoadIcon(IDI_ZC_ICON);
hIcon[1] = theApp.LoadIcon(IDI_DRC_ICON);
hIcon[2] = theApp.LoadIcon(IDI_HB_ICON);
hIcon[3] = theApp.LoadIcon(IDI_JRJ_ICON);
hIcon[4] = theApp.LoadIcon(IDI_ZLF_ICON);
hIcon[5] = theApp.LoadIcon(IDI_SZYWJ_ICON);
hIcon[6] = theApp.LoadIcon(IDI_BFXS_ICON);
hIcon[7] = theApp.LoadIcon(IDI_PC_ICON);
hIcon[8] = theApp.LoadIcon(IDI_TP_ICON);
hIcon[9] = theApp.LoadIcon(IDI_YL_ICON);
// 创建图像序列CImageList对象
m_imagelist.Create(50, 50, ILC_COLOR32, 10, 10);
// 将三个图标添加到图像序列
for (int i=0; i<10; i++)
{
m_imagelist.Add(hIcon[i]);
}
hItem = m_tree.InsertItem(_T("主餐(9:15-10:44)"), 0, 0);
// 在根节点下插入子节点
hSubItem = m_tree.InsertItem(_T("超值多人餐"), 1, 1, hItem, TVI_LAST);
// 为“超值多人餐”节点添加附加的编号数据,在鼠标划过该节点时显示
m_tree.SetItemData(hSubItem, 1);
// 在根节点下插入第2个子节点
hSubItem = m_tree.InsertItem(_T("美味汉堡"), 2, 2, hItem, TVI_LAST);
// 为“美味汉堡”节点添加附加的编号数据,在鼠标划过该节点时显示
m_tree.SetItemData(hSubItem, 2);
hSubItem = m_tree.InsertItem(_T("丰富配餐"), 7, 7, hItem, TVI_LAST);
m_tree.SetItemData(hSubItem, 7);
hSubItem = m_tree.InsertItem(_T("甜品/儿童餐"), 8, 8, hItem, TVI_LAST);
m_tree.SetItemData(hSubItem, 8);
hSubItem = m_tree.InsertItem(_T("缤纷饮料"), 9, 9, hItem, TVI_LAST);
m_tree.SetItemData(hSubItem, 9); 展开
CKFCApp theApp;
HICON hIcon[10]; // 图标句柄数组
HTREEITEM hItem; // 树的根节点的句柄
HTREEITEM hSubItem; // 可表示任一分类节点的句柄
// 加载三个图标,并将它们的句柄保存到数组
hIcon[0] = theApp.LoadIcon(IDI_ZC_ICON);
hIcon[1] = theApp.LoadIcon(IDI_DRC_ICON);
hIcon[2] = theApp.LoadIcon(IDI_HB_ICON);
hIcon[3] = theApp.LoadIcon(IDI_JRJ_ICON);
hIcon[4] = theApp.LoadIcon(IDI_ZLF_ICON);
hIcon[5] = theApp.LoadIcon(IDI_SZYWJ_ICON);
hIcon[6] = theApp.LoadIcon(IDI_BFXS_ICON);
hIcon[7] = theApp.LoadIcon(IDI_PC_ICON);
hIcon[8] = theApp.LoadIcon(IDI_TP_ICON);
hIcon[9] = theApp.LoadIcon(IDI_YL_ICON);
// 创建图像序列CImageList对象
m_imagelist.Create(50, 50, ILC_COLOR32, 10, 10);
// 将三个图标添加到图像序列
for (int i=0; i<10; i++)
{
m_imagelist.Add(hIcon[i]);
}
hItem = m_tree.InsertItem(_T("主餐(9:15-10:44)"), 0, 0);
// 在根节点下插入子节点
hSubItem = m_tree.InsertItem(_T("超值多人餐"), 1, 1, hItem, TVI_LAST);
// 为“超值多人餐”节点添加附加的编号数据,在鼠标划过该节点时显示
m_tree.SetItemData(hSubItem, 1);
// 在根节点下插入第2个子节点
hSubItem = m_tree.InsertItem(_T("美味汉堡"), 2, 2, hItem, TVI_LAST);
// 为“美味汉堡”节点添加附加的编号数据,在鼠标划过该节点时显示
m_tree.SetItemData(hSubItem, 2);
hSubItem = m_tree.InsertItem(_T("丰富配餐"), 7, 7, hItem, TVI_LAST);
m_tree.SetItemData(hSubItem, 7);
hSubItem = m_tree.InsertItem(_T("甜品/儿童餐"), 8, 8, hItem, TVI_LAST);
m_tree.SetItemData(hSubItem, 8);
hSubItem = m_tree.InsertItem(_T("缤纷饮料"), 9, 9, hItem, TVI_LAST);
m_tree.SetItemData(hSubItem, 9); 展开
1个回答
展开全部
您好,这样的:
// 117.h : main header file for the 117 application
//
#if !defined(AFX_117_H__31B967EE_CE22_4E77_9133_3CC355B747B8__INCLUDED_)
#define AFX_117_H__31B967EE_CE22_4E77_9133_3CC355B747B8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CMy117App:
// See 117.cpp for the implementation of this class
//
class CMy117App : public CWinApp
{
public:
CMy117App();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMy117App)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CMy117App)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_117_H__31B967EE_CE22_4E77_9133_3CC355B747B8__INCLUDED_)
// 117.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "117.h"
#include "117Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy117App
BEGIN_MESSAGE_MAP(CMy117App, CWinApp)
//{{AFX_MSG_MAP(CMy117App)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy117App construction
CMy117App::CMy117App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMy117App object
CMy117App theApp;
/////////////////////////////////////////////////////////////////////////////
// CMy117App initialization
BOOL CMy117App::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CMy117Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
// 117.h : main header file for the 117 application
//
#if !defined(AFX_117_H__31B967EE_CE22_4E77_9133_3CC355B747B8__INCLUDED_)
#define AFX_117_H__31B967EE_CE22_4E77_9133_3CC355B747B8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CMy117App:
// See 117.cpp for the implementation of this class
//
class CMy117App : public CWinApp
{
public:
CMy117App();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMy117App)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CMy117App)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_117_H__31B967EE_CE22_4E77_9133_3CC355B747B8__INCLUDED_)
// 117.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "117.h"
#include "117Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy117App
BEGIN_MESSAGE_MAP(CMy117App, CWinApp)
//{{AFX_MSG_MAP(CMy117App)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy117App construction
CMy117App::CMy117App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMy117App object
CMy117App theApp;
/////////////////////////////////////////////////////////////////////////////
// CMy117App initialization
BOOL CMy117App::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CMy117Dlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
追问
看不明白?这是什么?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询