Page 1 of 1

#VK_RETURN in Stringgadget

Posted: Thu Nov 29, 2007 4:54 pm
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

Posted: Thu Nov 29, 2007 5:22 pm
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.

Re: #VK_RETURN in Stringgadget

Posted: Thu Nov 29, 2007 8:46 pm
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

Posted: Thu Nov 29, 2007 9:04 pm
by netmaestro
Unsupported Windows-only stuff in the FAQ? Isn't even identified as such.

Posted: Fri Nov 30, 2007 10:00 am
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?

Re: #VK_RETURN in Stringgadget

Posted: Fri Nov 30, 2007 10:12 am
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.

Posted: Fri Nov 30, 2007 1:31 pm
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)

Posted: Fri Nov 30, 2007 3:14 pm
by the.weavster
Control spy is an extremely useful tool for Windows events, SendMessage() etc... http://msdn2.microsoft.com/en-us/library/bb773165.aspx