Jason Teagle
March 14th, 2001, 09:41 AM
I have a situation where I need to build a picture out of a collection of icons, mosaic-style.
My first attempt was to create a form that would have Visible set to True, but be positioned off-screen so user couldn't see it; this form had all the icons I would need in pictures boxes. The main form then grabbed these icons using the picture box's Image property and tried to use the API call DrawIcon(). The problem is, the call failed, even though the hDC was valid, the Image property returned something non-zero, and the position was well within limits.
Question (1a) Why did the call fail? I can only suspect that what the Image property returns is NOT an HICON as required by DrawIcon()...
My second attempt was to take this handle and use it with the API call BitBlt() instead, assuming it was an HBITMAP. Despite creating a memory DC compatible with the display (passing 0, or NULL, to CreateCompatibleDC() ), it failed when I tried to select the HBITMAP(?) into the memory DC for blitting.
Question (1b) Why did the select fail? I assume the handle was not an HBITMAP, or it was not compatible with the DC (which should not be the case, since the DC matched the display!).
Question (1c) Given a picture box with an icon as its Picture property, how can I get an HICON handle from it, if the Image property does not give it as it hinted it did?
My third attempt was to use an image list. I added all the icons to the list(s), and sure enough they show when I DrawIcon() after calling ExtractIcon on the image list entries. Great. The problem is, it is not using the colours present in the icons (which are 16 colour)! It seems to use shades of grey, but not even a proportional shade to the real colours - white comes out as black. I told it NOT to use the mask colour, and I set the mask colour to an unused colour just be sure.
Question (2) Why is it not using my colours? How can I get it to do so?
If it is of any help, I am trying to draw these on a large picture box (AutoRedraw = False). I see no Palette property, so I don't understand why colours are being messed up.
Can anyone help?
My first attempt was to create a form that would have Visible set to True, but be positioned off-screen so user couldn't see it; this form had all the icons I would need in pictures boxes. The main form then grabbed these icons using the picture box's Image property and tried to use the API call DrawIcon(). The problem is, the call failed, even though the hDC was valid, the Image property returned something non-zero, and the position was well within limits.
Question (1a) Why did the call fail? I can only suspect that what the Image property returns is NOT an HICON as required by DrawIcon()...
My second attempt was to take this handle and use it with the API call BitBlt() instead, assuming it was an HBITMAP. Despite creating a memory DC compatible with the display (passing 0, or NULL, to CreateCompatibleDC() ), it failed when I tried to select the HBITMAP(?) into the memory DC for blitting.
Question (1b) Why did the select fail? I assume the handle was not an HBITMAP, or it was not compatible with the DC (which should not be the case, since the DC matched the display!).
Question (1c) Given a picture box with an icon as its Picture property, how can I get an HICON handle from it, if the Image property does not give it as it hinted it did?
My third attempt was to use an image list. I added all the icons to the list(s), and sure enough they show when I DrawIcon() after calling ExtractIcon on the image list entries. Great. The problem is, it is not using the colours present in the icons (which are 16 colour)! It seems to use shades of grey, but not even a proportional shade to the real colours - white comes out as black. I told it NOT to use the mask colour, and I set the mask colour to an unused colour just be sure.
Question (2) Why is it not using my colours? How can I get it to do so?
If it is of any help, I am trying to draw these on a large picture box (AutoRedraw = False). I see no Palette property, so I don't understand why colours are being messed up.
Can anyone help?