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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog Box: Bitmap gets erased when a screen is dragged over. 1

Status
Not open for further replies.

MrDwight

Programmer
Joined
May 8, 2002
Messages
6
Location
US
I have a dialog box that contains two bitmaps built into the dialog box user interface. While my application runs, it displays new images over the original ones. Unfortunately, when I drag a another window over the images, the original bitmaps reappear instead of the current ones. I am currently using the ActiveX BitBlt to place the new images onto the screen.

How do I make the new images persist?

Thank you for your help.
 
post your code to see where you put your code.
 
OK, it's kinda lengthy, but here it is. This version actually has three bitmaps instead of the two I stated earlier, but it exhibits the same problem.

bool CMedicalDlg::DrawImages()
{
// *** DIRECTDRAW PRIMARY SURFACE CREATION ***
// Prepare specifics of the surface to be created using ddsd (surface description).
ZeroMemory(&ddsd, sizeof(ddsd)); // Init surface description to zeroes.
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

// Create the surface on the DD2 object using the desired surface description.
ddrval = Image1DD2->CreateSurface(&ddsd, &Box1Primary, NULL);
if (FAILED(ddrval))
{
MessageBox("DirectDraw Surface Creation Failure!", NULL, MB_OK);
return FALSE;
}

// Create a handle to memory device (memoryDC) that is compatible with the screen.
HDC hdcImageReal, hdcImageImag, hdcImageAbs, hdcSurf;
hdcImageReal = CreateCompatibleDC(NULL);
hdcImageImag = CreateCompatibleDC(NULL);
hdcImageAbs = CreateCompatibleDC(NULL);
if (!hdcImageReal || !hdcImageImag || !hdcImageAbs)
{
MessageBox("Failed to create a memory device for hdcImage!", NULL, MB_OK);
Box1Primary->Release();
Box1Primary=NULL;
DeleteObject(hbm);
return FALSE;
}

// Expand the dimensions of the memoryDC to the bitmap dimensions.
if (CreateCompatibleBitmap(hdcImageReal, n, n) == NULL)
MessageBox("CreateCompatibleBitmap Failed for hdcImageReal!", NULL, MB_OK);
if (CreateCompatibleBitmap(hdcImageImag, n, n) == NULL)
MessageBox("CreateCompatibleBitmap Failed for hdcImageImag!", NULL, MB_OK);
if (CreateCompatibleBitmap(hdcImageAbs, n, n) == NULL)
MessageBox("CreateCompatibleBitmap Failed for hdcImageAbs!", NULL, MB_OK);

// Place the Image matrices into linear arrays with an RGB format.
int i, j, a = 0;
unsigned long TmpVal;

for(j=0; j<n; j++)
for(i=0; i<n; i++)
{
TmpVal = unsigned long(ImageMatrixReal[j]);
LinImageReal[a] = TmpVal + TmpVal * 256 + TmpVal * 65536; //Create RGB format.
TmpVal = unsigned long(ImageMatrixImag[j]);
LinImageImag[a] = TmpVal + TmpVal * 256 + TmpVal * 65536; //Create RGB format.
TmpVal = unsigned long(ImageMatrixAbs[j]);
LinImageAbs[a] = TmpVal + TmpVal * 256 + TmpVal * 65536; //Create RGB format.
a++;
}

// Prepare some variables to create a new DI Bitmap
__declspec(align(32)) BITMAPINFO *pbmi = NULL;
pbmi = new BITMAPINFO;
PBYTE pBitmapBits = NULL;
// Setup the BITMAPINFO structure with the bitmap specs.
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = n;
pbmi->bmiHeader.biHeight = -n;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = 32;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = n*n*4;

DeleteObject(hbm);
DeleteObject(hbm2);
DeleteObject(hbm3);

// Create new DI Bitmaps and stuff the image data into them.
hbm = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (PVOID*)pBitmapBits, NULL, 0);
if (hbm == NULL)
MessageBox(&quot;Failed to Create a new DI Bitmap for Real Image!&quot;, NULL, MB_OK);
SetDIBits(hdcImageReal, hbm, 0, n, &LinImageReal[0], pbmi, DIB_RGB_COLORS);

hbm2 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (PVOID*)pBitmapBits, NULL, 0);
if (hbm2 == NULL)
MessageBox(&quot;Failed to Create a new DI Bitmap for Imaginary!&quot;, NULL, MB_OK);
SetDIBits(hdcImageImag, hbm2, 0, n, &LinImageImag[0], pbmi, DIB_RGB_COLORS);

hbm3 = CreateDIBSection(NULL, pbmi, DIB_RGB_COLORS, (PVOID*)pBitmapBits, NULL, 0);
if (hbm3 == NULL)
MessageBox(&quot;Failed to Create a new DI Bitmap for Absolute Image!&quot;, NULL, MB_OK);
SetDIBits(hdcImageAbs, hbm3, 0, n, &LinImageAbs[0], pbmi, DIB_RGB_COLORS);

// Select the new bitmaps into the memory DC's.
SelectObject(hdcImageReal, hbm);
SelectObject(hdcImageImag, hbm2);
SelectObject(hdcImageAbs, hbm3);

// Determine the Window Locations
CWnd *cPic;
CRect cRealPicRect, cImagPicRect, cAbsPicRect;
CDialog::SetForegroundWindow();
cPic = CDialog::GetDlgItem(Pic_Real);
cPic->GetWindowRect(cRealPicRect);
cPic = CDialog::GetDlgItem(Pic_Imag);
cPic->GetWindowRect(cImagPicRect);
cPic = CDialog::GetDlgItem(Pic_Abs);
cPic->GetWindowRect(cAbsPicRect);
// Adjust for Window borders
cRealPicRect.left += 5;
cImagPicRect.left += 5;
cAbsPicRect.left += 5;
cRealPicRect.top += 5;
cImagPicRect.top += 5;
cAbsPicRect.top += 5;

Box1Primary->GetSurfaceDesc(&ddsd);
if (Box1Primary->GetDC(&hdcSurf) == DD_OK)
{
BitBlt(hdcSurf, cRealPicRect.left, cRealPicRect.top, n, n, hdcImageReal, 0, 0, SRCCOPY);
BitBlt(hdcSurf, cImagPicRect.left, cImagPicRect.top, n, n, hdcImageImag, 0, 0, SRCCOPY);
BitBlt(hdcSurf, cAbsPicRect.left, cAbsPicRect.top, n, n, hdcImageAbs, 0, 0, SRCCOPY);
Box1Primary->ReleaseDC(hdcSurf);
}
else
MessageBox(&quot;Blitter Failure!&quot;, NULL, MB_OK);

FirstTime = FALSE;
Box1Primary->Release();
Box1Primary=NULL;
DeleteObject(hbm);
DeleteObject(hbm2);
DeleteObject(hbm3);
return TRUE;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top