Date: 02-16-2022
Return to Index
created by gbSnippets
'Note: This code does not work if Graphic Control has a border
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_Graphic = 500
Global hDlg As Dword, borderH, captionH As Long, AspectRatio As Single
Function PBMain() As Long
AspectRatio = 1.0 'desired aspect ratio of graphic control
Dialog New Pixels, 0, "Test Code",300,300,300,300/AspectRatio, %WS_OverlappedWindow To hDlg
captionH = Metrics(Caption)
borderH = Metrics(Frame.Resize.Y)
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,100,100 'sized in WM_Size
Graphic Attach hDlg, %IDC_Graphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long, prc As Rect Ptr
Select Case Cb.Msg
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_Graphic, w, h
Graphic Render "cowgirl.bmp", (0,0)-(w-1,h-1)
Dialog Set Text hDlg, Str$(w) + Str$(h) + Format$(w/h," 0.0 ")
Case %WM_Sizing
prc = Cb.LParam : w = (@prc.nRight - @prc.nLeft) : h = (@prc.nBottom - @prc.nTop)
Select Case Cb.WParam
Case %WMSZ_TopLeft :
@prc.nTop = @prc.nBottom - (w / AspectRatio) - captionH
Case %WMSZ_Top, %WMSZ_Bottom, %WMSZ_TopRight
@prc.nRight = @prc.nLeft + ((h-captionH) * AspectRatio)
Case %WMSZ_Left, %WMSZ_Right, %WMSZ_BottomLeft, %WMSZ_BottomRight
@prc.nBottom = @prc.nTop + (w / AspectRatio) + captionH
End Select
Function = %True
End Select
End Function
'gbs_00745
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm