Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#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 (API DC)", 20,10,100,20
Control Add Button, hDlg, 102,"Clear", 140,25,50,20
Control Add Button, hDlg, 101,"Load (DDT DC)", 20,40,100,20
Control Add Graphic, hDlg, 200,"", 50,70,100,100
Graphic Attach hDlg, 200
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local TargetDC, hGraphic As Dword
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Control Handle Cb.Hndl, 200 To hGraphic
TargetDC = GetDC (hGraphic)
LoadBitMapFileThenDisplay (TargetDC, "cowgirl.bmp")
ReleaseDC(hGraphic,TargetDC)
Clipboard Reset
Clipboard Set Bitmap hGraphic
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_00957
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm