Inserare CBitmap in CListCtrl

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
Mihail
Junior
Junior
Posts: 15
Joined: 11 Apr 2013, 10:14

Inserare CBitmap in CListCtrl

Post by Mihail » 03 Jan 2015, 20:12

Salut la toata lumea,

- Am o mica problema care suna cam asa: vreau sa creez citeva obiecte CBitmap in care desenez ceva/orice, apoi sa le inserez intr-un CListCtrl sub forma "thumbnail view" ,deci fara text, vreau sa fac o lista cu niste imagini create de mine la runtime. Daca inserez un icon, e ok, dar daca inserez un bitmap, se insereaza doar un patrat negru si nu bmp-ul in care tocmai am desenat ceva.

Code: Select all

	
         // Am creat lista
         lstCtrl.Create(WS_VISIBLE | WS_CHILD | WS_BORDER | WS_EX_CLIENTEDGE, CRect(10, 10, 320, 280), this, 6561);


	CBitmap bitmap;
	CClientDC windowDC(this);
	bitmap.CreateCompatibleBitmap(&windowDC, 200, 100);
  
        // Vom desena in memoryDC, deci nu pe ecran
	CDC memoryDC;
	memoryDC.CreateCompatibleDC(&windowDC);

	CBitmap* pOldBitmap = memoryDC.SelectObject(&bitmap);

	CBrush* pRedBrush = new CBrush(RGB(255, 0, 0));
	CBrush* pWhiteBrush = new CBrush(RGB(255, 0, 255));
	CPen* pThickPen = new CPen(PS_SOLID, 3, RGB(0, 0, 0));

	CBrush* pOldBrush = memoryDC.SelectObject(pRedBrush);
	CPen* pOldPen = memoryDC.SelectObject(pThickPen);

        // Desenam ceva
	memoryDC.Rectangle(CRect(0, 0, 20, 20));

        // Trebuie sa cream un CImageList din care vom prelua/adauga imaginile
	 ImgHeaders.Create(64, 64, ILC_COLOR32, 0, 0);
	HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	 ImgHeaders.Add(hIcon);
	ImgHeaders.Add(&bitmap, RGB(0, 255, 0));


	lstCtrl.SetImageList(&ImgHeaders, LVSIL_NORMAL);
  
        // Inseram un icon si bmp-ul care nu functioneaza
	lstCtrl.InsertItem(0, _T("test"), 0);
	lstCtrl.InsertItem(1, _T("test1"), 1);
Vreo idee?

PS: Am atasat si-un mic exemplu care include executabilul.

Merci,
Mihail.
Attachments
Test.rar
(240.42 KiB) Downloaded 219 times



Viorel
Microsoft MVP
Microsoft MVP
Posts: 291
Joined: 13 Jul 2007, 12:26

Re: Inserare CBitmap in CListCtrl

Post by Viorel » 03 Jan 2015, 22:11

Încearcă o altă desenare:

Code: Select all

. . .
CBitmap bitmap;
bitmap.CreateCompatibleBitmap( &windowDC, 64, 64 );

CDC memoryDC;
memoryDC.CreateCompatibleDC( &windowDC );

CBrush redBrush( RGB( 255, 0, 0 ) );
CPen thickPen( PS_INSIDEFRAME, 3, RGB( 0, 0, 0 ) );

auto oldBitmap = memoryDC.SelectObject( bitmap );
auto oldBrush = memoryDC.SelectObject( redBrush );
auto oldPen = memoryDC.SelectObject( thickPen );

memoryDC.Rectangle( 0, 0, 64, 64 );

memoryDC.SelectObject( oldPen );
memoryDC.SelectObject( oldBrush );
memoryDC.SelectObject( oldBitmap );
. . .

Mihail
Junior
Junior
Posts: 15
Joined: 11 Apr 2013, 10:14

Re: Inserare CBitmap in CListCtrl

Post by Mihail » 03 Jan 2015, 22:47

Merge! Merci f. mult Viorel! Te pricepi, nu gluma, am stat citeva ore sa-i dau de capat si fara succes. Thx again.

Post Reply