Page 1 of 1

Text is not displayed in string gadget

Posted: Mon Jan 03, 2005 1:07 pm
by Vater
Hello NG,

I got a problem that drives me nuts, I have two String Gadgets which should display the Screen Coordinates of the Mouse and if the Left Mouse Button is down.
Here is the Code

Declare.l GetMouseX()
Declare.l GetMouseY()
Declare.s LeftMouseButtonState()

#WindowID = 0
#cmd_Starten = 1
#cmd_Beenden = 2
#lbl_Ausgabe = 3
#lbl_MouseState = 4

quit.l = 0
lngEventID.l
str_XPos.s
str_YPos.s
str_Ausgabe.s
lng_Run.l = 0
bMouseState.b = 0
str_MouseState.s


If OpenWindow(#WindowID, 0, 0, 200, 150, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "ScreenCapture")
If CreateGadgetList(WindowID())
ButtonGadget(#cmd_Starten, 5, 5, 190, 20, "Starten")
ButtonGadget(#cmd_Beenden, 5, 30, 190, 20, "Beenden")
StringGadget(#lbl_Ausgabe, 5, 55, 190, 20, "")
StringGadget(#lbl_MouseState, 5, 80, 190, 20, "")
EndIf
EndIf


Repeat

lngEventID = WaitWindowEvent()

If lngEventID = #PB_Event_Gadget
Select EventGadgetID()
Case #cmd_Starten
lng_Run = 1
Case #cmd_Beenden
lng_Run = 0
EndSelect
EndIf

If lng_Run <> 0

lng_XPos = GetMouseX()
lng_YPos = GetMouseY()
str_Ausgabe = "X-Pos: " + Str(lng_XPos) + " Y-Pos: " + Str(lng_YPos)
SetGadgetText(#lbl_Ausgabe, str_Ausgabe)

str_MouseState = LeftMouseButtonState()
If Len(str_MouseState) > 0
SetGadgetText(#lbl_MouseState, str_MouseState)
Else
SetGadgetText(#lbl_MouseState, "empty")
EndIf
Delay(1)

EndIf

If lngEventID = #PB_Event_CloseWindow
quit = 1
SetGadgetText(#lbl_Ausgabe, "")
SetGadgetText(#lbl_MouseState, "")
EndIf

Until quit = 1

Procedure.l GetMouseX()

lngCheck.l = 0
pointStruct.POINT

lngCheck = GetCursorPos_(@pointStruct)
If lngCheck <> 0
ProcedureReturn pointStruct\x
EndIf

EndProcedure

Procedure.l GetMouseY()

lngCheck.l = 0
pointStruct.POINT

lngCheck = GetCursorPos_(@pointStruct)
If lngCheck <> 0
ProcedureReturn pointStruct\y
EndIf

EndProcedure

Procedure.s LeftMouseButtonState()

lngState.l
str_Message.s
VK_LBUTTON.l = 1
lngState = getasynckeystate_(VK_LBUTTON)
If lngState = 0
str_Message = "Mouse up"
Else
str_Message = "Mouse down"
EndIf
ProcedureReturn str_Message

EndProcedure

When I run the code i got no display of the Mouse Down Status. I'm absolutely desperated. PLEASE HELP.

Thanks in Advance

Posted: Mon Jan 03, 2005 1:39 pm
by Vater
Problem solved, seemed to be a too short Delay Time that caused the problem

Posted: Mon Jan 03, 2005 1:43 pm
by The_CodeMaster
All right then, but when you upload code, can you please use the code-tag!!! Else i'll have to paste the code first in a word-document before I can paste it properly in PB.

Posted: Mon Jan 03, 2005 1:47 pm
by The_CodeMaster
Problem solved, seemed to be a too short Delay Time that caused the problem
Your code worked perfectly on my machine.

My Code

Posted: Mon Jan 03, 2005 3:12 pm
by Vater
Hello NG,

sorry for that with the code tags, I am absolutely new to PB and always a little bit in a rush trying to dive into it beside working on some other projects in .NET ;-)
Anyway the problem I had seemed to be that I only can refresh the Gadgettext when the WindowEvent returns 0 (no more events in queue).

Stefan