#PB_EventType_ReturnKey

Just starting out? Need help? Post your questions and find answers here.
Armoured
Enthusiast
Enthusiast
Posts: 346
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

#PB_EventType_ReturnKey

Post by Armoured »

Hi, :)
This constant work in the new PureBasic 4.61?
I see it in the example "Gadget.pb" but doesn't work for me. :?

Thanks
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: #PB_EventType_ReturnKey

Post by ts-soft »

I think this is a bug in the helpfile :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Armoured
Enthusiast
Enthusiast
Posts: 346
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Re: #PB_EventType_ReturnKey

Post by Armoured »

Not only in the help file :D
There is an alternative?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: #PB_EventType_ReturnKey

Post by ts-soft »

Windows only!

Code: Select all

Import ""
  PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport 

EnableExplicit

Procedure StringCallback(hWnd, uMsg, wParam, lParam)
  Protected oldproc = GetProp_(hWnd, "oldproc")
 
  Select uMsg
    Case #WM_NCDESTROY
      RemoveProp_(hWnd, "oldproc")
    Case #WM_KEYDOWN
      Select GadgetType(GetDlgCtrlID_(hWnd))
        Case #PB_GadgetType_String
          If wParam = #VK_RETURN
            PB_Gadget_SendGadgetCommand(hWnd, #PB_EventType_ReturnKey)
          EndIf
      EndSelect
  EndSelect
 
  ProcedureReturn CallWindowProc_(oldproc, hWnd, uMsg, wParam, lParam)
EndProcedure

Procedure SubClassGadget(ID)
  Protected oldproc = SetWindowLongPtr_(GadgetID(ID), #GWL_WNDPROC, @StringCallback())
  ProcedureReturn SetProp_(GadgetID(ID), "oldproc", oldproc)
EndProcedure


; Example

OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   
ButtonGadget(0, 10, 10, 200, 20, "Default Button")
StringGadget(1, 10, 40, 200, 20, "")
StringGadget(2, 10, 70, 200, 20, "")
OptionGadget(3, 10, 100, 60, 20, "Option 1")
OptionGadget(4, 10, 130, 60, 20, "Option 2")
OptionGadget(5, 10, 160, 60, 20, "Option 3")
SetGadgetState(3, 1)
SubClassGadget(1)
SubClassGadget(2)
SetActiveGadget(0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow : Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1, 2
          Select EventType()
            Case #PB_EventType_ReturnKey
              Debug "Return pressed"
          EndSelect
      EndSelect
  EndSelect
ForEver
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Armoured
Enthusiast
Enthusiast
Posts: 346
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Re: #PB_EventType_ReturnKey

Post by Armoured »

ts-soft wrote:Windows only!

Code: Select all

Import ""
  PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport 

EnableExplicit

Procedure StringCallback(hWnd, uMsg, wParam, lParam)
  Protected oldproc = GetProp_(hWnd, "oldproc")
 
  Select uMsg
    Case #WM_NCDESTROY
      RemoveProp_(hWnd, "oldproc")
    Case #WM_KEYDOWN
      Select GadgetType(GetDlgCtrlID_(hWnd))
        Case #PB_GadgetType_String
          If wParam = #VK_RETURN
            PB_Gadget_SendGadgetCommand(hWnd, #PB_EventType_ReturnKey)
          EndIf
      EndSelect
  EndSelect
 
  ProcedureReturn CallWindowProc_(oldproc, hWnd, uMsg, wParam, lParam)
EndProcedure

Procedure SubClassGadget(ID)
  Protected oldproc = SetWindowLongPtr_(GadgetID(ID), #GWL_WNDPROC, @StringCallback())
  ProcedureReturn SetProp_(GadgetID(ID), "oldproc", oldproc)
EndProcedure


; Example

OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   
ButtonGadget(0, 10, 10, 200, 20, "Default Button")
StringGadget(1, 10, 40, 200, 20, "")
StringGadget(2, 10, 70, 200, 20, "")
OptionGadget(3, 10, 100, 60, 20, "Option 1")
OptionGadget(4, 10, 130, 60, 20, "Option 2")
OptionGadget(5, 10, 160, 60, 20, "Option 3")
SetGadgetState(3, 1)
SubClassGadget(1)
SubClassGadget(2)
SetActiveGadget(0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow : Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1, 2
          Select EventType()
            Case #PB_EventType_ReturnKey
              Debug "Return pressed"
          EndSelect
      EndSelect
  EndSelect
ForEver
Thanks ts-soft!
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: #PB_EventType_ReturnKey

Post by falsam »

Example with #PB_EventType_ReturnKey (Not very cool !!!)

Code: Select all

Enumeration
  #MainForm
  #String1
  #String2
EndEnumeration

OpenWindow(#Mainform, 0, 0, 320 , 200, "Exemple #PB_EventType_ReturnKey")
StringGadget(#String1, 10, 45, 300, 24, "",#ES_MULTILINE)
StringGadget(#String2, 10, 70, 300, 24, "",#ES_MULTILINE)
SetActiveGadget(#String1)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #String1 
          If EventType()=#PB_EventType_ReturnKey
            SetActiveGadget(#String2)
          EndIf
          
        Case #String2
          If EventType()=#PB_EventType_ReturnKey
            SetActiveGadget(#String1)
          EndIf
          
      EndSelect
      
  EndSelect
ForEver
Another example with a multiline string. 4 lines maximum. Message at End Of Line.

Code: Select all

Enumeration
  #MainForm
  #String
EndEnumeration

OpenWindow(#Mainform, 0, 0, 320 , 200, "Exemple #PB_EventType_ReturnKey")
TextGadget(#PB_Any, 10, 20, 100, 22, "multiline string")
StringGadget(#String, 10, 45, 300, 60, "Four lines in this string", #ES_MULTILINE|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
      
    Case #PB_Event_Gadget
      If EventGadget()=#String And EventType()=#PB_EventType_ReturnKey
        MessageRequester("Information", "End of String")
      EndIf
  EndSelect
ForEver

Alternative

Code: Select all

Enumeration
  #MainForm
  #String1
  #String2
  #Kbd_Return
EndEnumeration

OpenWindow(#Mainform, 0, 0, 320 , 200, "Exemple #PB_EventType_ReturnKey")
StringGadget(#String1, 10, 45, 300, 24, "",#ES_MULTILINE)
StringGadget(#String2, 10, 70, 300, 24, "",#ES_MULTILINE)
AddKeyboardShortcut(#MainForm, #PB_Shortcut_Return, #Kbd_Return) 
SetActiveGadget(#String1)

Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_Menu
      Select EventMenu()
        Case #Kbd_Return
          Select GetActiveGadget()
            Case #String1 : SetActiveGadget(#String2)
            Case #String2 : SetActiveGadget(#String1)
          EndSelect
      EndSelect
      
    Case #PB_Event_CloseWindow
      End
      
    Case #PB_Event_Gadget
      
  EndSelect
ForEver

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
Armoured
Enthusiast
Enthusiast
Posts: 346
Joined: Mon Jan 26, 2004 11:39 am
Location: ITALY
Contact:

Re: #PB_EventType_ReturnKey

Post by Armoured »

And thanks to you falsam! :)
Post Reply