Click here to Skip to main content
16,011,358 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generallinking lib files in Visual C++.NET Pin
9-Feb-02 2:05
suss9-Feb-02 2:05 
GeneralRe: linking lib files in Visual C++.NET Pin
Mazdak9-Feb-02 4:47
Mazdak9-Feb-02 4:47 
GeneralRe: linking lib files in Visual C++.NET Pin
Anders Molin9-Feb-02 5:36
professionalAnders Molin9-Feb-02 5:36 
GeneralRe: linking lib files in Visual C++.NET Pin
Mazdak9-Feb-02 6:11
Mazdak9-Feb-02 6:11 
GeneralRe: linking lib files in Visual C++.NET Pin
Anders Molin9-Feb-02 11:00
professionalAnders Molin9-Feb-02 11:00 
GeneralTransparent bitmap (win32) Pin
Brian van der Beek9-Feb-02 0:42
Brian van der Beek9-Feb-02 0:42 
GeneralRe: Transparent bitmap (win32) Pin
Christian Graus9-Feb-02 0:48
protectorChristian Graus9-Feb-02 0:48 
GeneralRe: Transparent bitmap (win32) Pin
Brian van der Beek9-Feb-02 8:46
Brian van der Beek9-Feb-02 8:46 
Christian,

Thanks for your reply. I downloaded the source, and extracted the method I need. But it's not exactly clear to me how this mehod works. (I have never worked with GUI stuff before). Is this the correct code, without memory leaks? Your example copies a piece of the source bitmap and places it back on another location (?) How would I just make the source bitmap transparent?

The method:

bool TransparentBltU(
HDC dcDest, // handle to Dest DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int nHeightDest, // height of destination rectangle
HDC dcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
UINT crTransparent // color to make transparent
)
{
if (nWidthDest < 1) return false;
if (nWidthSrc < 1) return false;
if (nHeightDest < 1) return false;
if (nHeightSrc < 1) return false;

HDC dc = CreateCompatibleDC(NULL);
HBITMAP bitmap = CreateBitmap(nWidthSrc, nHeightSrc, 1, GetDeviceCaps(dc, BITSPIXEL), NULL);

if (bitmap == NULL)
return false;

HBITMAP oldBitmap = (HBITMAP)SelectObject(dc, bitmap);

if (!BitBlt(dc, 0, 0, nWidthSrc, nHeightSrc, dcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY))
return false;

HDC maskDC = CreateCompatibleDC(NULL);
HBITMAP maskBitmap = CreateBitmap(nWidthSrc, nHeightSrc, 1, 1, NULL);

if (maskBitmap == NULL)
return false;

HBITMAP oldMask = (HBITMAP)SelectObject(maskDC, maskBitmap);

SetBkColor(maskDC, RGB(0,0,0));
SetTextColor(maskDC, RGB(255,255,255));
if (!BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,NULL,0,0,BLACKNESS))
return false;

SetBkColor(dc, crTransparent);
BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,dc,0,0,SRCINVERT);

SetBkColor(dc, RGB(0,0,0));
SetTextColor(dc, RGB(255,255,255));
BitBlt(dc, 0,0,nWidthSrc,nHeightSrc,maskDC,0,0,SRCAND);

HDC newMaskDC = CreateCompatibleDC(NULL);
HBITMAP newMask;
newMask = CreateBitmap(nWidthDest, nHeightDest, 1, GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);

if (newMask == NULL)
{
SelectObject(dc, oldBitmap);
DeleteDC(dc);
SelectObject(maskDC, oldMask);
DeleteDC(maskDC);
DeleteDC(newMaskDC);
return false;
}

SetStretchBltMode(newMaskDC, COLORONCOLOR);
HBITMAP oldNewMask = (HBITMAP) SelectObject(newMaskDC, newMask);
StretchBlt(newMaskDC, 0, 0, nWidthDest, nHeightDest, maskDC, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);

SelectObject(maskDC, oldMask);
DeleteDC(maskDC);

HDC newImageDC = CreateCompatibleDC(NULL);
HBITMAP newImage = CreateBitmap(nWidthDest, nHeightDest, 1, GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);

if (newImage == NULL)
{
SelectObject(dc, oldBitmap);
DeleteDC(dc);
DeleteDC(newMaskDC);
return false;
}

HBITMAP oldNewImage = (HBITMAP)SelectObject(newImageDC, newImage);
StretchBlt(newImageDC, 0, 0, nWidthDest, nHeightDest, dc, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);

SelectObject(dc, oldBitmap);
DeleteDC(dc);

BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, newMaskDC,
0, 0, SRCAND);

BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, newImageDC,
0, 0, SRCPAINT);

SelectObject(newImageDC, oldNewImage);
DeleteDC(newImageDC);
SelectObject(newMaskDC, oldNewMask);
DeleteDC(newMaskDC);

return true;
}
GeneralRe: Transparent bitmap (win32) Pin
Christian Graus9-Feb-02 8:57
protectorChristian Graus9-Feb-02 8:57 
GeneralRe: Transparent bitmap (win32) Pin
Brian van der Beek9-Feb-02 11:48
Brian van der Beek9-Feb-02 11:48 
GeneralRe: Transparent bitmap (win32) Pin
Christian Graus9-Feb-02 17:29
protectorChristian Graus9-Feb-02 17:29 
GeneralRe: Transparent bitmap (win32) Pin
Brian van der Beek10-Feb-02 1:33
Brian van der Beek10-Feb-02 1:33 
Generalif(localPath[i] == "\\") Pin
Rickard Andersson209-Feb-02 0:20
Rickard Andersson209-Feb-02 0:20 
GeneralRe: if(localPath[i] == "\\") Pin
Christian Graus9-Feb-02 0:26
protectorChristian Graus9-Feb-02 0:26 
GeneralRe: if(localPath[i] == "\\") Pin
Rickard Andersson209-Feb-02 1:17
Rickard Andersson209-Feb-02 1:17 
GeneralRe: if(localPath[i] == "\\") Pin
Christian Graus9-Feb-02 1:28
protectorChristian Graus9-Feb-02 1:28 
GeneralRe: if(localPath[i] == "\\") Pin
Rickard Andersson209-Feb-02 2:08
Rickard Andersson209-Feb-02 2:08 
GeneralRe: if(localPath[i] == "\\") Pin
Rickard Andersson209-Feb-02 2:15
Rickard Andersson209-Feb-02 2:15 
GeneralRe: if(localPath[i] == "\\") Pin
Christian Graus9-Feb-02 2:33
protectorChristian Graus9-Feb-02 2:33 
GeneralRe: if(localPath[i] == "\\") Pin
Christian Graus9-Feb-02 2:45
protectorChristian Graus9-Feb-02 2:45 
GeneralRe: if(localPath[i] == "\\") Pin
Ernest Laurentin9-Feb-02 3:59
Ernest Laurentin9-Feb-02 3:59 
GeneralRe: if(localPath[i] == "\\") Pin
moliate9-Feb-02 1:54
moliate9-Feb-02 1:54 
GeneralRe: HEEEEEEEEEEELP!!!!!! Pin
Rickard Andersson209-Feb-02 5:59
Rickard Andersson209-Feb-02 5:59 
GeneralRe: HEEEEEEEEEEELP!!!!!! Pin
Nish Nishant9-Feb-02 7:09
sitebuilderNish Nishant9-Feb-02 7:09 
GeneralRe: HEEEEEEEEEEELP!!!!!! Pin
Michael Dunn9-Feb-02 7:34
sitebuilderMichael Dunn9-Feb-02 7:34 

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.