Select text in inputRequester by default without pressing tab?

Just starting out? Need help? Post your questions and find answers here.
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Select text in inputRequester by default without pressing tab?

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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")
Egypt my love
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

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

Post by Quin »

Thank you, this worked! :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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) 
Egypt my love
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

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

Post 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!
Post Reply