#VK_RETURN in Stringgadget

Just starting out? Need help? Post your questions and find answers here.
Amnesty
User
User
Posts: 54
Joined: Wed Jul 04, 2007 4:34 pm
Location: Germany

#VK_RETURN in Stringgadget

Post by Amnesty »

Hi everybody,

the way I use #VK_RETURN in my little code, causes this great Windows xylophone sound when you press return. It's not a real error, but users can suppose, that something wrong, because messageboxes use the same sound. Does anybody know, how to avoid it ?

Ofcourse I could use Addkeyboardshortcut, but in this case I can't use this great PURELVSORT library to edit Listicon cells, because return is blocked in this case. :oops:

Code: Select all

If OpenWindow(0, 0, 0, 322, 205, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  StringGadget(0, 8,  10, 306, 20, "")
  SetActiveGadget(0)
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #WM_KEYDOWN
      If EventwParam() = #VK_RETURN
        Debug "Return with great xylophone sound"
      EndIf
    EndSelect
  Until event = #PB_Event_CloseWindow
EndIf
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You're in luck. The StringGadget supports two very handy events, #PB_EventType_Focus and #PB_EventType_LostFocus. So you can have your shortcut active only when the string gadget has the focus and at no other time:

Code: Select all

Select Event
  Case #PB_Event_Gadget
    Select gadget
      Case mystring
        Select EventType()
          Case #PB_EventType_Focus
            ;AddKeyboardShortcut([..])
          Case #PB_EventType_LostFocus
            ;RemoveKeyboardShortcut([..])
        EndSelect
    EndSelect
EndSelect
..and the ding is defeated. Amnesty 1, Gates 0.
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: #VK_RETURN in Stringgadget

Post by PB »

> Does anybody know, how to avoid it ?

It's in the Coding Questions FAQ:
http://www.purebasic.fr/english/viewtopic.php?t=4876

And your answer (from the FAQ) is here:
http://www.purebasic.fr/english/viewtopic.php?t=3802
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Unsupported Windows-only stuff in the FAQ? Isn't even identified as such.
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Unsupported Windows-only stuff in the FAQ?

SendMessage is documented/supported by Windows.

> Isn't even identified as such

Who said it had to be?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: #VK_RETURN in Stringgadget

Post by PB »

> It's not a real error, but users can suppose, that something wrong

Well it is an error, because single-line StringGadgets can't have the Enter key
used on them because they're not multi-line. That's why they beep like that.
Amnesty
User
User
Posts: 54
Joined: Wed Jul 04, 2007 4:34 pm
Location: Germany

Post by Amnesty »

Thank you for replies. I'm satisfied.

Thank you PB for this link to FAQ. Mea Culpa, I 've missed that thread, because I haven't searched with the right keywords. (ding dong)
User avatar
the.weavster
Addict
Addict
Posts: 1577
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Post by the.weavster »

Control spy is an extremely useful tool for Windows events, SendMessage() etc... http://msdn2.microsoft.com/en-us/library/bb773165.aspx
Post Reply