I am trying to render a PNG image on a window, which has other controls on it. Below is the standard code built using PureFORM:
Code: Select all
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Image_0
#Button_1
EndEnumeration
;}
;{ Images
Enumeration
#Image_Image_0
EndEnumeration
;}
;{ Included Images
DataSection
Image_Image_0:
IncludeBinary "imagefilename"
EndDataSection
;}
;{ Image Plugins
UsePNGImageDecoder()
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 415, 196, 414, 364, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
If CreateGadgetList(WindowID(#Window_0))
ImageGadget(#Image_0, 15, 15, 384, 291, CatchImage(#Image_Image_0, ?Image_Image_0), #PB_Image_Border)
ButtonGadget(#Button_1, 310, 325, 85, 25, "Close")
EndIf
EndIf
EndProcedure
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Image_0
ElseIf EventGadget = #Button_1
CloseWindow(#Window_0)
Break
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}
http://purebasic.fr/english/viewtopic.php?t=32298
...and the code I have translated into procedures [to work with my existing code]:
Code: Select all
Global str_logofilename$
Procedure StringToBStr (str_logofilename$)
Protected Unicode$ = Space(Len(str_logofilename$)* 2 + 2)
Protected bstr_string.l
PokeS(@Unicode$, str_logofilename$, -1, #PB_Unicode)
bstr_string = SysAllocString_(@Unicode$)
ProcedureReturn bstr_string
EndProcedure
ProcedureDLL LoadDecodedImage(str_logofilename$)
CompilerIf Defined(GdiplusStartupInput, #PB_Structure) = 0
Structure GdiplusStartupInput
GdiPlusVersion.l
*DebugEventCallback.Debug_Event
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
CompilerEndIf
OpenLibrary(0, "gdiplus.dll")
input.GdiplusStartupInput
input\GdiPlusVersion = 1
CallFunction(0, "GdiplusStartup", @*token, @input, #Null)
CallFunction(0, "GdipCreateBitmapFromFile", StringToBStr(str_logofilename$), @*image)
CallFunction(0, "GdipGetImageWidth", *image, @Width.l)
CallFunction(0, "GdipGetImageHeight", *image, @Height.l)
CallFunction(0, "GdipCreateHBITMAPFromBitmap", *image, @imageid.l, -1)
CallFunction(0, "GdipDisposeImage", *image)
CallFunction(0, "GdiplusShutdown", *token)
CloseLibrary(0)
return_imagenumber = CreateImage(#PB_Any, width, height, 32)
StartDrawing(ImageOutput(return_imagenumber))
DrawAlphaImage(imageid,0,0)
StopDrawing()
ProcedureReturn return_imagenumber
EndProcedure
Procedure LoadLogo()
img_logo = LoadDecodedImage("imagefilename")
OpenWindow(#Window_Logo,int_mainwindowposx,int_mainwindowpos,300,300,"",#PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowLong_(WindowID(#Window_Logo),#GWL_EXSTYLE,GetWindowLong_(WindowID(#Window_Logo),#GWL_EXSTYLE)|#WS_EX_LAYERED)
CreateGadgetList(WindowID(#Window_Logo))
hDC = StartDrawing(ImageOutput(img_logo))
sz.SIZE
sz\cx = ImageWidth(img_logo)
sz\cy = ImageHeight(img_logo)
ContextOffset.POINT
BlendMode.BLENDFUNCTION
BlendMode\SourceConstantAlpha = 255
BlendMode\AlphaFormat = 1
UpdateLayeredWindow_(WindowID(#Window_Logo), 0, 0, @sz, hDC, @ContextOffset, 0, @BlendMode, 2)
StopDrawing()
ImageGadget(0,0,0,0,0,ImageID(img_logo))
HideWindow(#Window_Logo,0)
Repeat
Event = WaitWindowEvent()
Delay(10)
Until Event = #PB_Event_CloseWindow
End
EndProcedure
Messy.
Any ideas/suggestions? Thanks

Sample apha-layer image URL: http://www.w3.org/Graphics/PNG/alphatest.png