Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bmp "disappearing" ?

Status
Not open for further replies.

iza

Programmer
Apr 4, 2000
1,804
FR
i copy a bmp into memory, then from memory to a window
this goes fine almost all the time, but from time to time, under certain platform (win9x - win2000 is always fine), instead of copying the bmp to the window, i get a grey screen - nothing was copied. but no error raises tho ... f someone could help !!
some code :
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); // normal DC, provides a "snapshot" of the screen contents.
hdcCompatible = CreateCompatibleDC(hdcScreen); // memory DC keeps a copy of this "snapshot" in the associated bmp
botx=GetDeviceCaps(hdcScreen, HORZRES);
boty=GetDeviceCaps(hdcScreen, VERTRES);


// Create a compatible bitmap for hdcScreen.
hbmScreen = CreateCompatibleBitmap(hdcScreen,botx,boty);
if (hbmScreen==NULL)

raise error

// Select the bitmaps into the compatible DC.
if (SelectObject(hdcCompatible, hbmScreen)==NULL)
raise error

// won't capture the window
ShowWindow(SW_HIDE);

//Copy color data for the entire display into a bitmap that is selected into a compatible DC.
if (BitBlt(hdcCompatible,topx,topy,botx, boty,hdcScreen, 0,0,SRCCOPY))
....
else

raise error
 

Here is some other code that works:

pdc is the CDC* received from the framework

CBitmap bitmap;
CDC memDC;
CRect rect;
int nWidth;
int nHeigth;

... init nWidth and nHeight

memDC.CreateCompatibleDC( pdc);

bitmap.CreateCompatibleBitmap( pdc, nWidth, nHeight);

CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
memDC.BitBlt(0, 0, nWidth, nHeight, pdc, 0, 0, SRCCOPY);

memDC.SelectObject(pOldBitmap);


Thierry


 
thanks thierry
- but actually, my code DO work - only from time to time the bmp is not here ... sounds like memory flaw, but i can't figure out where/how ...
- btw your code and my code are the same, except that you don't catch errors - i do but they are never raised, and except that you select twice the bmp into memory (i'll try this anyway !) ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top