Home > Software engineering >  What's the ListCtrlEx like drawing in the list item?
What's the ListCtrlEx like drawing in the list item?

Time:10-06

Trouble you ask next, in a recent ListCtrlEx (work demand, must use this class), should derive from ListCtrl, who can give me an example, tell me how to use ListCtrlEx one row in the list to determine a column in the bitmap ICONS or draw a picture? http://www.cnblogs.com/dlbrant/archive/2009/02/17/1392597.html is the online source code, I put the source code ListCtrlExDemoDlg. OnInitialDialog made a change in the CPP, and add the function InsertPic, specific content you can check the following code, compile environment is vs2010, but always couldn't draw the image, and is my code has a problem? I don't know how to return a responsibility? Please help me have a look at, thank you

 
BOOL CListCtrlExDemoDlg: : OnInitDialog ()
{
CDialog: : OnInitDialog ();

//Add "About... "Menu item to system menu.

//IDM_ABOUTBOX must be in the system command range.
ASSERT ((IDM_ABOUTBOX & amp; 0==IDM_ABOUTBOX xfff0));
ASSERT (IDM_ABOUTBOX & lt; 0 xf000);

CMenu * pSysMenu=GetSystemMenu (FALSE);
If (pSysMenu!=NULL)
{
Cstrings strAboutMenu;
StrAboutMenu. LoadString (IDS_ABOUTBOX);
if (! StrAboutMenu. IsEmpty ())
{
PSysMenu - & gt; The AppendMenu (MF_SEPARATOR);
PSysMenu - & gt; AppendMenu (MF_STRING IDM_ABOUTBOX, strAboutMenu);
}
}

//Set the icon for this dialog. The framework does this automatically
//when the application 's main window is not a dialog
SetIcon (m_hIcon, TRUE);//Set the big icon
SetIcon (m_hIcon, FALSE);//Set the small icon

M_list. ModifyStyle (0, LVS_SINGLESEL | LVS_REPORT | LVS_SHOWSELALWAYS);
M_list. SetExtendedStyle (m_list. GetExtendedStyle () | LVS_EX_FULLROWSELECT);

InsertPic ();

return TRUE;//return TRUE unless you set the focus to a control
}

Void CListCtrlExDemoDlg: : InsertPic ()
{
M_list. ModifyStyle (0, LVS_SINGLESEL | LVS_REPORT | LVS_SHOWSELALWAYS);
M_list. SetExtendedStyle (m_list GetExtendedStyle ());

DWORD dwStyle;
DwStyle=m_list. GetExtendedStyle ();
DwStyle=dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES;
M_list. SetExtendedStyle (dwStyle);

AddImages ();

//to the listview control InsertColumn insert 3 column data
CRect mRect;
M_list. GetWindowRect (& amp; MRect);//access controls rectangle
Int length=mRect. Width ();

/*
M_list. InsertColumn (0, _T (" portrait "), LVCFMT_CENTER, length/4, 1);
M_list. InsertColumn (1, _T (" username "), LVCFMT_CENTER, length/4, 1);
M_list. InsertColumn (2, _T (" QQ motto "), LVCFMT_CENTER, length/2, 1);
//*/

//*
M_list. InsertColumn (0, L "avatars", length/4, ListCtrlEx: : Normal, LVCFMT_CENTER, ListCtrlEx: : SortByString, 1);
M_list. InsertColumn (1, L "user name", length/8, ListCtrlEx: : Normal, LVCFMT_CENTER, ListCtrlEx: : SortByString, 1);
M_list. InsertColumn (2, "QQ motto" L, length/8, ListCtrlEx: : Normal, LVCFMT_CENTER, ListCtrlEx: : SortByString, 1);

//*/
Int nRow;

For (int LSN=0; Lsn<20; Lsn++)
{
Cstrings CSN=_T (" ");
CSN. The Format (_T (" % d "), LSN + 1);

LVITEM LVITEM={0};
LvItem. Mask=LVIF_IMAGE | LVIF_TEXT | LVIF_STATE;//text, pictures, state
LvItem. IItem=LSN;//line number (third row)
LvItem. IImage=2;//picture index number (the third picture IDB_BITMAP3)
LvItem. ISubItem=0;//child column number
NRow=m_list. InsertItem (& amp; LvItem);
M_list. SetItemText (nRow, 1, CSN);
M_list. SetItemText (nRow, 2, _T (" Eastmount production "));
}
return;

}

CodePudding user response:

Did you add imageList ListCtrl

CodePudding user response:

Uh huh, add the image list, I forgot to write another function

CodePudding user response:

Uh huh, add the image list, I forgot to write another function, writing in the following, don't know writing right
 
Void CListCtrlExDemoDlg: : AddImages ()
{
//load the 64 * 64 pixels 24 true color images (ILC_COLOR24)
M_imList. Create (14, 14, ILC_COLOR24, 10, 20);//create a CImageList object image sequence
CBitmap * pBmp=NULL;
PBmp=new CBitmap ();
PBmp - & gt; LoadBitmap (IDB_BITMAP1);//load the bitmap IDB_BITMAP1

M_imList. Add (pBmp, RGB (0, 0));
The delete pBmp;
//
PBmp=new CBitmap ();
PBmp - & gt; LoadBitmap (IDB_BITMAP2);

M_imList. Add (pBmp, RGB (0, 0));
The delete pBmp;
//
PBmp=new CBitmap ();
PBmp - & gt; LoadBitmap (IDB_BITMAP3);

M_imList. Add (pBmp, RGB (0, 0));
The delete pBmp;

//set the CImageList image list LVSIL_SMALL CListCtrl controls associated with the small icon list
M_list. SetImageList (& amp; M_imList LVSIL_SMALL);

}

CodePudding user response:

I'll rearrange the code, convenient ace to help me have a look at:

Trouble you ask next, in a recent ListCtrlEx (work demand, must use this class), should derive from ListCtrl, who can give me an example, tell me how to use ListCtrlEx one row in the list to determine a column in the bitmap ICONS or draw a picture? http://www.cnblogs.com/dlbrant/archive/2009/02/17/1392597.html is the online source code, I put the source code ListCtrlExDemoDlg. OnInitialDialog made a change in the CPP, and add the function InsertPic, specific content you can check the following code, compile environment is vs2010, but always couldn't draw the image, and is my code has a problem? I don't know how to return a responsibility? Please help me have a look at, thank you

Declared global variables:
 ListCtrlEx: : CListCtrlEx m_list; 
The CImageList m_imList;

BOOL CListCtrlExDemoDlg: : OnInitDialog ()
{
CDialog: : OnInitDialog ();

//Add "About... "Menu item to system menu.

//IDM_ABOUTBOX must be in the system command range.
ASSERT ((IDM_ABOUTBOX & amp; 0==IDM_ABOUTBOX xfff0));
ASSERT (IDM_ABOUTBOX & lt; 0 xf000);

CMenu * pSysMenu=GetSystemMenu (FALSE);
If (pSysMenu!=NULL)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related