Click here to Skip to main content
15,912,072 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How To Detect Proxy Settings and Manipulate them Pin
Joaquín M López Muñoz25-Mar-03 22:13
Joaquín M López Muñoz25-Mar-03 22:13 
GeneralRe: How To Detect Proxy Settings and Manipulate them Pin
John-theKing26-Mar-03 2:06
John-theKing26-Mar-03 2:06 
GeneralRe: How To Detect Proxy Settings and Manipulate them Pin
Joaquín M López Muñoz26-Mar-03 2:28
Joaquín M López Muñoz26-Mar-03 2:28 
GeneralRe: How To Detect Proxy Settings and Manipulate them Pin
John-theKing26-Mar-03 20:00
John-theKing26-Mar-03 20:00 
GeneralRe: How To Detect Proxy Settings and Manipulate them Pin
Joaquín M López Muñoz26-Mar-03 20:10
Joaquín M López Muñoz26-Mar-03 20:10 
GeneralRe: How To Detect Proxy Settings and Manipulate them Pin
John-theKing26-Mar-03 20:15
John-theKing26-Mar-03 20:15 
Questionhow to add entry to personnel address book programatically Pin
Alfred25-Mar-03 21:38
Alfred25-Mar-03 21:38 
GeneralProblem drawing transparent bitmap using DrawTransparentBitmap exisitng ONLY in Win98 16bit color Pin
lob25-Mar-03 21:12
lob25-Mar-03 21:12 
Hello,

I'm using following function :
-----------------------------------------------------------------------
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, int xStart,
int yStart, COLORREF cTransparentColor)
{
BITMAP bm;
COLORREF cColor;
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
POINT ptSize;

hdcTemp = CreateCompatibleDC(hdc);
SelectObject(hdcTemp, hBitmap); // Select the bitmap

GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth; // Get width of bitmap
ptSize.y = bm.bmHeight; // Get height of bitmap
DPtoLP(hdcTemp, &ptSize, 1); // Convert from device

// to logical points

// Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc);
hdcObject = CreateCompatibleDC(hdc);
hdcMem = CreateCompatibleDC(hdc);
hdcSave = CreateCompatibleDC(hdc);

// Create a bitmap for each DC. DCs are required for a number of
// GDI functions.

// Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

// Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);

// Each DC must select a bitmap object to store pixel data.
bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);

// Set proper mapping mode.
SetMapMode(hdcTemp, GetMapMode(hdc));

// Save the bitmap sent here, because it will be overwritten.
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

// Set the background color of the source DC to the color.
// contained in the parts of the bitmap that should be transparent
cColor = SetBkColor(hdcTemp, cTransparentColor);

// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
SRCCOPY);

// Set the background color of the source DC back to the original
// color.
SetBkColor(hdcTemp, cColor);

// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
NOTSRCCOPY);

// Copy the background of the main DC to the destination.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
SRCCOPY);

// Mask out the places where the bitmap will be placed.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

// Mask out the transparent colored pixels on the bitmap.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

// XOR the bitmap with the background on the destination DC.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

// Copy the destination to the screen.
BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
SRCCOPY);

// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

// Delete the memory bitmaps.
DeleteObject(SelectObject(hdcBack, bmBackOld));
DeleteObject(SelectObject(hdcObject, bmObjectOld));
DeleteObject(SelectObject(hdcMem, bmMemOld));
DeleteObject(SelectObject(hdcSave, bmSaveOld));

// Delete the memory DCs.
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
}
-----------------------------------------------------------------------
I use function a lot and it works perfect. Recently , by chance i finded out
there's a problem in win98 ( second edition ) when using 16 BIT COLOR.

Here's example of how i use this function :

DrawTransparentBitmap(
m_hMemDC ,
HBITMAP(pictBubble),
nBubblePosX,
nBubblePosY,
CLR_TRANSPARENT);

Here's my define of transparent color ( "clean" CYAN )
#define CLR_TRANSPARENT RGB(0,255,255)

As i said , it works everywhere except win98 ( second edition ) when using 16 BIT COLOR.
As far as i know , each loaded image produces it's own palette. In some cases , it can
cause color to be changed to nearest color and obviously , transparency won't work in this
case since above function needs transparent color to be exact down to pixel.
So , i tried to use following to work it out :

cTransparentColor = GetNearestColor( hdc , CLR_TRANSPARENT );

But , it didn't work.


Need your help ( it's pretty urgent ) , thanks !
P.S. I just prefer solution that won't force me to change everything , but a small patch Wink | ;)

GeneralRe: Problem drawing transparent bitmap using DrawTransparentBitmap exisitng ONLY in Win98 16bit color Pin
lob27-Mar-03 0:54
lob27-Mar-03 0:54 
GeneralRe: Problem drawing transparent bitmap using DrawTransparentBitmap exisitng ONLY in Win98 16bit color Pin
John R. Shaw28-Mar-03 18:13
John R. Shaw28-Mar-03 18:13 
GeneralRe: Problem drawing transparent bitmap using DrawTransparentBitmap exisitng ONLY in Win98 16bit color Pin
lob28-Mar-03 22:48
lob28-Mar-03 22:48 
QuestionDistributed Compiling? Pin
AAntix25-Mar-03 21:09
AAntix25-Mar-03 21:09 
AnswerRe: Distributed Compiling? Pin
Abbas_Riazi25-Mar-03 21:36
professionalAbbas_Riazi25-Mar-03 21:36 
QuestionHow To Turn Off The PC ? Pin
Vikrant Kapoor25-Mar-03 21:09
Vikrant Kapoor25-Mar-03 21:09 
AnswerRe: How To Turn Off The PC ? Pin
Hesham Amin25-Mar-03 21:32
Hesham Amin25-Mar-03 21:32 
GeneralCopying the Device COntext Pin
RaajaOfSelf25-Mar-03 20:58
RaajaOfSelf25-Mar-03 20:58 
QuestionHow To Get a FrameWindow From the Document Class in MDI Pin
Vikrant Kapoor25-Mar-03 20:55
Vikrant Kapoor25-Mar-03 20:55 
AnswerRe: How To Get a FrameWindow From the Document Class in MDI Pin
567890123426-Mar-03 0:58
567890123426-Mar-03 0:58 
GeneralWant to generate system alarm Pin
summo25-Mar-03 20:37
summo25-Mar-03 20:37 
Generaldoc Icon... Pin
Manikandan25-Mar-03 20:16
Manikandan25-Mar-03 20:16 
GeneralRe: doc Icon... Pin
Dave Bryant26-Mar-03 8:57
Dave Bryant26-Mar-03 8:57 
GeneralProblem in email sending(SMTP) Pin
summo25-Mar-03 19:44
summo25-Mar-03 19:44 
GeneralProperty pages not initialized Pin
DREVET Olivier25-Mar-03 19:38
DREVET Olivier25-Mar-03 19:38 
GeneralRe: Property pages not initialized Pin
Roger Allen26-Mar-03 0:33
Roger Allen26-Mar-03 0:33 
GeneralRe: Property pages not initialized Pin
DREVET Olivier26-Mar-03 0:46
DREVET Olivier26-Mar-03 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.