VC++ adds different icons to the tab control

win10, vc6; create a new dialog box project;

Add tab control; add member variable m_tab;

Insert 3 icons in the resource;

Add the member variable m_TabImageList to the dialog box header file; this control is to store the picture list;

Class wizard, enter the OnInitDialog() member function of the dialog box as shown in the figure below;

Add code to the OnInitDialog() function; add it after // TODO:; other codes are generated by VC;

Added code

    m_TabImageList.Create(32, 32, TRUE, 3, 3);
    
	HICON hIcon1;
	HICON hIcon2;
	HICON hIcon3;
 
	hIcon1 = AfxGetApp()->LoadIcon(IDI_ICON1);
	m_TabImageList.Add(hIcon1);
 
	hIcon2 = AfxGetApp()->LoadIcon(IDI_ICON2);
	m_TabImageList.Add(hIcon2);
 
	hIcon3 = AfxGetApp()->LoadIcon(IDI_ICON3);
	m_TabImageList.Add(hIcon3);
 
	m_tab.SetImageList(&m_TabImageList);
 
	m_tab.InsertItem(0,_T("功能1"),0);
	m_tab.InsertItem(1,_T("功能2"),1);
	m_tab.InsertItem(2,_T("功能3"),2);

Run as follows; 

The code is added to the CTabdemoDlg::OnInitDialog() function, //TODO: and before return TRUE;

 

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/113814943