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$, x,y As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
Dialog Get Loc hDlg To x,y
ghHook = SetWindowsHookEx(%WH_CBT, CodePtr(InputBoxProc), GetModuleHandle(""), GetCurrentThreadId)
Control Get Text hDlg, %IDC_TextBox To temp$
temp$ = InputBox$("", "Input Box", temp$, x+100,y+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=20:@cst.y=40:@cst.cx=60
Case %IdCancel : @cst.x=110:@cst.y=40:@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 = 30
iStyle = GetWindowLong(wParam,%GWL_Style)
SetWindowLong wparam, %GWL_Style, iStyle Or %ES_Password
End If
If UCase$(szTemp) = "#32770" Then @cst.cx = 200 : @cst.cy = 100 'dialog
End If
End Function
'gbs_01455
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm