For the life of me, I cannot seem to put a picture control on a form, associate an icon with it and then get the icon background to be transparent. I tried every combination of styles available via the FF properties. I do have a custom painted form.
Is there some "trick" that all you win32 api guys have up your sleeve? See attached example....
Rick Kelly
As far as I recall Paul has done this in FF with BMP-images and not ICO-files. You will have to define a color/pixel (often the upper leftmost pixel) to represent the transparent area and do some custom drawing API magic. It's nothing I have tried, so I don't have a more specific recipe for you.
Dealing with an alpha channel to allow for 256 levels of transparency, I believe is another ball-game requiring a fair bit more work.
The attachment show one of FireFly's actual toolbar graphics in it's raw form.
You can do it with icons as well but you need to set the transparency within the icon itself. You can do that with just about any icon editor. I use MicroAngelo http://www.microangelo.us/icon-editor.asp
Quote from: TechSupport on July 24, 2011, 05:50:22 PM
You can do it with icons as well but you need to set the transparency within the icon itself. You can do that with just about any icon editor. I use MicroAngelo http://www.microangelo.us/icon-editor.asp
I used IcoFX and set the transparency color to a bright shade of red and the form background a bright green. Now when I working with the form in FF, the icon shows with a white background. The code FF generated is:
'------------------------------------------------------------------------------
' Create FINDICON [Picture] control.
'------------------------------------------------------------------------------
hWndControl = CreateWindowEx( 0, _
"Static", _
"", _
%WS_CHILD Or %WS_VISIBLE Or %WS_CLIPSIBLINGS Or %WS_CLIPCHILDREN _
Or %SS_ICON Or %SS_NOTIFY, _
212, FLY_ClientOffset + 6, _
32, 32, _
hWndForm, IDC_RIBBONDEMO_FINDICON, _
App.hInstance, ByVal %Null )
ff = FLY_SetControlData( hWndControl, %TRUE, %FALSE, _
"", 0, %FALSE, _
%FALSE, %FALSE, 0, _
0, -1, CodePtr(RIBBONDEMO_CODEPROCEDURE), "" )
' Set the Tag properties for the Control
FF_Control_SetTag hWndControl, ""
FF_Control_SetTag2 hWndControl, ""
HWND_RIBBONDEMO_FINDICON = hWndControl
GetClientRect hWndControl, FLY_RECT
FLY_hPicture = LoadImage( App.hInstance, "IMAGE_FIND", %IMAGE_ICON, FLY_RECT.nRight, FLY_RECT.nBottom, 32800 )
SendMessage hWndControl, %STM_SETIMAGE, %IMAGE_ICON, FLY_hPicture
Is there something I'm missing?
Rick
I just downloaded IcoFX. Check out the attached screenshot. See where my cursor is? I believe you need to click on that section in order to select "transparent" as your color. You can then click within your icon to set the portions of the icon that you want to be transparent.
Quote from: TechSupport on July 24, 2011, 10:58:49 PM
I just downloaded IcoFX. Check out the attached screenshot. See where my cursor is? I believe you need to click on that section in order to select "transparent" as your color. You can then click within your icon to set the portions of the icon that you want to be transparent.
Here is the FF project I'm using. I think it is fine and the transparency is set where it should be. I'm impressed you would go the trouble of downloading IcoFx to help me....
Rick
Found out this works. Added a label control and removed the text, set to transparent.
In the forms create event, added:
Local ff As FLY_DATA Ptr
ff = GetProp (HWND_RIBBONDEMO_LABEL3, "FLY_PTR")
@ff.hBackBrush = GetStockObject (%NULL_BRUSH)
SetProp HWND_RIBBONDEMO_LABEL3, "FLY_PTR", ff
SetBkMode GetDC(HWND_RIBBONDEMO_LABEL3), %TRANSPARENT
Then in the labels paint handler added:
Function RIBBONDEMO_LABEL3_WM_PAINT ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword _ ' handle of Control
) As Long
Local hPicture As Dword
hPicture = LoadImage( App.hInstance, "IMAGE_FIND", %IMAGE_ICON, 32, 32, 32768 )
DrawIconEx (GetDC(hWndControl), 0, 0, hPicture, 32, 32, 0, 0, %DI_NORMAL)
End Function
Thoughts?
Rick Kelly
Hi Rick,
You have hit on a good solution however you will find that you will have massive amounts of GDI handle leaks because you are creating, but not deleting, resources during your WM_PAINT.
Your WM_PAINT should look something like this:
Function RIBBONDEMO_LABEL3_WM_PAINT ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword _ ' handle of Control
) As Long
Local hPicture As Dword
Local hDC As DWord
hPicture = LoadImage( App.hInstance, "IMAGE_FIND", %IMAGE_ICON, 32, 32, %LR_DEFAULTSIZE Or %LR_SHARED )
hDC = GetDC(hWndControl)
DrawIconEx (hDC, 0, 0, hPicture, 32, 32, 0, 0, %DI_NORMAL)
ReleaseDC hWndControl, hDC
DeleteObject hPicture
End Function
Also, I would check the WS_EX_TRANSPARENT windowstyle for the control so that it paints last ensuring that the background of the control reflects the true color of the Form background.
Thanks for pointing that out. I'm only a journey man level gui guy. My 35 years experience dealt mostly with databases, software design and reporting. I was thinking about looking at how you add custom controls and making up an IconBox control so I don't have to ever have to think about this again. ::)
Rick