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_Button = 500
IDC_TextBox = 501
End Enum
Global hDlg,ghHook As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 50,10,100,20
Control Add TextBox, hDlg, %IDC_TextBox, "Start with this!", 20,40,160,150
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
ghHook = SetWindowsHookEx(%WH_CBT, CodePtr(InputBoxProc), GetModuleHandle(""), GetCurrentThreadId)
Control Get Text hDlg, %IDC_TextBox To temp$
temp$ = InputBox$("", "Instructions", temp$, 100,100)
Control Set Text hDlg, %IDC_TextBox, temp$ 'Len(temp$)=0 when ESC is presed
End Select
End Select
End Function
Function InputBoxProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' If Debug Then Txt.Print FuncName$ '<---- turned off by choice
Local szTemp As WStringZ * %Max_Path, cw As CBT_CREATEWND Ptr, cst As CREATESTRUCT Ptr, iStyle As Long
Function = CallNextHookEx(ByVal ghHook, ByVal nCode, ByVal wParam, ByVal lParam)
If nCode < 0 Then Exit Function
If nCode = %HCBT_ACTIVATE Then UnhookWindowsHookEx ghHook
If nCode = %HCBT_CREATEWND Then
cw = lParam : cst = @cw.lpcs ' get a pointer to the CREATESTRUCT struct
GetClassName wParam, szTemp, %Max_Path ' for each window / control as it is created
If UCase$(szTemp) = "BUTTON" Then
Select Case @cst.hMenu
Case %IdOk : @cst.x=30:@cst.y=220:@cst.cx=60
Case %IdCancel : @cst.x=120:@cst.y=220:@cst.cx=60
End Select
End If
If UCase$(szTemp) = "STATIC" Then @cst.x = 400 'prompt moved out of the way
If UCase$(szTemp) = "EDIT" Then
@cst.x = 10 : @cst.y = 10 : @cst.cx = 175 : @cst.cy = 200
iStyle = GetWindowLong(wParam,%GWL_Style)
SetWindowLong wparam, %GWL_Style, iStyle Or %ES_MultiLine Or %ES_WantReturn
End If
If UCase$(szTemp) = "#32770" Then @cst.cx = 200 : @cst.cy = 280 'dialog
End If
End Function
'gbs_01228
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm