Gadgets only work sometimes!???

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 momo.

Hi!
The Gadgets i put on a window only work sometimes
sometimes Ì've to click once sometimes twice And so on
Here is the code:


InitKeyboard()
InitSprite()
OpenWindow(0,50,50,700,500,#PB_window_minimizegadget | #PB_window_maximizegadget | #PB_Window_sizegadget,"dsjkfg")
momo = WindowID()

CreateGadgetList(momo)
ButtonGadget(0,10,10,300,100,"sljdh")
CheckBoxGadget(1,500,200,40,40,"ldskjf")

Repeat
ExamineKeyboard()
WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 0
OpenWindow(1,20,20,100,50,#PB_window_minimizegadget | #PB_window_maximizegadget | #PB_Window_sizegadget,"ksf")
Case 1
MessageRequester("checkbox","checkbox",0)
EndSelect
EndIf
EventID.l = WaitWindowEvent()
If eventID.l = #PB_eventclosewindow
ende = 1
EndIf

Until KeyboardPushed(#PB_key_escape)

Don't Look so stupid
I've got no Signature!!
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 plouf.

your code its a bit wrong a) you should use one waitwindowevent() as it hangs the problem twice waiting for a command and the first one does not event put the result in a varaible
second i suggest to use keyboard event search the forum there are some examples somewhere . since keyboardpushed() command return true only if escape is pushed the time it check and since you program, waits for a event you can press escape forever without quit
here is a working one

Code: Select all

InitKeyboard()
InitSprite()
OpenWindow(0,50,50,700,500,#PB_window_minimizegadget | #PB_window_maximizegadget | #PB_Window_sizegadget,"dsjkfg")
momo = WindowID()
CreateGadgetList(momo)
ButtonGadget(0,10,10,300,100,"sljdh")
CheckBoxGadget(1,500,200,40,40,"ldskjf")
Repeat 
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 0
  OpenWindow(1,20,20,100,50,#PB_window_minimizegadget | #PB_window_maximizegadget | #PB_Window_sizegadget,"second")
Case 1
  MessageRequester("checkbox","checkbox",0)
EndSelect 
EndIf 
;EventID.l = WaitWindowEvent()
If eventID = #PB_eventclosewindow
  ende = 1
EndIf 
Until ende 
End
Christos
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 freak.

Each WaitWindowEvent() returns 1 event, so if you youse it twice, each call receives only every second event that is happening, that is why you sometimes have to push twice.
ploufs way to store it in a Variable first is the right one here.

The Keyboard functions you use (KeyboardPushed() for example) are DirectX functions intended to be used with Fullscreen programs (like Games) using them like this yould mean, that every user needs to have DirectX 7 installed to use you application. (applications should never need that)

Instead, please have a look at the 'AddKeyboardShortcut()' function in the 'Window' library.
Whith it you can assign a Keyboard Shortcut to a menu item. Note that you don't need to have a menu to use this.

Example:
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 1)

This now assigns a menu item number 1 to the ESC key for your Window 0.
The WaitWindowEvent() now returns #PB_EventMenu as Event and 1 as EventMenuID() if the user pressed ESC.

Code then looks like this:

Code: Select all

OpenWindow(0,50,50,700,500,#PB_window_minimizegadget | #PB_window_maximizegadget | #PB_Window_sizegadget,"dsjkfg")
momo = WindowID()
CreateGadgetList(momo)
ButtonGadget(0,10,10,300,100,"sljdh")
CheckBoxGadget(1,500,200,40,40,"ldskjf")

AddKeyboardShortcut(0, #PB_Shortcut_Escape, 1) 

Repeat 
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 0
  OpenWindow(1,20,20,100,50,#PB_window_minimizegadget | #PB_window_maximizegadget | #PB_Window_sizegadget,"second")
Case 1
  MessageRequester("checkbox","checkbox",0)
EndSelect 
EndIf 
;EventID.l = WaitWindowEvent()
If eventID = #PB_eventclosewindow
  ende = 1
EndIf 

If EventID = #PB_EventMenu
  If EventMenuID() = 1
    ende = 1
  EndIF
EndIf
Until ende 
End

Hope that helps...

Timo

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 momo.

Thank you very much!!!
I only checked the functions with these code.
but you reminded me of the Directx thing thank you!!

Don't Look so stupid
I've got no Signature!!
Post Reply