Greyscale an Icon

GregDuncan
01-06-2005, 04:36 AM
I am making a button control.
When the button is disabled I wanted to turn the icon grey.

I have been able to do this fine if the picture loaded is a bitmap.

When the picture is an icon however my converttogreyscale function that I found on the web doesnt work.

The reason it doesnt work is because when the icon is copyed into a bitmap structure it doesnt hold any of the necessary information such as width and height etc.
eg Dim BMI As BitmapInfo

Can anyone suggest another way to convert an icon to greyscale or perhaps point me in the right direction to convert my icon into a valid bitmap.

Thanks

ps as this is just a small button I didnt want to use gdi+

SteRobson
01-06-2005, 04:39 AM
If you set the button's style to graphical and load any image onto it (including an icon) then when the button is disabled the image is automatically greyed out! :)

GregDuncan
01-06-2005, 03:57 PM
Sorry, you have misunderstood me. I am not using a standard vb control button. I am making my own button using a usercontrol.

SteRobson
01-07-2005, 11:28 AM
:whoops: My mistake, sorry. Right, this may sound like a horrible way to do it, but can you just copy the button's image pixel by pixel and manually convert the pixels to greyscale? You said that the button is very small so this may not be too much of a performance bottleneck (as long as there aren't LOTS of buttons).

Will the icons be loaded from a standard ico file? If so then with a little research it is pretty straight forward to get the dimensions from the file headers.

Hope this is of some help :)

GregDuncan
01-14-2005, 11:24 AM
I found my answer in the DrawState function.
Posting this info in case anyone else can benifit from it.

Private Declare Function DrawState Lib "user32" Alias "DrawStateA" _
(ByVal hdc As Long, _
ByVal hBrush As Long, _
ByVal lpDrawStateProc As Long, _
ByVal lParam As Long, _
ByVal wParam As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cX As Long, _
ByVal cY As Long, _
ByVal fuFlags As Long) As Long

'/* Image type */
Private Const DST_COMPLEX = &H0
Private Const DST_TEXT = &H1
Private Const DST_PREFIXTEXT = &H2
Private Const DST_ICON = &H3
Private Const DST_BITMAP = &H4

' /* State type */
Private Const DSS_NORMAL = &H0
Private Const DSS_UNION = &H10 ' Dither
Private Const DSS_DISABLED = &H20
Private Const DSS_MONO = &H80 ' Draw in colour of brush specified in hBrush
Private Const DSS_RIGHT = &H8000

DrawState UserControl.hdc, 0, 0, Image1.Picture.Handle, 0, 0, 0, W, H, DST_ICON or DSS_DISABLED

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum