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
#Debug Error On
#Include "Win32API.inc"
Global hDlg,hFontA,hFontB As Dword
%IDC_LabelA = 500
%IDC_LabelB = 501
%IDC_Line = 502
Function PBMain() As Long
Dialog New Pixels, 0, "Label Align",300,300,250,100, %WS_OverlappedWindow To hDlg
Font New "Arial",14,1 To hFontA
Font New "Arial",32,1 To hFontB
Control Add Label, hDlg, %IDC_LabelA, "gWord", 20,50,150,50
Control Set Font hDlg, %IDC_LabelA, hFontA
Control Add Label, hDlg, %IDC_LabelB, "gWord", 120,50,150,50
Control Set Font hDlg, %IDC_LabelB, hFontB
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
Resize
End Select
End Function
Sub Resize
Local y,Baseline As Long, temp$, TM As TextMetric, hDC As Dword
Baseline = 50 : temp$ = "gWord"
Control Add Line, hDlg, %IDC_Line, "", 10,Baseline,230,1
'hidden bitmap so can use GetTextMetrics
Local hBMP As Dword
Graphic Bitmap New 100,100 To hBMP
Graphic Attach hBMP,0
Graphic Get DC To hDC
'locate 1st label
Graphic Set Font hFontA
GetTextMetrics hDC, TM
y = Baseline-TM.tmHeight+TM.tmDescent
Control Set Loc hDlg, %IDC_LabelA,10,y
'locate 2nd label
Graphic Set Font hFontB
GetTextMetrics hDC, TM
y = Baseline-TM.tmHeight+TM.tmDescent
Control Set Loc hDlg, %IDC_LabelB,90,y
'cleanup
Graphic Bitmap End
End Sub
'gbs_01051
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm