为CTreeCtrl类添加一个图象列表类CImageList对象m_ImageList 这句话什么意思啊?
正在学习VC++,基本没有基础,这句话看不懂,前面的CTreeCtrl类是我刚刚新建的,那么后面这个怎么添加呢?...
正在学习VC++,基本没有基础,这句话看不懂,前面的CTreeCtrl类是我刚刚新建的,那么后面这个怎么添加呢?
展开
1个回答
展开全部
1.初始化CImageList、设置图像列表
成员函数:
CImageList::Create
CTreeCtrl::SetImageList
示例:
BOOL CMfc1Dlg::OnInitDialog(){
//...
m_iml.Create(16,16,ILC_COLOR16 | ILC_MASK,20,20);
m_Tree.SetImageList(&m_iml,TVSIL_NORMAL);
}
2.向树视图中添加窗口列表
成员函数:
CImageList::Replace
CTreeCtrl::InsertItem
示例:
int i=0;
HWND hDesktop=::GetDesktopWindow();
HWND hWnd=::GetWindow(hDesktop,GW_CHILD);
TCHAR sTitle[MAX_PATH];
HICON hIcon;
BOOL bShow=TRUE;
LONG idx;
while ( i<1000 && hWnd!=NULL ) {
bShow=TRUE;
if (!::GetWindowTextLength(hWnd)) bShow=FALSE;
if (!::IsWindowEnabled(hWnd)) bShow=FALSE;
if (!::IsWindowVisible(hWnd)) bShow=FALSE;
if (!::GetWindow(hWnd,GW_CHILD)) bShow=FALSE;
if (bShow) {
::GetWindowText(hWnd,sTitle,MAX_PATH);
hIcon=(HICON)::SendMessage(hWnd,WM_GETICON,ICON_SMALL,NULL);
if ((LONG)hIcon==NULL)
hIcon=(HICON)::SendMessage(hWnd,WM_GETICON,ICON_BIG,NULL);
if ((LONG)hIcon==NULL)
hIcon=m_hIcon;
idx=m_iml.Replace(-1,hIcon);
m_Tree.InsertItem(sTitle,idx,idx);
}
hWnd=::GetWindow(hWnd,GW_HWNDNEXT);
++i;
}
源代码mfc_study_2.zip(38KB)
成员函数:
CImageList::Create
CTreeCtrl::SetImageList
示例:
BOOL CMfc1Dlg::OnInitDialog(){
//...
m_iml.Create(16,16,ILC_COLOR16 | ILC_MASK,20,20);
m_Tree.SetImageList(&m_iml,TVSIL_NORMAL);
}
2.向树视图中添加窗口列表
成员函数:
CImageList::Replace
CTreeCtrl::InsertItem
示例:
int i=0;
HWND hDesktop=::GetDesktopWindow();
HWND hWnd=::GetWindow(hDesktop,GW_CHILD);
TCHAR sTitle[MAX_PATH];
HICON hIcon;
BOOL bShow=TRUE;
LONG idx;
while ( i<1000 && hWnd!=NULL ) {
bShow=TRUE;
if (!::GetWindowTextLength(hWnd)) bShow=FALSE;
if (!::IsWindowEnabled(hWnd)) bShow=FALSE;
if (!::IsWindowVisible(hWnd)) bShow=FALSE;
if (!::GetWindow(hWnd,GW_CHILD)) bShow=FALSE;
if (bShow) {
::GetWindowText(hWnd,sTitle,MAX_PATH);
hIcon=(HICON)::SendMessage(hWnd,WM_GETICON,ICON_SMALL,NULL);
if ((LONG)hIcon==NULL)
hIcon=(HICON)::SendMessage(hWnd,WM_GETICON,ICON_BIG,NULL);
if ((LONG)hIcon==NULL)
hIcon=m_hIcon;
idx=m_iml.Replace(-1,hIcon);
m_Tree.InsertItem(sTitle,idx,idx);
}
hWnd=::GetWindow(hWnd,GW_HWNDNEXT);
++i;
}
源代码mfc_study_2.zip(38KB)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询