String gadget and API multiline flag

Just starting out? Need help? Post your questions and find answers here.
swan
Enthusiast
Enthusiast
Posts: 225
Joined: Sat Jul 03, 2004 9:04 am
Location: Sydney Australia
Contact:

String gadget and API multiline flag

Post by swan »

Have used #ES_MULTILINE flag many times without a problem until recently when I added a keyboardshortcut #PB_Shortcut_Return then noticed doing so Nulled all the String Gadgets Multiline flags for that window.
Not sure if you could call this a bug because it uses an API flag.
My OS - Windoze 10 and tested on all PB versions from 5.31 to recent.

Code: Select all

  If OpenWindow(0, 0, 0, 322, 205, "StringGadget example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 8,  10, 306, 50, "Multiline StringGadget.",#ES_MULTILINE)
    CreateMenu(0, WindowID(0))
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 10) ; REM this line to see multiline work as it should.
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: String gadget and API multiline flag

Post by Little John »

Well, your code seems to work as I'd expect (PB 5.60 x64 on Windows 10).
By adding that keyboard shortcut you are "capturing" the [Return] key, so it is not handled internally by PureBasic anymore. After adding that keybord shortcut, it is the responsibility of your code what happens after the user has pressed the [Return] key. :-)

A solution might be, that your code will add the keyboard shortcut dynamically only when needed, and remove it afterwards. I have learned this clever technique from this post by netmaestro.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: String gadget and API multiline flag

Post by RASHAD »

Hi
# 1:

Code: Select all

  If OpenWindow(0, 0, 0, 322, 205, "StringGadget example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 8,  10, 306, 50, "Multiline StringGadget.",#ES_MULTILINE)
    CreateMenu(0, WindowID(0))
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 10) ; REM this line to see multiline work as it should.
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit = 1
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case 10
              If GetActiveGadget() = 0
                SendMessage_(GadgetID(0),#WM_CHAR,$D,0)
              EndIf
          EndSelect
      EndSelect
    Until Quit = 1
  EndIf
# 2:

Code: Select all

  If OpenWindow(0, 0, 0, 322, 205, "StringGadget example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 8,  10, 306, 50, "Multiline StringGadget.",#ES_MULTILINE)
    CreateMenu(0, WindowID(0))
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 10) ; REM this line to see multiline work as it should.
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Quit = 1
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case 10
              If GetActiveGadget() = 0
                keybd_event_(#VK_SHIFT,0,0,0)
                keybd_event_(#VK_RETURN,0,0,0) 
                keybd_event_(#VK_RETURN,0,#KEYEVENTF_KEYUP,0)
                keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0)
              EndIf
          EndSelect
      EndSelect
    Until Quit = 1
  EndIf
Egypt my love
swan
Enthusiast
Enthusiast
Posts: 225
Joined: Sat Jul 03, 2004 9:04 am
Location: Sydney Australia
Contact:

Re: String gadget and API multiline flag

Post by swan »

I class it as a "gotchya" nontheless. I didn't know AddKeyboardShortcut would do that, not just with Return key but any key.
Perhaps a quick mention in the docs is worthy.
Thanx Rashad again for your "quick as a flash" solutions.
But I rather liked netmaestro's solution from 2012

Code: Select all

      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_Focus
              AddKeyboardShortcut(0, #PB_Shortcut_Return, 10)
            Case #PB_EventType_LostFocus
              RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
          EndSelect
      EndSelect
Post Reply