|
Post by tsh73 on Jun 18, 2021 7:44:24 GMT -5
Ok, I just put together some pieces without uderstanding much But it works for me, try it Pieces: 1) by Walt Decker 2) + some googling, I took pieces from this thread code by Chris Iverson libertybasiccom.proboards.com/thread/1267/multiple-monitors-display-different-windowsHere I have 4 textboxes (but them could be 70 if you would cram them on single screen) randomly populated with numbers "Reset" button fill new numbers "Check for Odd" checks which numbers are odd - logs them to texteditor - and changes their styles! 'try to mark selected textboxes by different border
nomainwin
WindowWidth = 432 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
textbox #main.textbox1, 22, 16, 100, 25 'yes it changes how textbox looks 'stylebits #main.textbox2, 0,_WS_BORDER,0,0 textbox #main.textbox2, 22, 56, 100, 25 textbox #main.textbox3, 22, 96, 100, 25 textbox #main.textbox4, 22, 136, 100, 25 button #main.button5, "Check for Odd", [buttonCheck], UL, 14, 176, 122, 25 button #main.button5, "Reset", [buttonReset], UL, 14, 220, 122, 25 statictext #main.statictext6, "log", 158, 11, 144, 20 texteditor #main.log, 150, 31, 264, 320 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "textbox check/highlight" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
N=4 'number of textboxes. I am lazy so I left them textbox1,textbox2... dim HW(N) for i = 1 to 4 hndl$="#main.textbox";i HW(i) = hwnd(#hndl$) 'print i, hndl$, HW(i) next oldstyle = GetWindowLong(HW(3), _GWL_STYLE) newstyle = oldstyle xor _WS_BORDER uFlags = _SWP_NOOWNERZORDER or _SWP_FRAMECHANGED or _SWP_NOZORDER or _SWP_NOSIZE or _SWP_NOMOVE ' a = SetWindowLong(HW(3), _GWL_STYLE, newstyle) ' a = SetWindowPos(HW(3), _NULL, 0, 0, 0, 0, uFlags) 'TO UPDATE STYLE
goto [buttonReset] 'will get to WAIT there
wait
[quit.main] Close #main END
[buttonCheck] 'check #main.log time$() for i = 1 to 4 hndl$="#main.textbox";i #hndl$ "!contents? value" 'print i, value if value mod 2 then #main.log hndl$;" has odd number!" a = SetWindowLong(HW(i), _GWL_STYLE, newstyle) a = SetWindowPos(HW(i), _NULL, 0, 0, 0, 0, uFlags) 'TO UPDATE STYLE
end if next #main.log "-------------------"
wait
[buttonReset] 'new numbers for i = 1 to 4 hndl$="#main.textbox";i #hndl$ int(rnd(0)*10) 'default styles a = SetWindowLong(HW(i), _GWL_STYLE, oldstyle) a = SetWindowPos(HW(i), _NULL, 0, 0, 0, 0, uFlags) 'TO UPDATE STYLE next wait
Function GetWindowLong(hWnd, nIndex) CallDLL #user32, "GetWindowLongA",_ hWnd as ulong,_ nIndex as long,_ GetWindowLong as long End Function
Function SetWindowLong(hWnd, nIndex, newLong) CallDLL #user32, "SetWindowLongA",_ hWnd as ulong,_ nIndex as long,_ newLong as long,_ SetWindowLong as long End Function
Function SetWindowPos(hWnd, hWInsertAfter, X, Y, cx, cy, uFlags) CallDLL #user32, "SetWindowPos",_ hWnd as ulong,_ hWInsertAfter as ulong,_ X as long,_ Y as long,_ cx as long,_ cy as long,_ uFlags as long,_ SetWindowPos as long End Function
|
|
|
Post by Brandon Parker on Jun 18, 2021 14:05:40 GMT -5
David, I sent you a PM earlier. Just wanted to make sure you received it.
{:0)
Brandon Parker
|
|
|
Post by tsh73 on Jun 18, 2021 15:05:37 GMT -5
now, this one *does* require additional control. But for this setup - single graphicbox strip to draw marks on. Results? Looks better IMHO 'try to mark selected textboxes 'no API solution
nomainwin
WindowWidth = 432 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'sorry I cannot use variable. But I can pretend it is there, so i = 0 to 3 will get me coords textbox #main.textbox1, 35, 15+0*40, 100, 25 textbox #main.textbox2, 35, 15+1*40, 100, 25 textbox #main.textbox3, 35, 15+2*40, 100, 25 textbox #main.textbox4, 35, 15+3*40, 100, 25
'thing to put marks onto. 'With LB, you could remove border with a stylebits command stylebits #main.gr5, 0,_WS_BORDER,0,0 graphicbox #main.gr5, 5, 15, 25, 3*(25+15)+25
button #main.button6, "Check for Odd", [buttonCheck], UL, 14, 176, 122, 25 button #main.button7, "Reset", [buttonReset], UL, 14, 220, 122, 25 statictext #main.statictext8, "log", 158, 11, 144, 20 texteditor #main.log, 150, 31, 264, 320 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "textbox check/highlight" for window as #main print #main, "trapclose [quit.main]" print #main, "font ms_sans_serif 10" #main.gr5, "down; fill buttonface; color red; backcolor red; flush"
N=4 'number of textboxes. I am lazy so I left them textbox1,textbox2...
goto [buttonReset] 'will get to WAIT there
wait
[quit.main] Close #main END
[buttonCheck] 'check #main.log time$() for i = 1 to 4 hndl$="#main.textbox";i #hndl$ "!contents? value" 'print i, value if value mod 2 then #main.log hndl$;" has odd number!" #main.gr5, "place ";12;" ";10+(i-1)*40;";circlefilled 7" end if next #main.gr5, "flush" #main.log "-------------------"
wait
[buttonReset] 'new numbers for i = 1 to 4 hndl$="#main.textbox";i #hndl$ int(rnd(0)*10) 'default styles #main.gr5, "fill buttonface; flush" next wait
|
|
|
Post by Walt Decker on Jun 18, 2021 17:02:09 GMT -5
Here is yet another solution. This one blinks the appropriate edit control.
' GLOBAL SM.CYCAPTION, _ SM.CXBORDER, _ SM.CYBORDER, _ SM.CXFRAME, _ SM.CYFRAME, _ SM.CXSIZEFRAME, _ SM.CYSIZEFRAME
GLOBAL BaseHndl
GLOBAL Caption, _ SizerX, _ SizerY
[INITIALIZE] SM.CYCAPTION = 4 SM.CXBORDER = 5 SM.CYBORDER = 6 SM.CXFRAME = 32 SM.CYFRAME = 33 SM.CXSIZEFRAME = SM.CXFRAME ' ;win40 name change SM.CYSIZEFRAME = SM.CYFRAME ' ;win40 name change
Caption = 0 SizerX = 0 SizerY = 0 BorderX = 0 BorderY = 0 ClientX = 0 ClientY = 0 A = 0
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
DIM CtlCoords(-1, -1) DIM TxtHndls$(-1, -1)
OPEN "User32" FOR DLL AS #USER CALLDLL #USER, "GetSystemMetrics", SM.CYCAPTION AS LONG, Caption AS LONG CALLDLL #USER, "GetSystemMetrics", SM.CXBORDER AS LONG, BorderX AS LONG CALLDLL #USER, "GetSystemMetrics", SM.CYBORDER AS LONG, BorderY AS LONG CALLDLL #USER, "GetSystemMetrics", SM.CXFRAME AS LONG, SizerX AS LONG CALLDLL #USER, "GetSystemMetrics", SM.CYFRAME AS LONG, SizerY AS LONG
TEXTBOX #BWIN.0TXT, 5, 5, 75, 25 TEXTBOX #BWIN.1TXT, 85, 5, 75, 25 TEXTBOX #BWIN.2TXT, 5, 35, 75, 25 TEXTBOX #BWIN.3TXT, 85, 35, 75, 25
ClientX = 10 + 75 * 2 + 85 ClientY = 10 + 35 * 2 + 25 ClientX = ClientX + SizerY * 2 + BorderY * 2 ClientY = ClientY + SizerX * 2 + BorderX * 2 + Caption
UpperLeftX = 100 UpperLeftY = 100 WindowWidth = ClientX WindowHeight = ClientY
OPEN "TEST" FOR WINDOW AS #BWIN PRINT #BWIN, "TRAPCLOSE END.TEST" BaseHndl = HWND(#BWIN)
REDIM TxtHndls$(3, 2) REDIM CtlCoords(3, 3)
TxtHndls$(0, 0) = "#BWIN.0TXT" TxtHndls$(1, 0) = "#BWIN.1TXT" TxtHndls$(2, 0) = "#BWIN.2TXT" TxtHndls$(3, 0) = "#BWIN.3TXT"
TxtHndls$(0, 1) = STR$(HWND(#BWIN.0TXT)) TxtHndls$(1, 1) = STR$(HWND(#BWIN.1TXT)) TxtHndls$(2, 1) = STR$(HWND(#BWIN.2TXT)) TxtHndls$(3, 1) = STR$(HWND(#BWIN.3TXT))
A = FN.SetText() A = FN.GetCoords() A = FN.ResizeWindow() A = FN.Giggle()
WAIT END
'--------------------------------------------------------------------------------- '---------------------------------------------------------------------------------
SUB END.TEST WinHndl$
CLOSE #USER CLOSE #BWIN END END SUB
'--------------------------------------------------------------------------------- '---------------------------------------------------------------------------------
FUNCTION FN.SetText()
TxtOut$ = "" Ctl$ = ""
FOR I = 0 TO 3 Ctl$ = TxtHndls$(I, 0) TxtOut$ = "THIS IS A TEST " + STR$(I) PRINT #Ctl$, TxtOut$ NEXT I
END FUNCTION
'--------------------------------------------------------------------------------- '---------------------------------------------------------------------------------
FUNCTION FN.GetCoords() '=================================================================== 'API FUNCTION GetWindowRect(Hwnd, Rect) casts Hwnd as type HWND, 'Rect as a pointer to a structure. The function automatically casts 'Hwnd to the proper data type. '=================================================================== Hndl = 0 RetVal = 0 CtlId = 0 I = 0
FOR I = 0 TO 3 Hndl = VAL(TxtHndls$(I, 1)) CALLDLL #USER, "GetWindowRect", Hndl AS LONG, tRect AS STRUCT, RetVal AS VOID CtlCoords(I, 0) = tRect.X.struct CtlCoords(I, 1) = tRect.Y.struct CtlCoords(I, 2) = tRect.X1.struct CtlCoords(I, 3) = tRect.Y1.struct
CALLDLL #USER, "GetDlgCtrlID", Hndl AS LONG, CtlId AS LONG TxtHndls$(I, 2) = STR$(CtlId) NEXT I END FUNCTION
'------------------------------------------------------------------------------ '------------------------------------------------------------------------------
FUNCTION FN.ResizeWindow()
'MoveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint) 'The API function automatically casts the arguments to the proper data type
RetVal = 0 LstSzx = 0 LstSzy = 0 WinSzx = 0 WinSzy = 0 DifX = 0 DifY = 0 X = 0 Y = 0
STRUCT tRect, _ X AS LONG, _ Y AS LONG, _ X1 AS LONG, _ Y1 AS LONG
LstSzx = CtlCoords(3, 2) - CtlCoords(3, 0) + 5 LstSzy = CtlCoords(3, 3) - CtlCoords(3, 1) + 5
[GET.WINDOW.CLIENT] CALLDLL #USER, "GetClientRect", BaseHndl AS LONG, tRect AS STRUCT, RetVal AS VOID WinSzx = tRect.X1.struct WinSzy = tRect.Y1.struct
[GET.WINDOW.POSITION] CALLDLL #USER, "GetWindowRect", BaseHndl AS LONG, tRect AS STRUCT, RetVal AS VOID X = tRect.X.struct Y = tRect.Y.struct
[WAIT.A.BIT] FOR I = 0 TO 1500000 NEXT I
[RESIZE.WINDOW] DifX = WinSzx - LstSzx + SizerY * 2 DifY = WinSzy - LstSzy + Caption + SizerX
CALLDLL #USER, "MoveWindow", BaseHndl AS LONG, X AS LONG, Y AS LONG, _ DifX AS LONG, DifY AS LONG, 1 AS LONG, RetVal AS VOID
END FUNCTION
'--------------------------------------------------------------------------------- '---------------------------------------------------------------------------------
FUNCTION FN.Giggle()
DT.VCENTER = 00000004 DT.SINGLELINE = HEXDEC("&H00000020")
CtlDc = 0 Fore = 0 Back = 0 DtFrm = 0 Hndl = 0 I = 0 J = 0 K = 0
ForClr = 0'HEXDEC("&HFFFF00") BakClr = HEXDEC("&HFFFFFF")
Ctl$ = "" TxtIn$ = ""
OPEN "Gdi32" FOR DLL AS #GDI CALLDLL #GDI, "CreateSolidBrush", 0 AS ULONG, Fore AS ULONG CALLDLL #GDI, "CreateSolidBrush", BakClr AS ULONG, Back AS ULONG TRACE 2
DtFrm = DT.VCENTER OR DT.SINGLELINE FOR I = 0 TO 3 Hndl = VAL(TxtHndls$(I, 1)) Ctl$ = TxtHndls$(I, 0) CALLDLL #USER, "GetClientRect", Hndl AS LONG, tRect AS STRUCT, RetVal AS VOID CALLDLL #USER, "GetDC", Hndl AS LONG, CtlDc AS ULONG PRINT #Ctl$, "!contents? TxtIn$"
FOR K = 1 TO 5 CALLDLL #USER, "FillRect", CtlDc AS ULONG, tRect AS STRUCT, Fore AS ULONG, RetVal AS VOID CALLDLL #GDI, "SetBkColor", CtlDc AS ULONG, ForClr AS ULONG, RetVal AS VOID CALLDLL #GDI, "SetTextColor", CtlDc AS ULONG, BakClr AS ULONG, RetVal AS VOID CALLDLL #USER, "DrawTextA", CtlDc AS LONG, TxtIn$ AS PTR, -1 AS LONG, _ tRect AS STRUCT, DtFrm AS LONG, RetVal AS VOID
FOR J = 1 TO 1000000 NEXT J
CALLDLL #USER, "FillRect", CtlDc AS ULONG, tRect AS STRUCT, Back AS ULONG, RetVal AS VOID CALLDLL #GDI, "SetBkColor", CtlDc AS ULONG, BakClr AS ULONG, RetVal AS VOID CALLDLL #GDI, "SetTextColor", CtlDc AS ULONG, ForClr AS ULONG, RetVal AS VOID CALLDLL #USER, "DrawTextA", CtlDc AS LONG, TxtIn$ AS PTR, -1 AS LONG, _ tRect AS STRUCT, DtFrm AS LONG, RetVal AS VOID
FOR J = 1 TO 1000000 NEXT J NEXT K
CALLDLL #USER, "ReleaseDC", Hndl AS LONG, CtlDc AS ULONG, RetVal AS VOID
NEXT I
CALLDLL #GDI, "DeleteObject", Fore AS ULONG, RetVal AS VOID CALLDLL #GDI, "DeleteObject", Back AS ULONG, RetVal AS VOID CLOSE #GDI
END FUNCTION '
Except in the cases where an additional control is used to draw attention to erroneous entries, the only way I can see to allow the user to make changes in the appropriate control is to subclass the control in order to capture both WM_SETFOCUS and WM_KEYDOWN.
|
|
|
Post by Chris Iverson on Jun 18, 2021 18:01:35 GMT -5
If we're using APIs/DLLs, and limiting ourselves to textboxes, then I submit my modified version of Anatoly's example. Code: open "LBTBColor.dll" for DLL as #lbtbc
badTextClr = RGB(156, 0, 6) badBGClr = RGB(255, 199, 206)
'try to mark selected textboxes by different border
nomainwin
WindowWidth = 432 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
textbox #main.textbox1, 22, 16, 100, 25 'yes it changes how textbox looks 'stylebits #main.textbox2, 0,_WS_BORDER,0,0 textbox #main.textbox2, 22, 56, 100, 25 textbox #main.textbox3, 22, 96, 100, 25 textbox #main.textbox4, 22, 136, 100, 25 button #main.button5, "Check for Odd", [buttonCheck], UL, 14, 176, 122, 25 button #main.button5, "Reset", [buttonReset], UL, 14, 220, 122, 25 statictext #main.statictext6, "log", 158, 11, 144, 20 texteditor #main.log, 150, 31, 264, 320 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "textbox check/highlight" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
N=4 'number of textboxes. I am lazy so I left them textbox1,textbox2... dim HW(N) for i = 1 to 4 hndl$="#main.textbox";i HW(i) = hwnd(#hndl$) 'print i, hndl$, HW(i) next
goto [buttonReset] 'will get to WAIT there
wait
[quit.main] Close #main close #lbtbc END
[buttonCheck] 'check #main.log time$() for i = 1 to 4 hndl$="#main.textbox";i #hndl$ "!contents? value" 'print i, value if value mod 2 then #main.log hndl$;" has odd number!" a = SetTextboxColors(HW(i), badTextClr, badBGClr) end if next #main.log "-------------------"
wait
[buttonReset] 'new numbers for i = 1 to 4 hndl$="#main.textbox";i #hndl$ int(rnd(0)*10) 'default styles a = ResetTextboxColors(HW(i)) next wait
Function RGB(r, g, b) RGB = ((b AND 255) * 65536) + ((g AND 255) * 256) + (r AND 255) End Function
Function SetTextboxColors(hTB, textColor, bgColor) CallDLL #lbtbc, "SetTextboxColors",_ hTB as ulong, textColor as long,_ bgColor as long, SetTextboxColors as long End Function
Function ResetTextboxColors(hTB) CallDLL #lbtbc, "ResetTextboxColors",_ hTB as ulong, ResetTextboxColors as long End Function Required DLL download: github.com/iversc/LBTBColor/releases/download/1.0-RC1/LBTBColor.dll
|
|
curly
Full Member
Posts: 161
|
Post by curly on Jun 19, 2021 3:37:04 GMT -5
Hi All,
I am really overwhelmed now! Thank you all so very much. I had a break yesterday 'cos my brain hurt! I'm working through all the suggestions, one at a time, to try to understand what the code is doing, and how it works, and trying to see how they will fit in my application.
I'll be back soon, but don't hold your breath...........
Kind regards, David
|
|
|
Post by Carl Gundel on Jun 19, 2021 8:59:34 GMT -5
Hi All, I am really overwhelmed now! Thank you all so very much. I had a break yesterday 'cos my brain hurt! I'm working through all the suggestions, one at a time, to try to understand what the code is doing, and how it works, and trying to see how they will fit in my application. I'll be back soon, but don't hold your breath........... Kind regards, David LOL. Clearly there's more than one way to skin a cat!
|
|
|
Post by Walt Decker on Jun 19, 2021 12:30:38 GMT -5
Judging by the number of controls you indicate you might consider using a tab control to keep them all on one form(window). You can find one here:
For some reason the link keeps putting the focus back to this topic.
|
|
curly
Full Member
Posts: 161
|
Post by curly on Jun 22, 2021 6:01:58 GMT -5
Hi All, By making a cock-up in another routine, I think I have a simple solution (until you Gurus point out my error)
I created different coloured tiny texboxes as progress indicators, one red, one yellow and one green, and showed progress by hiding one and showing the other. I failed to include a hide, with the reult that I effectively put one on top of the other, and when I clicked into the box, the last one printed disappeared?
I've tried this and it works a treat. I create a visible white textbox for someone to add text. I also create an identical textbox coloured yellow that is hidden. When I check the contents of the textbox and find it wrong, I 'show' the yellow textbox without hiding the white one. As soon as you click into the yellow textbox, the white textbox appears and the value can be edited. The yellow textbox hides the contents of the white textbox, but it still works if you grab the contents of the white tetbox, and print it to the yellow. How cool is that?
|
|
|
Post by Rod on Jun 22, 2021 6:06:19 GMT -5
Very cool, nice to see you making progress.
|
|
curly
Full Member
Posts: 161
|
Post by curly on Jun 22, 2021 7:30:30 GMT -5
Thanks Rod
|
|