Date: 02-16-2022
Return to Index
created by gbSnippets
'uses memory bitmap as buffer
'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
%IDC_Timer = 503
Global hDlg, hBMP, token, hDC As Dword, FileName As WString
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,190,220,190, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic,"", 10,10,200,170, %WS_Border
Graphic Bitmap New 200,170 To hBMP
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local StartupInput As GdiplusStartupInput, w,h As Long
Static x1,dx1,x2,dx2 As Long, FileName As WString
Select Case Cb.Msg
Case %WM_InitDialog
StartupInput.GdiplusVersion = 1 ' Initialize GDI+
GdiplusStartup(Token, StartupInput, ByVal %NULL) ' Initialize GDI+
SetTimer(hDlg, %IDC_Timer, 25, ByVal %NULL)
FileName = Exe.Path$ + "world.gif" 'FileName needs full filepath
dx1 = 3 : dx2 = -3 : x1 = 10 : x2 = 100
Case %WM_Timer
x1 = x1 + dx1
If x1 < 0 Then x1 = 0 : dx1 = -1 * dx1
If x1 > 105 Then x1 = 105 : dx1 = -1 * dx1
x2 = x2 + dx2
If x2 < 0 Then x2 = 0 : dx2 = -1 * dx2
If x2 > 105 Then x2 = 105 : dx2 = -1 * dx2
Graphic Attach hBMP, 0
Graphic Get DC To hDC
Graphic Clear
LoadTheImage FileName, x1,10
LoadTheImage FileName, x2,70
Graphic Attach hDlg, %IDC_Graphic
Graphic Copy hBMP, 0
Case %WM_Destroy
GdiPlusShutDown token
End Select
End Function
Sub LoadTheImage(FileName As WString, 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_01315
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm