Page 1 of 1

Select text in inputRequester by default without pressing tab?

Posted: Sat Jun 29, 2024 3:04 am
by Quin
Hi,
In my app, I have an InputRequester that has some initial content. I noticed in the latest PB 6.11, if I press tab and then refocus the text field with the initial value it's automatically highlighted, but it's not when I initially open the requester. Is there a way to automatically select it, perhaps by getting a handle to the StringGadget and sending a WM_SETSEL message?
Thanks.

Re: Select text in inputRequester by default without pressing tab?

Posted: Sat Jun 29, 2024 4:27 am
by RASHAD
Hi

Code: Select all

CompilerIf #PB_Compiler_Thread = 0
  MessageRequester("Info","Threadsafe compiler option not set",#MB_ICONINFORMATION)
  End
CompilerEndIf

Global Thread

Procedure Input_Requster(Par)
  Repeat
      Delay(10)
      hwnd = FindWindow_(0, "Input Opacity Value")
      hEdit = FindWindowEx_(hwnd, #Null, "Edit", #Null)
      If hEdit
        SendMessage_(hEdit,#EM_SETSEL,0,-1)
        KillThread(Thread)
      EndIf
  ForEver
EndProcedure

Thread = CreateThread(@Input_Requster(), 0)

Input$ = InputRequester("Input Opacity Value", "Opacity from 0  to 255 ", "Opacity 128")

Re: Select text in inputRequester by default without pressing tab?

Posted: Sat Jun 29, 2024 4:59 am
by Quin
Thank you, this worked! :)

Re: Select text in inputRequester by default without pressing tab?

Posted: Sat Jun 29, 2024 5:34 am
by RASHAD
In case you don't want to use Thread

Code: Select all

Global Hook,hWnd

Procedure HookCB( uMsg , wParam , lParam)   
  Select uMsg
    Case #HCBT_ACTIVATE
        hWnd = wparam
        
    Case #HCBT_CREATEWND
      If hwnd
        hEdit = FindWindowEx_(hwnd, #Null, "Edit", #Null)
        SendMessage_(hEdit,#EM_SETSEL,0,-1)
      EndIf    
  EndSelect  
  ProcedureReturn #False
EndProcedure

Hook = SetWindowsHookEx_( #WH_CBT, @ HookCB() , 0, GetCurrentThreadId_ ())
Input$ = InputRequester("Input Opacity Value", "Opacity from 0  to 255 ", "Opacity 128")
UnhookWindowsHookEx_ (Hook) 

Re: Select text in inputRequester by default without pressing tab?

Posted: Sat Jun 29, 2024 5:45 am
by Quin
RASHAD wrote: Sat Jun 29, 2024 5:34 am In case you don't want to use Thread

Code: Select all

Global Hook,hWnd

Procedure HookCB( uMsg , wParam , lParam)   
  Select uMsg
    Case #HCBT_ACTIVATE
        hWnd = wparam
        
    Case #HCBT_CREATEWND
      If hwnd
        hEdit = FindWindowEx_(hwnd, #Null, "Edit", #Null)
        SendMessage_(hEdit,#EM_SETSEL,0,-1)
      EndIf    
  EndSelect  
  ProcedureReturn #False
EndProcedure

Hook = SetWindowsHookEx_( #WH_CBT, @ HookCB() , 0, GetCurrentThreadId_ ())
Input$ = InputRequester("Input Opacity Value", "Opacity from 0  to 255 ", "Opacity 128")
UnhookWindowsHookEx_ (Hook) 
Even better :)
You're a wizard!