Date: 02-16-2022
Return to Index
created by gbSnippets
'Primary Code:
'Syntax: sResult$ = InputBox$(prompt$ [[, title$], default$] [, xpos%, ypos%])
Result$ = InputBox$("Please enter your name.", "Name Entry", "Gary Beene", CenterX,CenterY
'use the function below to get the CenterX/CenterY values.
'BoxX and BoxY are the InputBox dimensions
Sub CenterOverDialog(BoxX as Long, BoxY as Long, CenterX As Long, CenterY as Long)
'gets top/left position to center Box over Dialog
'you need to know, or at least estimate, the Box size
Local x as Long, y as Long, w as Long, h as Long
Dialog Get Loc hDlg To x,y
Dialog Get Size hDlg To w,h
CenterX = x + (w-BoxX)/2
CenterY = y + (h-BoxY)/2
End Sub
'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,400,400, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local x as Long, y as Long, result$
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
CenterOverDialog(300,225,x,y) 'inputbox is 300x225
result$ = InputBox$ ("Am I centered?", "InputBox Test", "yes?",x,y)
End If
End Function
Sub CenterOverDialog(BoxX as Long, BoxY as Long, CenterX As Long, CenterY as Long)
'gets top/left position to center Box over Dialog
'you need to know, or at least estimate, the Box size
Local x as Long, y as Long, w as Long, h as Long
Dialog Get Loc hDlg To x,y
Dialog Get Size hDlg To w,h
CenterX = x + (w-BoxX)/2
CenterY = y + (h-BoxY)/2
End Sub
'gbs_00109
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm