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"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,220,250, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 200, "Push", 10,10,60,20
Control Add Button, hDlg, 201, "Push", 90,10,60,20
Control Add Graphic, hDlg, 300, "", 10,40,200,200, %WS_Border
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hBMP, hBitMap,hDesktopDC,hMemoryDC,hGraphicDC As Dword, bm As Bitmap, ddw,ddh As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 200 Then
'get handle to desktop DC
hDesktopDC = GetDC(%Null)
'create compatible memory DC, with bitmap selected into it
Desktop Get Size To ddw,ddh
hMemoryDC = CreateCompatibleDC(hDesktopDC)
hBMP = CreateCompatibleBitmap(hDesktopDC,ddw,ddh)
SelectObject(hMemoryDC,hBMP)
hBitMap = GetCurrentObject(hMemoryDC, %OBJ_BITMAP)
If hBitMap Then
GetObject hBitMap, SizeOf(bm), bm
MsgBox Str$(bm.bmWidth) + Str$(bm.bmHeight)
End If
'copy desktop DC into memory DC
BitBlt hMemoryDC,0,0,ddw,ddh,hDesktopDC,0,0,%SrcCopy
'copy memory DC into graphic control DC
Graphic Attach hDlg, 300, ReDraw
Graphic Get DC To hGraphicDC
BitBlt hGraphicDC,0,0,ddw,ddh,hMemoryDC,0,0,%SrcCopy
Graphic ReDraw
ReleaseDC(%Null, hDeskTopDC)
End If
If Cb.Msg = %WM_Command And Cb.Ctl = 201 Then
'get handle to desktop DC
hDesktopDC = GetDC(%Null)
'copy memory DC into graphic control DC
Graphic Attach hDlg, 300, ReDraw
Graphic Get DC To hGraphicDC
Desktop Get Size To ddw,ddh
BitBlt hGraphicDC,0,0,ddw,ddh,hDesktopDC,0,0,%SrcCopy
Graphic ReDraw
ReleaseDC(%Null, hDeskTopDC)
End If
End Function
'gbs_00941
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm