Uses "UI"
Uses "gdip"
Uses "File"
Randomize
' -- ID numbers of controls
Begin ControlID
%cCanvasDB
%bModifyBitmap
%bClose
End ControlID
' -- Create dialog here
Function TBMain()
Local hDlg As DWord
Dialog New 0, "Managing canvas bitmap",-1,-1, 350, 300, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg
' -- Place controls here
Dim cx, cy As Long
Dialog Pixels hDlg, 400, 400 To Units cx, cy
Control Add Canvas, hDlg, %cCanvasDB, "", 0, 0, cx, cy
Control Add Button, hDlg, %bModifyBitmap, "Redraw", 10+cx, 5 , 50, 14, Call bModifyBitmapProc
Control Add Button, hDlg, %bClose , "Close" , 10+cx, cy+5-14, 50, 14, Call bCloseProc
Dialog Show Modal hDlg, Call dlgProc
End Function
' -- Callback for dialog
CallBack Function dlgProc()
' -- Test for messages
Select Case CBMSG
Case %WM_INITDIALOG
Canvas_Attach(CBHNDL, %cCanvasDB, %FALSE)
DrawGraphics(CBHNDL)
Canvas_Redraw
Case %WM_CLOSE
' -- Put code to be executed before dialog end here
End Select
End Function
' -- Callback for close button
CallBack Function bCloseProc()
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function
CallBack Function bModifyBitmapProc()
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
Canvas_Attach(CBHNDL, %cCanvasDB, %TRUE)
Canvas_Clear(Rgb(0,0,0), %CANVAS_FILLSTYLE_SOLID)
DrawGraphics(CBHNDL)
End If
End If
End Function
Sub DrawGraphics(ByVal hDlg As DWord)
Static lNextImage As Long
Dim pGraphics As DWord
Dim hDC As DWord
Dim pImage As DWord
Dim nFiles As Long
Dim sFiles() As String
nFiles = DIR_ListArray(sFiles, APP_ScriptPath & "images\", "*.JPG", %FILE_NORMAL Or %FILE_ADDPATH)
If nFiles Then
hDC = Canvas_GetDC
pGraphics = GDIp_CreateFromHDC(hdc)
lNextImage += 1
If lNextImage > nFiles Then
lNextImage = 1
End If
Dialog Set Text hDlg, Format$(lNextImage) & " " & sFiles(lNextImage)
pImage = GDIp_LoadImageFromFile(sFiles(lNextImage))
GDIp_DrawImage(pGraphics, pImage, 1, 1)
'---Release GDI image
GDIp_DisposeImage(pImage)
GDIp_DeleteGraphics(pGraphics)
Canvas_Redraw
End If
End Sub
Bookmarks