Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Function PBMain() As Long
Local hDlg As Dword
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Load to Graphic Bitmap", 20,10,150,20
Control Add Button, hDlg, 101,"Load to Graphic Control", 20,40,150,20
Control Add Graphic, hDlg, 200,"", 50,70,100,100
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local TargetDC, hBitmap, hGraphic As Dword
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Graphic Bitmap New 100,100 To hBitmap
Graphic Attach hBitmap, 0
Graphic Get DC To TargetDC
LoadBitMapFileThenDisplay (TargetDC, "cowgirl.bmp")
Clipboard Reset
Clipboard Set Bitmap hBitmap
Graphic Attach Cb.Hndl, 200
Graphic Copy hBitmap, 0 'now put bitmap content into Graphic control so can see it
End If
If Cb.Msg = %WM_Command And Cb.Ctl = 101 And Cb.CtlMsg = %BN_Clicked Then
Control Handle Cb.Hndl, 200 To hGraphic
Graphic Get DC To TargetDC
LoadBitMapFileThenDisplay (TargetDC, "face.bmp")
Graphic ReDraw
Clipboard Reset
Clipboard Set Bitmap hGraphic
End If
If Cb.Msg = %WM_Command And Cb.Ctl = 102 And Cb.CtlMsg = %BN_Clicked Then Graphic Clear
End Function
Sub LoadBitMapFileThenDisplay (TargetDC As Dword, fSource As Asciiz*%Max_Path)
Local hBMP, SourceDC As Dword, bm As Bitmap
hBmp = LoadImage ( %NULL, fSource, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
SourceDC = CreateCompatibleDC (%NULL)
SelectObject (SourceDC,hBmp)
GetObject (hBmp, SizeOf(bm),bm)
BitBlt (TargetDC,0,0,bm.bmWidth,bm.bmHeight,SourceDC,0,0, %SRCCOPY)
DeleteDC(SourceDC) : DeleteObject(hBMP)
End Sub
'gbs_00958
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm