Click here to Skip to main content
15,881,424 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: relation between CMainframe and the application class Pin
Nelek24-May-07 21:22
protectorNelek24-May-07 21:22 
QuestionLNK2005 linking problem with libcmt.lib [modified] Pin
theboywilse24-May-07 5:41
theboywilse24-May-07 5:41 
QuestionApplication Crashes on OnBegindrag Pin
AAKAra24-May-07 5:19
AAKAra24-May-07 5:19 
QuestionAccess from thread Pin
garfield18524-May-07 5:12
garfield18524-May-07 5:12 
AnswerRe: Access from thread Pin
KellyR24-May-07 5:24
KellyR24-May-07 5:24 
GeneralRe: Access from thread Pin
garfield18524-May-07 5:38
garfield18524-May-07 5:38 
GeneralRe: Access from thread Pin
Roger Stoltz24-May-07 5:49
Roger Stoltz24-May-07 5:49 
QuestionWeird problem with bitmaps.. Pin
KellyR24-May-07 4:32
KellyR24-May-07 4:32 
Hi, I'm having an odd problem with bitmaps and I was hoping someone might have some idea of what to look for.

I'm using only VC++ and the Windows API, not MFC.

The basic goal I want to accomplish is to have one array of bitmaps, and a corresponding array of masks for these bitmaps so that I can easily draw the bitmaps transparently.

The problem is that one of the bit masks is not being created properly for some reason, even though all of the others work just fine using the same function.

So here's what I'm doing: I first create an array of bitmap handles using LoadBitmap, with MAKEINTRESOURCE called on a resource id. This works fine. Then I attempt to create a bit mask for each of these bitmaps.

The bitmap mask created, basically, as follows:

Into the function, I pass the HBITMAP to create the mask for, as variable Hbm, and I pass
the COLORREF of the color to be transparent, as Trans.

<br />
HBITMAP CreateMask(HBITMAP Hbm, COLORREF Trans)<br />
{<br />
 HBITMAP Mask, o1, o2; <br />
 HDC hd1, hdc2;<br />
<br />
 // Create a monochrome mask<br />
 Mask = CreateBitmap(10, 10, 1, 1, NULL);<br />
<br />
 hdc1 = CreateCompatibleDC(main_HDC);<br />
 hdc2 = CreateCompatibleDC(main_HDC);<br />
 o1 = (HBITMAP)SelectObject(hdc1, Hbm);<br />
 o2 = (HBITMAP)SelectObject(hdc2, Mask);<br />
 SetBkColor(hdc1, Trans);<br />
<br />
 // Copy the bitmap to the monochrome mask, this makes background color white and all else black<br />
 BitBlt(hdc2, 0, 0, 10, 10, hdc1, 0, 0, SRCCOPY);<br />
<br />
 // Now turn the original transparent color in the first bitmap to black so we can use SRCPAINT<br />
 BitBlt(hdc1, 0, 0, 10, 10, hdc2, 0, 0, SRCINVERT);<br />
<br />
 Hbm = (HBITMAP)SelectObject(hdc1, o1);<br />
 Mask = (HBITMAP)SelectObject(hdc2, o2);<br />
<br />
 DeleteDC(hdc1);<br />
 DeleteDC(hdc2);<br />
<br />
 return Mask;<br />
}<br />


I use this function to create 6 masks, and it works fine for most of them, but for some reason the 3rd mask does not seem to be created properly. Even if I only try to create that one mask and not the other 5, it doesn't work. The mask handle is returned, and it has the correct size (10, 10), but when I try to blit it to the screen, either it doesn't show up, or it's in some weird shape that isn't correct. Even if I use the SAME bitmap to create all 6 of the masks, 5 of them come out correctly and that one, the 3rd one, is still messed up.

Here's the function I use to blit to my double-buffered HDC:
<br />
void DrawTransparentBitmap(HBITMAP bitmap, HBITMAP mask, int x, int y, int wid, int hgt)<br />
{<br />
   HBITMAP orig;<br />
<br />
   orig = (HBITMAP)SelectObject(DrawDC, mask);<br />
   BitBlt(wobj.getBackHDC(), x, y, wid, hgt, DrawDC,0,0,SRCAND); // Copy everything except what's white<br />
  <br />
   mask = (HBITMAP)SelectObject(DrawDC, orig);<br />
<br />
   orig = (HBITMAP)SelectObject(DrawDC, bitmap);<br />
   BitBlt(wobj.getBackHDC(), x, y, wid, hgt, DrawDC,0,0,SRCPAINT); // Copy everything except what's black<br />
<br />
   bitmap = (HBITMAP)SelectObject(DrawDC, orig);<br />
}<br />


I've tried creating the global DrawDC as variable local to the DrawTransparentBitmap function; this has no effect.

The problem is almost certainly that the mask is somehow being screwed up in its creation.

Does anyone have any ideas about what might be wrong? Am I missing some bitmap "best practice" or something (like selecting the original bitmap handles back into the HDCs, etc)?

KR

Questionhow to close .exe file in process list in task manager Pin
nahitan24-May-07 4:13
nahitan24-May-07 4:13 
QuestionRe: how to close .exe file in process list in task manager Pin
David Crow24-May-07 4:19
David Crow24-May-07 4:19 
AnswerRe: how to close .exe file in process list in task manager Pin
Mark Salsbery24-May-07 6:32
Mark Salsbery24-May-07 6:32 
GeneralRe: how to close .exe file in process list in task manager Pin
nahitan24-May-07 9:41
nahitan24-May-07 9:41 
AnswerRe: how to close .exe file in process list in task manager Pin
swarup24-May-07 8:22
swarup24-May-07 8:22 
GeneralRe: how to close .exe file in process list in task manager Pin
nahitan24-May-07 9:45
nahitan24-May-07 9:45 
AnswerRe: how to close .exe file in process list in task manager Pin
Hamid_RT24-May-07 11:12
Hamid_RT24-May-07 11:12 
Questiondelete "anonymous?" string Pin
daveyerwin24-May-07 4:07
daveyerwin24-May-07 4:07 
AnswerRe: delete "anonymous?" string Pin
BadKarma24-May-07 4:11
BadKarma24-May-07 4:11 
GeneralRe: delete "anonymous?" string Pin
Mark Salsbery24-May-07 6:33
Mark Salsbery24-May-07 6:33 
Question.Net 1.1 --> .Net 2.0 Pin
Tal S.24-May-07 3:51
Tal S.24-May-07 3:51 
AnswerRe: .Net 1.1 --&gt; .Net 2.0 Pin
Mark Salsbery24-May-07 6:41
Mark Salsbery24-May-07 6:41 
GeneralRe: .Net 1.1 --&gt; .Net 2.0 Pin
Tal S.24-May-07 8:50
Tal S.24-May-07 8:50 
GeneralRe: .Net 1.1 --&gt; .Net 2.0 Pin
Mark Salsbery24-May-07 9:07
Mark Salsbery24-May-07 9:07 
GeneralRe: .Net 1.1 --&gt; .Net 2.0 Pin
Tal S.24-May-07 10:00
Tal S.24-May-07 10:00 
GeneralRe: .Net 1.1 --&gt; .Net 2.0 Pin
Mark Salsbery24-May-07 10:03
Mark Salsbery24-May-07 10:03 
GeneralRe: .Net 1.1 --&gt; .Net 2.0 Pin
Tal S.24-May-07 10:17
Tal S.24-May-07 10:17 

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.