Solved

Visual C++ beginer

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

759 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

21 Experts available now in Live!

Get 1:1 Help Now