Sign in to follow this  

Adding checkboxes to a list view, checkbox image missing

This topic is 3846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I Created a list view and modified the style with LVS_EX_CHECKBOXES, and the checkbox is created, but there is no image where the checkbox should be, only a blank space. Here's part of the code:


CAPPRESULT CListViewCtrl::Create(HWND pHWndParentS_, int nWndID_, CWnd::SCWndConf* pConfDataS)
{

	CAPPRESULT sRes;

	if(CAPP_FAILED(sRes = CCtrl::Create(pHWndParentS_, nWndID_, pConfDataS)))
	{
	
		return sRes;

	}// end if

	WNDCLASSEX  WindowClassS;

	if(CWndMgr::GetInstance().InsertRegisteredClassName("CListViewCtrl", FALSE))
	{

		INITCOMMONCONTROLSEX InitCommCtrlS = {0};
		InitCommCtrlS.dwSize = sizeof(INITCOMMONCONTROLSEX);
		InitCommCtrlS.dwICC = ICC_TREEVIEW_CLASSES;
		//we need to initialize common controls
		InitCommonControlsEx(&InitCommCtrlS);
		
	}// end if

	DWORD ulStyle, ulExStyle;
	
	if(static_cast<CListViewCtrl::SCListViewCtrlConf*>(pConfDataS)->m_bEditLabel)
	{
	
		ulStyle = WS_TABSTOP | WS_CHILD | WS_VISIBLE | LVS_AUTOARRANGE | LVS_REPORT | LVS_OWNERDATA | LVS_EDITLABELS;

	}else
	{

		ulStyle = WS_TABSTOP | WS_CHILD | WS_VISIBLE | LVS_AUTOARRANGE | LVS_REPORT | LVS_OWNERDATA;
	
	}// end else

	HWND pHWndS;

	if(static_cast<CListViewCtrl::SCListViewCtrlConf*>(pConfDataS)->m_bNoBorder)
	{
	
		ulExStyle = NULL;

	}else
	{

		ulExStyle = WS_EX_CLIENTEDGE;
	
	}// end else

	if(CAPP_FAILED(sRes = this->CreateEx(ulExStyle, WC_LISTVIEW, "", ulStyle,
									    0,0,0,0, pHWndParentS_, (HMENU) (int) nWndID_, NULL, &pHWndS)))
	{
						
		return sRes;
			
	}// end if


	this->m_unIconID = static_cast<CListViewCtrl::SCListViewCtrlConf*>(pConfDataS)->m_unIconID;

	// we call OnCreate from here since we can't intercept WM_CREATE for system control classes
	if(CAPP_FAILED(sRes = (this->OnCreate(pHWndS, nWndID_))))
	{
			
		return sRes;

	}// end if

	return CAPP_ERR_NO_ERRORS;
	
}// end virtual CAPPRESULT CListViewCtrl::Create(HWND pHWndParentS_, int nWndID_, CWnd::SCWndConf* pConfDataS)




CAPPRESULT CListViewCtrl::SetExtendedStyleEx(DWORD ulExMask_, DWORD ulExStyle_)
{

	CAPPRESULT sRes;

	HWND pHWndS;

	if(CAPP_FAILED(sRes = this->GetHWnd(&pHWndS)))
	{
	
		return sRes;

	}// end if

	ListView_SetExtendedListViewStyleEx(pHWndS, ulExMask_, ulExStyle_);


	return CAPP_ERR_NO_ERRORS;
	
}// end CAPPRESULT CListViewCtrl::SetExtendedStyleEx(DWORD ulExMask_, DWORD ulExStyle_)



