Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "win32api.inc"
#Include "gdiplus_simple.inc"
%IDC_Button = 500
%IDC_TextBox = 501
%IDC_Graphic = 502
Global hDlg, token As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,220,280, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Load Image", 10,10,100,20
Control Add TextBox, hDlg, %IDC_TextBox,"world.gif", 10,35,180,20
Control Add Graphic, hDlg, %IDC_Graphic,"", 10,60,200,200, %WS_Border
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local FileName As WString, StartupInput As GdiplusStartupInput, w,h As Long, hDC As Dword
Select Case Cb.Msg
Case %WM_InitDialog
StartupInput.GdiplusVersion = 1 ' Initialize GDI+
GdiplusStartup(Token, StartupInput, ByVal %NULL) ' Initialize GDI+
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
Control Get Text hDlg, %IDC_TextBox To FileName
FileName = Exe.Path$ + FileName 'FileName needs full filepath
Graphic Attach hDlg, %IDC_Graphic
Graphic Get DC To hDC
LoadTheImage FileName, hDC, 0,0
LoadTheImage FileName, hDC, 50,50
LoadTheImage FileName, hDC, 100,100
Control ReDraw hDlg, %IDC_Graphic
End Select
Case %WM_Destroy
GdiPlusShutDown token
End Select
End Function
Sub LoadTheImage(FileName As WString, hDC As Dword, x As Long, y As Long)
Local pImage,pGraphics As Dword
GdipLoadImageFromFile(StrPtr(FileName), pImage) 'pImage - image object
GdipCreateFromHDC(hDC, pGraphics) 'create graphic object
GdipDrawImage(pGraphics, pImage, x,y) 'draw image at 0,0
If pImage Then GdipDisposeImage(pImage) 'GDIP cleanup
If pGraphics Then GdipDeleteGraphics(pGraphics) 'GDIP cleanup
End Sub
'gbs_01314
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm