|
Post by Brandon Parker on Jul 13, 2024 10:14:21 GMT -5
Walt, The FN.KeyState() function below could result in issues. In Liberty BASIC, one should never set a Timer for a branch label within a function and then Wait. There could be a scenario where LB branches from the Wait statement to another code section. If the Timer is executed on another Wait/Scan statement outside the function it will cause an error where the Branch Label is not found. Or, if some other control's branch label (if using labels) is activated while waiting inside the FN.KeyState() function, it would not be found either.
FUNCTION FN.KeyState(Vkey)
[SET.KEY.TIMER] TIMER 150, [CHECK.STATE] WAIT
[CHECK.STATE] TIMER 0 CALLDLL #user32, "GetAsyncKeyState", Vkey AS ULONG, KeyState AS SHORT
IF KeyState THEN RetVal = FN.CheckCoords() IF RetVal THEN PRINT CoordName$(0, 4), CoordName$(0, 5) FN.KeyState = 1 EXIT FUNCTION END IF END IF
GOTO [SET.KEY.TIMER] END FUNCTION
{:0)
Brandon Parker
|
|
|
Post by Brandon Parker on Jul 14, 2024 10:13:34 GMT -5
Adding to what Rod says, if you do use the "Sleep" API call in a loop within the function and do not have a "Wait" or "Scan" within the loop, LB cannot branch elsewhere since messages are only handled while LB is at a "Wait" or "Scan" command. It should work, but it would not be ideal. Since I use WMLiberty.dll quite a bit in my code, I always use a main scan loop that looks like this. I typically wrap the "Sleep" API call in a function, but you get the idea. Depending on what you are doing, it can get quite a bit more complex, but this is the simplest form.
processWaitTime = 10
While Hwnd(#Main) Scan CallDLL #kernel32, "Sleep", processWaitTime As ulong, ret As void Wend
Regarding the OP's original post, I have some code that uses WMLiberty.dll to change a TextBox's colors upon hovering over it if anyone is interested.
{:0)
Brandon Parker
|
|
|
Post by turtleman on Jul 14, 2024 13:26:44 GMT -5
Thanks! I was trying the use the "usual" reply box at the bottom of the page instead hitting the "reply button." Hope this works. ![](https://storage.proboards.com/6923193/thumbnailer/PkpJoHIEdnyYgbSZBKZS.png) I have no code to share right now, but here's a partial pic of what I have working so far: Bet amounts are entered from the keyboard into the textboxes on the left-hand side. (Everything is stored.) If the bet is won, the next bet goes to the textbox (row number) corresponding to the row number in the W column, or if lost, the L column. Left or right mouse clicks are used to increase or decrease these numbers. Depending on win, loss, or push, the new active bet textbox changes from white to yellow. Believe or not, it's working fine. The purely cosmetic goal is to have the betting textbox change color when selected by the mouse in order to enter a new bet size, and return to white when the Enter key is pressed. That's it – just an unimportant cosmetic frill! While unnecessary, I seem to be obsessed with figuring out how to do it.
|
|
|
Post by Walt Decker on Jul 16, 2024 12:57:41 GMT -5
If I understand what you are doing the following is one method to accomplish the task. ' [DECLARE.GLOBALS]
GLOBAL BnClicked, _ Hilited
GLOBAL ForeClr$, _ BackClr$
DIM Ctrl$(2, 1) DIM Win$(2, 1) DIM Loss$(2, 1)
[INIT.GLOBALS] ForeClr$ = "TEXTCLR" BackClr$ = "BKGND"
BnClicked = 0 Hilited = 0
[VARBS] SS.CENTER = 1 'static SS.RIGHT = 2 SS.CENTERIMAGE = HEXDEC("&H00000200") SS.SUNKEN = HEXDEC("&H00001000")
ES.CENTER = 1 'edit ES.MULTILINE = 4 ES.AUTOHSCROLL = HEXDEC("&H0080") ES.WANTRETURN = HEXDEC("&H1000")
VK.RETURN = HEXDEC("&H0D") 'virtual key code EM.SETSEL = HEXDEC("&H00B1")
RetVal = 0 AryElm = 0 Wager = 0 Lost = 0 TotalW = 0 TotalL = 0 CtlHnd = 0
Bet$ = "" CtlTag$ = ""
[DECLARE.DLL] OPEN "CTL_COLOR" FOR DLL AS #CLRCTL
[DEF.CONTROLS] STYLEBITS #DMO.STABET, SS.CENTER, 0, 0, 0 STYLEBITS #DMO.STA1, SS.RIGHT, 0, 0, 0 STYLEBITS #DMO.STA2, SS.RIGHT, 0, 0, 0 STYLEBITS #DMO.STA3, SS.RIGHT, 0, 0, 0 STYLEBITS #DMO.STAW, SS.CENTER, 0, 0, 0 STYLEBITS #DMO.STAL, SS.CENTER, 0, 0, 0 STYLEBITS #DMO.STAW1, SS.CENTER OR SS.SUNKEN, 0, 0, 0 STYLEBITS #DMO.STAW2, SS.CENTER OR SS.SUNKEN , 0, 0, 0 STYLEBITS #DMO.STAW3, SS.CENTER OR SS.SUNKEN, 0, 0, 0 STYLEBITS #DMO.STAL1, SS.CENTER OR SS.SUNKEN, 0, 0, 0 STYLEBITS #DMO.STAL2, SS.CENTER OR SS.SUNKEN, 0, 0, 0 STYLEBITS #DMO.STAL3, SS.CENTER OR SS.SUNKEN, 0, 0, 0
STATICTEXT #DMO.STABET, "BET", 25, 5, 35, 18 STATICTEXT #DMO.STA1, "1", 5, 30, 10, 18 STATICTEXT #DMO.STA2, "2", 5, 55, 10, 18 STATICTEXT #DMO.STA3, "3", 5, 85, 10, 18 STATICTEXT #DMO.STAW, "W", 70, 5, 35, 18 STATICTEXT #DMO.STAL, "L", 110, 5, 35, 18 STATICTEXT #DMO.STAW1, "1", 70, 30, 35, 18 STATICTEXT #DMO.STAW2, "1", 70, 55, 35, 18 STATICTEXT #DMO.STAW3, "1", 70, 85, 35, 18 STATICTEXT #DMO.STAL1, "1", 110, 30, 35, 18 STATICTEXT #DMO.STAL2, "1", 110, 55, 35, 18 STATICTEXT #DMO.STAL3, "1", 110, 85, 35, 18
STYLEBITS #DMO.TXB1, ES.WANTRETURN, 0, 0, 0 STYLEBITS #DMO.TXB2, ES.WANTRETURN, 0, 0, 0 STYLEBITS #DMO.TXB3, ES.WANTRETURN, 0, 0, 0
TEXTBOX #DMO.TXB1, 25, 26, 35, 20 TEXTBOX #DMO.TXB2, 25, 52, 35, 20 TEXTBOX #DMO.TXB3, 25, 82, 35, 20
[DEF.WINDOWS] WindowWidth = 230 WindowHeight = 200 UpperLeftX = 200 UpperLeftY = 200
OPEN "TEXT DEMO" FOR WINDOW AS #DMO
[SAVE.CONTROL.HANDLES] Ctrl$(0, 0) = STR$(HWND(#DMO.TXB1)) Ctrl$(0, 1) = "#DMO.TXB1" Ctrl$(1, 0) = STR$(HWND(#DMO.TXB2)) Ctrl$(1, 1) = "#DMO.TXB2" Ctrl$(2, 0) = STR$(HWND(#DMO.TXB3)) Ctrl$(2, 1) = "#DMO.TXB3"
FOR I = 0 TO 2 Win$(I, 0) = "#DMO.STAW" + STR$(I + 1) Win$(I, 1) = "0" Loss$(I, 0) = "#DMO.STAL" + STR$(I + 1) Loss$(I, 1) = "0" NEXT I
[SET.NORMAL.CONTROL.COLORS]
SALMON = HEXDEC("&H7A96E9") '&H7A96E9 salmon PAPYA = HEXDEC("&HD5EFFF") '&HD5EFFF papya PEACH = HEXDEC("&HB9DAFF") '&HB9DAFF peach WHITE = HEXDEC("&HFFFFFF") BLACK = 0 '&HFAE6E6 LAVENDER
RetVal = FN.SetCtrlClr(HWND(#DMO.STABET), BLACK, PEACH) RetVal = FN.SetCtrlClr(HWND(#DMO.STA1), BLACK, PEACH) RetVal = FN.SetCtrlClr(HWND(#DMO.STA2), BLACK, PEACH) RetVal = FN.SetCtrlClr(HWND(#DMO.STA3), BLACK, PEACH) RetVal = FN.SetCtrlClr(HWND(#DMO.STAW), BLACK, PEACH) RetVal = FN.SetCtrlClr(HWND(#DMO.STAL), BLACK, PEACH) RetVal = FN.SetCtrlClr(VAL(Ctrl$(0, 0)), 0, HEXDEC("&HFFFFFF")) RetVal = FN.SetCtrlClr(VAL(Ctrl$(1, 0)), 0, HEXDEC("&HFFFFFF"))
[INITIALIZE.WINDOW] RetVal = FN.InitDll(HWND(#DMO), PEACH, 0)'HEXDEC("&H7A96E9"), 0)
#DMO, "TRAPCLOSE END.DMO"
[SCAN.LOOP] CALLDLL #kernel32, "Sleep", 120 AS LONG, RetVal AS VOID
Wager = FN.CheckFocus(Wager)
IF Wager THEN AryElm = Hilited - 1 Lost = RND(0)
IF Lost > 0.49 THEN CtlTag$ = Win$(AryElm, 0) TotalW = VAL(Win$(AryElm, 1)) + 1 Win$(AryElm, 1) = STR$(TotalW) #CtlTag$, STR$(TotalW) ELSE CtlTag$ = Loss$(AryElm, 0) TotalL = VAL(Loss$(AryElm, 1)) + 1 Loss$(AryElm, 1) = STR$(TotalL) #CtlTag$, STR$(TotalW) END IF
AryElm = Hilited
IF AryElm > 2 THEN AryElm = 0 END IF
CtlTag$ = Ctrl$(AryElm, 1) #CtlTag$, "!SETFOCUS" END IF
SCAN
GOTO [SCAN.LOOP]
WAIT
'-------------------------------- '--------------------------------
SUB BTN BtnHndl$
END SUB
'-------------------------------- '--------------------------------
SUB END.DMO Win$
WinHndl = HWND(#DMO) CALLDLL #CLRCTL, "FN_CLOSE", WinHndl AS ULONG, RetVal AS ULONG CLOSE #CLRCTL
CLOSE #DMO END END SUB
'-------------------------------- '--------------------------------
FUNCTION FN.CheckFocus(Wager)
VK.RETURN = HEXDEC("&H0D") 'virtual key code EM.SETSEL = HEXDEC("&H00B1")
NormalBkg = HEXDEC("&HFFFFFF") NormalTxt = 0 HiliteBkg = HEXDEC("&H00D7FF") HiliteTxt = 0
Bet$ = ""
I = 0
'SCAN CtlHndl = 0 RetVal = 0 CtlElm = 0
Ctl$ = ""
CALLDLL #user32, "GetFocus", CtlHndl AS ULONG
'<---- check for CTRL + ENTER key ---> IF Hilited THEN CtlElm = Hilited - 1 Ctl$ = Ctrl$(CtlElm, 1) #Ctl$, "!CONTENTS? Bet$" RetVal = FN.KeyState(VK.RETURN)
IF RetVal = VK.RETURN THEN FN.CheckFocus = VAL(Bet$) EXIT FUNCTION END IF END IF
FOR I = 0 TO 2 IF CtlHndl = VAL(Ctrl$(I, 0)) THEN
IF BnClicked = 0 THEN '<--- SET INITIAL HILITE BnClicked = CtlHndl Hilited = I + 1 Ctl$ = Ctrl$(I, 1)
#Ctl$, "!CONTENTS? Bet$" #Ctl$, "!HIDE"
RetVal = FN.SetCtrlClr(CtlHndl, HiliteTxt, HiliteBkg) #Ctl$, "!SHOW"
#Ctl$, Bet$ #Ctl$, "!SETFOCUS" EXIT FUNCTION END IF
IF CtlHndl = BnClicked THEN EXIT FUNCTION END IF
'----- CLEAR HILITE AND SET NEXT HILITE ----- Ctl$ = Ctrl$(Hilited - 1, 1) #Ctl$, "!HIDE" RetVal = FN.SetCtrlClr(VAL(Ctrl$(Hilited - 1, 0)), NormalTxt, NormalBkg) #Ctl$, "!SHOW"
IF Wager THEN #Ctl$, STR$(Wager) END IF
BnClicked = CtlHndl Hilited = I + 1
Ctl$ = Ctrl$(I, 1) #Ctl$, "!HIDE" RetVal = FN.SetCtrlClr(CtlHndl, HiliteTxt, HiliteBkg) #Ctl$, "!SHOW" #Ctl$, "!SETFOCUS" EXIT FUNCTION
END IF NEXT I
IF BnClicked THEN '<--- CLEAR HILITE Ctl$ = Ctrl$(Hilited - 1, 1) #Ctl$, "!HIDE" RetVal = FN.SetCtrlClr(VAL(Ctrl$(Hilited - 1, 0)), NormalTxt, NormalBkg) #Ctl$, "!SHOW" BnClicked = 0 Hilited = 0 END IF
END FUNCTION
'-------------------------------- '--------------------------------
FUNCTION FN.InitDll(WinHndl, WinColor, BmpTrue)
CALLDLL #CLRCTL, "FN_InitProperties", WinHndl AS LONG, ForeClr$ AS PTR, _ BackClr$ AS PTR, WinColor AS ULONG, BmpTrue AS LONG, _ RetVal AS LONG FN.InitDll = RetVal END FUNCTION
'-------------------------------- '--------------------------------
FUNCTION FN.KeyState(Key)
VK.RETURN = HEXDEC("&H0D") VK.CONTROL = HEXDEC("&H11")
Mask = HEXDEC("&H8000")
CALLDLL #user32, "GetAsyncKeyState", VK.CONTROL AS ULONG, Pressed AS USHORT
IF (Pressed AND Mask) THEN CALLDLL #user32, "GetAsyncKeyState", Key AS ULONG, Pressed AS USHORT
IF (Pressed AND Mask) THEN FN.KeyState = Key END IF END IF
END FUNCTION
'-------------------------------- '--------------------------------
FUNCTION FN.SetCtrlClr(CtlHndl, TxtClr, BkgClr)
CALLDLL #CLRCTL, "SetProperty", CtlHndl AS ULONG, ForeClr$ AS PTR, _ TxtClr AS ULONG, BackClr$ AS PTR, BkgClr AS ULONG, _ RetVal AS VOID END FUNCTION '
|
|