CBitmap problem in CTabCtrl

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
Anonymous

CBitmap problem in CTabCtrl

Post by Anonymous »

The problem is in inserting CBitmap in to CTabCtrl, if i load CBitmap from resource it`s ok, but if try to create CBitmap , write for example something on it, and then insert that bitmap to CTabCtrl nothing hepens.

First sample is code with CBitmap from resource working OK:

BOOL CCePropertySheet::OnInitDialog()
{

CTabCtrl* pTab = GetTabControl();
m_imageList.Create (60,36,ILC_COLOR, 0, 4);

CBitmap bm;

bm.LoadBitmap(IDB_TAB1);
m_imageList.Add(&bm, RGB(0, 0, 0));
...
..
. //more init code (not important)

}

=============================================
And now the sample code where is CBitmap created dinamicly thru CDC and inserted:


BOOL CCePropertySheet::OnInitDialog()
{

CTabCtrl* pTab = GetTabControl();
m_imageList.Create (60,36,ILC_COLOR, 0, 4);

CDC *bmCDC;
CBitmap *bm;

CDC* pdc = GetDC();
bmCDC->CreateCompatibleDC(pdc);
bm->CreateCompatibleDC(pdc,60,30);

bmCDC->SelectObject(bm);

bmCDC->TextOut ...... write something or draw


m_imageList.Add(bmCDC->GetCurrentBitmap(), RGB(0, 0, 0));
...
..
. //more init code (not important)

}


This is not working, i think is something about init CDC (GetCDC() ) but i don`t now what exactly, can anyone help me please.

Archived topic from Iceteks, old topic ID:2485, old post ID:20864
User avatar
Red Squirrel
Posts: 29206
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

CBitmap problem in CTabCtrl

Post by Red Squirrel »

Welcome aboard. Sorry I can't helo you though, hav'nt done C++ in a while and never got that advanced. Got discouraged when I realize making a triangle took 1000 lines of code. :lol2:

Archived topic from Iceteks, old topic ID:2485, old post ID:20865
Honk if you love Jesus, text if you want to meet Him!
Fat Cat
Posts: 16
Joined: Wed Mar 31, 2004 8:33 pm

CBitmap problem in CTabCtrl

Post by Fat Cat »

CDC* pdc = GetDC();
bmCDC->CreateCompatibleDC(pdc);
bm->CreateCompatibleDC(pdc,60,30);


You have 2 "CreateCompatibleDC" commands one after another. The second one has 3 parameters passed to it (pdc, 60, 30), should it only have 1 parameter passed to it ?

------------------------------------
CDC::CreateCompatibleDC
virtual BOOL CreateCompatibleDC( CDC* pDC );

Return Value: Nonzero if the function is successful; otherwise 0.

Parameters:

pDC
A pointer to a device context. If pDC is NULL, the function creates a memory device context that is compatible with the system display.

Remarks
Creates a memory device context that is compatible with the device specified by pDC. A memory device context is a block of memory that represents a display surface. It can be used to prepare images in memory before copying them to the actual device surface of the compatible device.

When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.

This function can only be used to create compatible device contexts for devices that support raster operations. See the CDC::BitBlt member function for information regarding bit-block transfers between device contexts. To determine whether a device context supports raster operations, see the RC_BITBLT raster capability in the member function CDC::GetDeviceCaps.






Archived topic from Iceteks, old topic ID:2485, old post ID:20900
Anonymous

CBitmap problem in CTabCtrl

Post by Anonymous »

Tnx Red Squirrel for worm welcome :) , and i like to say i am sorry but i made a mistake writing code in FORUM, i didn`t copy-paste from my project, it shold be :

bm->CreateCompatibleBitmap(pdc,60,30);

not: bm->CreateCompatibleDC(pdc,60,30);
i am sory "Fat Cat" but i still have a problem

Archived topic from Iceteks, old topic ID:2485, old post ID:20901
Fat Cat
Posts: 16
Joined: Wed Mar 31, 2004 8:33 pm

CBitmap problem in CTabCtrl

Post by Fat Cat »

I don't do much with bitmaps (mostly OpenGL), but there are a few notes on loading bitmaps and moving bitmaps using CreateCompatibleDC at http://www.gametutorials.com/Tutorials/win32/Win32_Pg3.htm

Might be worth a look.

Archived topic from Iceteks, old topic ID:2485, old post ID:20903
Fat Cat
Posts: 16
Joined: Wed Mar 31, 2004 8:33 pm

CBitmap problem in CTabCtrl

Post by Fat Cat »

is the syntax of your CreateCompatibileDC statements correct ?

should they be;

bmCDC.CreateCompatibleDC(pDC);

bmCDC.SelectObject(bm);

instead of;

bmCDC->CreateCompatibleDC(pDC);

bmCDC->SelectObject(bm);


then use;
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight,&bmCDC, 0, 0, SRCCOPY);

to copy the bitmap over






Archived topic from Iceteks, old topic ID:2485, old post ID:20904
Anonymous

CBitmap problem in CTabCtrl

Post by Anonymous »

I find the solution , i didnt select objects right here`s the code:

BOOL CCePropertySheet::OnInitDialog()
{

CTabCtrl* pTab = GetTabControl();
m_imageList.Create (60,36,ILC_COLOR, 0, 4);

CDC*pCtrlDC = GetDC();

CBitmap Bitmap;
CBitmap *pOldBitmap;

CDC TempDC;

TempDC.CreateCompatibleDC(pCtrlDC);
Bitmap.CreateCompatibleBitmap(pCtrlDC,60,32);

pOldBitmap = TempDC.SelectObject(&Bitmap);

TempDC.ExtTextOut(0,0,ETO_OPAQUE,NULL,"write or draw",NULL);

TempDC.SelectObject(pOldBitmap);

tmpImageList->Add(&Bitmap, RGB(0, 0, 0));
...
..
. //more init code (not important)


tmpImageList->Detach();
Bitmap.DeleteObject();
ReleaseDC(pCtrlDC);

}

Archived topic from Iceteks, old topic ID:2485, old post ID:20916
Locked