StringGadget : Problem with EventwParam()

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TeddyLM.

Hi everybody.

I'm working on a small application (with StringGadgets).
I'm looking for a way to jump from an active (and highlighted) StringGadget to another one when i press RETURN.
The problem is ... when i press the Return Key, it jumps twice (to the third one) !!?
What did i do wrong ? Some help would be nice.

Thanks.

Teddylm
A registered PB-Apprentice



Here's a small example :
;************************************
If OpenWindow(0, 200, 200, 150, 150, #PB_Window_MinimizeGadget, "TestString")
;CREATE STRINGGADGET
If CreateGadgetList(WindowID())
StringGadget (0, 40, 38, 80, 17, "String Nr.0")
StringGadget (1, 40, 58, 80, 17, "String Nr.1")
StringGadget (2, 40, 78, 80, 17, "String Nr.2")
EndIf
;SET FOCUS ON STRINGGADGET 0
Sendmessage_(GadgetID(0), #EM_SETSEL, 0, -1)
SetGadgetState(0,1)
ActivateGadget(0)
Repeat
EventID = WindowEvent()
ActualPos = EventGadgetID()
If EventwParam()=13 ;Key Return Pressed
If ActualPos = 0
SetGadgetState(0,0)
SetGadgetState(1,1)
Sendmessage_(GadgetID(1), #EM_SETSEL, 0, -1)
ActivateGadget(1)
ElseIf ActualPos = 1
SetGadgetState(1,0)
SetGadgetState(2,1)
Sendmessage_(GadgetID(2), #EM_SETSEL, 0, -1)
ActivateGadget(2)
Else
SetGadgetState(2,0)
SetGadgetState(0,1)
Sendmessage_(GadgetID(0), #EM_SETSEL, 0, -1)
ActivateGadget(0)
EndIf
EndIf
Until WindowEvent() = #PB_EventCloseWindow
EndIf



:-)
(New registered PB-Apprentice...
a long long way from home)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Please use the code-Tag (in []) to format codes.(ends by a /code in [] )

Also some thing:
SetGadgetState() on a StringGadget does nothing.

Don't use windowevent() or the programm becomes 100% of the CPU-Resource. Use waitwindowevent()

and don't use two windowevent() because both calls reads a new event, not the same. Store it i a variable and use the variable.

Also you can't use EventwParam() without testing the message-typ before. Not only the Keyboard can send a 13.

This Code work:

Code: Select all

;************************************
If OpenWindow(0, 200, 200, 150, 150, #PB_Window_MinimizeGadget, "TestString")
  ;CREATE STRINGGADGET
  If CreateGadgetList(WindowID())
    StringGadget  (0, 40, 38, 80, 17, "String Nr.0")
    StringGadget  (1, 40, 58, 80, 17, "String Nr.1")
    StringGadget  (2, 40, 78, 80, 17, "String Nr.2")
    ButtonGadget  (3, 40, 98, 80, 17, "TESTBUTTON")
  EndIf
  ;SET FOCUS ON STRINGGADGET 0  
  Sendmessage_(GadgetID(0), #EM_SETSEL, 0, -1)
  SetGadgetState(0,1)
  ActivateGadget(0) 
  Repeat
    EventID = WaitWindowEvent()
    gadget = EventGadgetID()
    eventtyp=EventType()
    If eventtyp=#PB_EventType_ReturnKey        
      Debug "return"; THIS DOESN'T WORK!
    ElseIf eventtyp=#PB_EventType_Focus            
      Debug "getfocus "+Str(gadget); A String-Gadget get the Focus
    EndIf
    
    Select eventid
      Case #wm_keydown
        If EventwParam()=13
          Select gadget
            Case 0
              ActivateGadget(1)
              Sendmessage_(GadgetID(1), #EM_SETSEL, 0, -1)
            Case 1
              ActivateGadget(2)
              Sendmessage_(GadgetID(2), #EM_SETSEL, 0, -1)
            Case 2
              ActivateGadget(0)
              Sendmessage_(GadgetID(0), #EM_SETSEL, 0, -1)
          EndSelect
        EndIf 
      Case #PB_Event_Gadget
        If gadget=3:Debug "Button pressed":EndIf
    EndSelect
  Until eventid=#PB_EventCloseWindow
EndIf
PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Don't use windowevent() or the programm becomes 100% of the CPU-Resource.
> Use waitwindowevent()

You can use WindowEvent() if you put Delay(1) before it, and CPU usage
will not be 100% anymore. Sometimes you just can't use WaitWindowEvent()
and therefore Delay(1) : WindowEvent() is a nice alternative combination.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

You should NOT have delays unless there are no event to take care of. I you do your gadgets will update real slow..
This would be the prefered way to use the WindowEvent() command:

Code: Select all

Repeat
  event = WindowEvent()
  If event
    Select event
      ...
    EndSelect
  Else
    Delay(1)
  EndIf
Until event = #PB_Event_CloseWindow
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

use settimer_(WindowID,TimerID,Time_in_ms,0)
and a #wm_timer will send every Time_in_ms.

end the timer with:
killtimer_(WindowID,TimerID)


PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TeddyLM.

Thanks everybody

It works fine now !

...seems so easy for you !
It's disappointing i didn't find myself !!!
Maybe one day ... i keep on trying !


:-)
(New registered PB-Apprentice...
a long long way from home)
Post Reply