Date: 02-16-2022
Return to Index
created by gbSnippets
'With PowerBASIC, copying images from one graphic target to another is very
'easy. But how do you copy the image in one control to another control, when
'graphic targets are not involved?
'The use of GetDC and BitBlt API make short work of this problem!
'Primary Code:
'The GetDC API is used to get the DC to the two controls and the
'BitBlt API is used to copy the image from one DC to the other.
hDCsource = GetDC(hDCsource) 'get handle of source
hDCdest = GetDC(hDCdest) 'get handle of destination
Xdest = 0 : Ydest = 0 : w = 100 : h = 100 : Xsource = 0 : Ysource = 0
BitBlt hDCdest, Xdest, Ydest, w, h, hDCsource, Xsource, Ysource, %SRCCopy
'Compilable Example: (Jose Includes)
'This example copies an image from one control to another on demand,
'but the result is not persistent. To be persistent the code would need
'to be included in a %WM_Paint event for the dialog.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Image Test",300,300,250,250, %WS_SysMenu, 0 To hDlg
Control Add Button, hDlg, 100,"Push", 120,10,70,30
Control Add Image, hDlg, 200,"cowgirl", 10,10,100,100, %SS_Notify
Control Add Image, hDlg, 300,"", 120,120,100,100, %SS_Notify Or %WS_Border
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %STN_Clicked Then
Local hDCsource, hDCdest As DWord, Xdest, Ydest, w, h, Xsource, Ysource As Long
'get source DC
Control Handle hDlg, 200 To hDCsource 'get source handle (Image control)
hDCsource = GetDC(hDCsource) 'get handle of source
'get destination DC
Control Handle hDlg, 300 To hDCdest 'get destination handle (Image control)
hDCdest = GetDC(hDCdest) 'get handle of destination
'copy source to destination
Xdest = 0 : Ydest = 0 : w = 100 : h = 100 : Xsource = 0 : Ysource = 0
BitBlt hDCdest, Xdest, Ydest, w, h, hDCsource, Xsource, Ysource, %SRCCopy
End If
End Function
'gbs_00504
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm