Solved

Visual C++ beginer

Posted on 1998-06-20
4
1,065 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 50 total points
ID: 1166361
Oops. I meant the comment above to be an answer...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 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