Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Graphic = 500
ID_Timer
IDM_ZoomIn
IDM_ZoomOut
End Enum
Global hDlg,hGraphic, hGraphicDC As Dword, Zoom As Single, pt As Point
Function PBMain() As Long
Dialog New Pixels, 0, "gbZoom",,,400,400, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic,"Push", 0,0,200,200
Control Handle hDlg, %IDC_Graphic To hGraphic
Graphic Attach hDlg, %IDC_Graphic, ReDraw
Graphic Get DC To hGraphicDC
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local rc As Rect, w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
BuildAcceleratorTable
Zoom = 1
SetTimer(hDlg, %ID_Timer, 100, ByVal %NULL)
Dialog Set Text hDlg, "gbZoom " + Str$(Zoom) + "X"
Case %WM_Command
Select Case Cb.Ctl
Case %IDM_ZoomIn : Zoom = Min(10,Zoom+1) : Dialog Set Text hDlg, "gbZoom " + Str$(Zoom) + "X" : CopyScreen
Case %IDM_ZoomOut : Zoom = Max( 1,Zoom-1) : Dialog Set Text hDlg, "gbZoom " + Str$(Zoom) + "X" : CopyScreen
End Select
Case %WM_ContextMenu
Incr Zoom : If Zoom > 10 Then Zoom = 1
Dialog Set Text hDlg, "gbZoom " + Str$(Zoom) + "X" : CopyScreen
Case %WM_Timer
GetCursorPos pt
GetWindowRect hGraphic, rc
If PtInRect(rc,pt) = %False Then CopyScreen
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_Graphic, w,h
End Select
End Function
Sub CopyScreen
Local hDeskTopDC As Dword, w,h As Long
Dialog Get Client hDlg To w,h
Graphic Clear
hDeskTopDC = GetDC(%Null)
StretchBlt hGraphicDC, 0, 0, w, h, hDeskTopDC, pt.x - w/Zoom/2, pt.y - h/Zoom/2, w/Zoom, h/Zoom, %SRCCopy
ReleaseDC(%Null,hDeskTopDC)
Graphic ReDraw
Graphic Width 2
Graphic Box (w/2-10,h/2-10)-(w/2+10,h/2+10),,%Red 'optional square are center of viewing area
Graphic Width 5
Graphic Box (0,0)-(w,h),,%Black
Graphic ReDraw
End Sub
Sub BuildAcceleratorTable
Local c As Long, ac() As ACCELAPI, hAccelerator As Dword ' for keyboard accelator table values
Dim ac(1)
ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key = %VK_M : ac(c).cmd = %IDM_ZoomOut : Incr c
ac(c).fvirt = %FVIRTKEY Or %FCONTROL : ac(c).key = %VK_P : ac(c).cmd = %IDM_ZoomIn : Incr c
Accel Attach hDlg, AC() To hAccelerator
End Sub
http://www.garybeene.com/sw/gbsnippets.htm