Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Visual C++ beginer

Posted on 1998-06-20
4
Medium Priority
?
1,083 Views
Last Modified: 2008-02-01
I am learning about displaying an overlapped immage
I got the following piece of code as example

"
void CImageListView::OnDraw(CDC* pDC)
{
      CImageListDoc* pDoc = GetDocument();
      ASSERT_VALID(pDoc);

      // TODO: add draw code for native data here
      m_imageList.SetBkColor(CLR_NONE);
      CPoint ptOverlay(50,50);
      m_imageList.SetOverlayImage(0,1);
      m_imageList.Draw(pDC, 3, ptOverlay, ILD_OVERLAYMASK|INDEXTOOVERLAYMASK(1));
}"

The explination for the SetOverlayImage function is confusing.
"The SetOverlayImage function takes two parameters: the image index used as the overlay, and the overlay index used to identify the overlay."
The funny think is that , I have a list of four images, no matter what I put as parameters for the SetOverlayImage I still get the same result when compiling and running. Even if I get rid of the function for good, I still get the same behaviour from the program.

Second case is regarding dispalying a transparent image.
I am given the following example
void CImageListView::OnDraw(CDC* pDC)
{
m_imageList.SetBkColor(CLR_NONE);
CPoint ptImage(0,0);
for(itn nImage = 0; nImage < 4; nImage++)
{
   m_imageList.Draw(pDC, nImage, ptImage, ILD_TRANSPARENT);
ptImage.x += 50;
}
}

The explination in the book sounds like this:
"The background color is set to CLR_NONE using the CImageList::SetBkColor function. The CLR_NONE parameter tella a masked image to list to prepare to use the coloor mask when drawing any images. Second, the ILD_TRANSPARENT flat is used when CImageList::Draw is called. This tells the iamge list to combine the image mask with the bitmap, if a mask ests. In this case , the bitmap uses a color mask, so the background color is made transparent"

I understand the above like this.:
Using SetBkColor with CLR_NONE parameter, we inform the immage list about the fact that it is supposed to use a color mask when drawing images. The last sentence confuses me. If the map was using anyway a color mask, why should we use the SetBkColor at all ? I understang that if the bitmap itself uses a mask, the ImageList , knowing that it should use a mask when draw objects( told by the SetBkColor function), will trie to do it, and when it sees that the bitmap allready has a mask it makes the background collor transparent. But if the bitmap had allready a mask, why did we use the whole thing after all ?
0
Comment
Question by:simi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:simi
ID: 1166358
Edited text of question
0
 

Author Comment

by:simi
ID: 1166359
Adjusted points to 50
0
 
LVL 1

Expert Comment

by:Arkadiy
ID: 1166360
1)SetOverlayImage
SetOverlayImage does not changes any image, nor does it draw anything. It lets you associate an overlay image index with an image in the list. There can be up to overlay images. So, when you call SetOverlayImage like this:

SetOverlayImage( 0, 1);
SetOverlayImage( 2, 2);
SetOverlayImage( 4, 3);
SetOverlayImage( 10, 4);

, you inform the list that images 1,2,4,10 willbe used as oberlay images. When you actually want to use them, you use
ILD_OVERLAYMASK | INDEXTOOVERLAYMASK(3) in the last parameter of Draw function. That will overlay image 4 over whatever image you are drawing.

2)SetBkColor vs. ILD_TRANSPARENT. Seems like CLR_NONE and ILD_TRANSPARENT are orthogonal. You can either call SetBkColor(CLR_NONE) and the call Draw with ILD_NORMAL, or you can forget about SetBkColor and just use ILD_TRANSPARENT.
0
 
LVL 1

Accepted Solution

by:
Arkadiy earned 200 total points
ID: 1166361
Oops. I meant the comment above to be an answer...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question