Solved

Visual C++ beginer

Posted on 1998-06-20
4
1,050 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now