CAPPRESULT CListViewCtrl::OnCreate(HWND pHWndS_, int nWndID_)
{
	
	CAPPRESULT sRes;
	if(CAPP_FAILED(sRes = CCtrl::OnCreate(pHWndS_, nWndID_)))
	{
	
		return sRes;

	}// end if

	if(this->m_unIconID)
	{

		// create the image list to contain bitmaps for the buttons
		if(CAPP_FAILED(sRes = this->m_ImageListC.Create( 16, 16, ILC_COLOR32 | ILC_MASK, 1, 0 )))
		{
		
			return sRes;

		}// end if

		HICON pIconHandleS;

		if(!(pIconHandleS = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(this->m_unIconID), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR)))
		{

			return sRes;

		}// end if

		UINT unImageIndex;
		// create the image list to contain bitmaps for the buttons
		if(CAPP_FAILED(sRes = this->m_ImageListC.Add((HICON)pIconHandleS, &unImageIndex)))
		{
		
			return sRes;

		}// end if

		if(CAPP_FAILED(sRes = this->SetImageList(&this->m_ImageListC, CListViewCtrl::m_eImageListStyle::SMALL)))
		{
		
			return sRes;

		}// end if

	}// end if



	return CAPP_ERR_NO_ERRORS;

}// end CAPPRESULT CListViewCtrl::OnCreate(HWND pHWndS_, int nWndID_)




// Here's the code that creates the window


	CListViewCtrl::SCListViewCtrlConf ConfDataS;

	ZeroMemory(&ConfDataS, sizeof(CChildWnd::SCChildWndConf));
	
	ConfDataS.m_bFrameDrawOvr = FALSE;
	ConfDataS.m_bClientDrawOvr = FALSE;
	ConfDataS.m_bEditLabel = FALSE;
	ConfDataS.m_pParentC = this;
	ConfDataS.m_unIconID = NULL;
	ConfDataS.m_fRelX = 0;
	ConfDataS.m_fRelY = 13;
	ConfDataS.m_fRelWidth = 100;
	ConfDataS.m_fRelHeight = 87;
	ConfDataS.m_nNoReszSide = CChildWnd::SCChildWndConf::m_eNoReszSide::NO_RESZ_TOP | CChildWnd::SCChildWndConf::m_eNoReszSide::NO_RESZ_LEFT | CChildWnd::SCChildWndConf::m_eNoReszSide::NO_RESZ_RIGHT | CChildWnd::SCChildWndConf::m_eNoReszSide::NO_RESZ_BOTTOM;

	if(CAPP_FAILED(sRes = this->AddChild("CListViewCtrl", &(this->m_pClientEventsListViewC), &ConfDataS, &(this->m_nClientEventsListViewID))))
	{
	
		return sRes;

	}// end if

/// And here's the one that adds the columns and the checkboxes


	LV_COLUMN   ListViewColumnS;

	//initialize the columns
	ListViewColumnS.mask    = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	ListViewColumnS.fmt     = LVCFMT_LEFT;
	ListViewColumnS.cx      = 100;
	ListViewColumnS.pszText = "Evento";

    int nColumnIndex = 0;
	// initialize the list view
	if(CAPP_FAILED(sRes = dynamic_cast<CListViewCtrl*>(this->m_pClientEventsListViewC)->InsertColumn(nColumnIndex, &ListViewColumnS, &nColumnIndex)))
	{
	
		return sRes;

	}// end if


	//initialize the columns
	ListViewColumnS.mask    = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	ListViewColumnS.fmt     = LVCFMT_LEFT;
	ListViewColumnS.cx      = 100;
	ListViewColumnS.pszText = "Utilidades";

    nColumnIndex = 1;
	// initialize the list view
	if(CAPP_FAILED(sRes = dynamic_cast<CListViewCtrl*>(this->m_pClientEventsListViewC)->InsertColumn(nColumnIndex, &ListViewColumnS, &nColumnIndex)))
	{
	
		return sRes;

	}// end if

	// set the checkboxes
	if(CAPP_FAILED(sRes = dynamic_cast<CListViewCtrl*>(this->m_pClientEventsListViewC)->SetExtendedStyleEx(LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES)))
	{
	
		return sRes;

	}// end if


Please if anybody has any clue as to what might be happening let me know. I aoplogize if the OO library that I'm using, which is my own, can be a bit confusing, but it's basically the same Win32.

Share this post


Link to post
Share on other sites
Not sure, but it could be because you send ICC_TREEVIEW_CLASSES to InitCommonControlsEx.
See what happens if you add the ICC_LISTVIEW_CLASSES flag.

Share this post


Link to post
Share on other sites

This topic is 3846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this