Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
%IDC_Graphic = 500
Global hDlg, hGraphic As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "First Camera Test",300,300,400,300, %WS_OverlappedWindow Or %WS_ClipChildren To hDlg
Control Add Graphic, hDlg, %IDC_Graphic,"", 50,50,300,200, %WS_Border
Control Handle hDlg, %IDC_Graphic To hGraphic
Graphic Attach hDlg, %IDC_Graphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
' Case %WM_Size : GraphicResize_Pixels(640/480, 20)
Case %WM_Size : GraphicResize_PerCent(640/480, 0.9)
End Select
End Function
Sub GraphicResize_PerCent(AR As Single, sPerCent As Single)
Local x,y,w,h,wNew, hNew As Long
Dialog Get Client hDlg To w,h
wNew = AR / Max(AR / w, 1 / h) * sPerCent
hNew = 1 / Max(AR / w, 1 / h) * sPerCent
x = (w-wNew)/2 : y = (h-hNew)/2
Control Set Loc hDlg, %IDC_Graphic, x,y
Control Set Size hDlg, %IDC_Graphic, wNew, hNew
End Sub
Sub GraphicResize_Pixels(AR As Single, sBorder As Long)
Local x,y,w,h,wNew, hNew As Long
Dialog Get Client hDlg To w,h
w -= sBorder*2 : h -= sBorder*2
wNew = AR / Max(AR / w, 1 / h)
hNew = 1 / Max(AR / w, 1 / h)
x = sBorder + (w-wNew)/2 : y = sBorder + (h-hNew)/2
Control Set Loc hDlg, %IDC_Graphic, x,y
Control Set Size hDlg, %IDC_Graphic, wNew, hNew
End Sub
http://www.garybeene.com/sw/gbsnippets.htm