Author |
Topic: Grid of Textboxes using Windows API (Read 83 times) |
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #11 on: Aug 17th, 2016, 8:42pm » |
|
This code works to create grids of textboxes for one window, but I want to generalize, and use it for several windows. But it seems that the actual window name is required in the three statements containing "tmp". Is there any way around this? r.m.
Code:
call tbNumberCG "#cogs.tb", 6,185,40,10,60,25
.......
sub tbNumberCG x$,lmt,j,k,l,m,n
for x = 1 to lmt
var$ = x$ + "0"+right$(str$(x),2)
textbox #cogs.tmp, j, (k*x)+l0, m, n
stylebits #cogs.tmp, _ES_NUMBER, 0, 0, 0
maphandle #cogs.tmp, var$
next x
end sub
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Grid of Textboxes using Windows API
« Reply #12 on: Aug 17th, 2016, 10:51pm » |
|
on Aug 17th, 2016, 8:42pm, Alincon wrote:But it seems that the actual window name is required in the three statements containing "tmp". Is there any way around this? |
|
In just the same way as you initially give your controls the same temporary name (later using maphandle to change them to the required names) you can initially give your multiple windows the same temporary name too! That should hopefully solve your problem, because now the window name you specify in your sub can be the same for all the windows. Something like this:
Code: call tbNumberCG "#cogs", 6,185,40,10,60,25
open "Window 1 (#cogs)" for window as #tmp
maphandle #tmp, #cogs
call tbNumberCG "#wheel", 6,185,40,10,60,25
open "Window 2 (#wheel)" for window as #tmp
maphandle #tmp, #wheel
#cogs.tb03 "Hello "
#wheel.tb04 "world!"
wait
sub tbNumberCG x$,lmt,j,k,l,m,n
for x = 1 to lmt
var$ = x$ + ".tb0" + right$(str$(x),2)
textbox #tmp.tmp, j, (k*x)+l0, m, n
stylebits #tmp.tmp, _ES_NUMBER, 0, 0, 0
maphandle #tmp.tmp, var$
next x
end sub Richard.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #13 on: Aug 18th, 2016, 01:48am » |
|
So the one maphandle statement takes care of several textboxes? (the '6' in the call statement below is the count of textboxes) r.m.
Code:
call tbNumberCG "#cogs", 6,185,40,10,60,25
open "Window 1 (#cogs)" for window as #tmp
maphandle #tmp, #cogs
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Grid of Textboxes using Windows API
« Reply #14 on: Aug 18th, 2016, 09:37am » |
|
on Aug 18th, 2016, 01:48am, Alincon wrote:| So the one maphandle statement takes care of several textboxes? |
|
No, in LBB each maphandle affects only one window or control. That's why maphandle is called 14 times in all in the code I listed (once for each textbox and once for each window).
Did you not run the code I listed? Unlike your snippet, mine was a complete self-contained program: I always prefer that complete programs be posted, rather than extracts that don't actually do anything in isolation.
Richard.
|
|
|
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #15 on: Aug 18th, 2016, 2:21pm » |
|
I meant to ask if only one maphandle statement was required for each window, after the maphandle statements for the individual controls for that window were done. I think I've got it now.
r.m.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #16 on: Aug 18th, 2016, 2:28pm » |
|
I also wanted to show this code that creates either one or two rows of four textboxes r.m.
Code:
for x = 1 to 4 + (4 * (filStat = 2))
a$ = "0" + str$(x)
var$ = "#ssb.tb" + a$
textbox #ssb.tmp, 200 + (100 * (x > 4)), (30*x)+30 - (120 * (x > 4)), 60, 25
stylebits #ssb.tmp, _ES_NUMBER, 0, 0, 0
maphandle #ssb.tmp, var$
next x
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #17 on: Aug 18th, 2016, 2:54pm » |
|
It appears that the 'window' maphandle command must occur before any other controls are created - is that right?
r.m.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Grid of Textboxes using Windows API
« Reply #18 on: Aug 18th, 2016, 4:21pm » |
|
on Aug 18th, 2016, 2:54pm, Alincon wrote:| It appears that the 'window' maphandle command must occur before any other controls are created - is that right? |
|
The 'window' MAPHANDLE must come after the OPEN, whereas all the controls for that window must be created before the OPEN (this is the case in LB and LBB); so I'm not really following what you mean. If by "other" controls you mean controls which aren't shared between multiple windows, here's an example (I've added a checkbox to window 2):
Code: call tbNumberCG "#cogs", 6,185,40,10,60,25
open "Window 1 (#cogs)" for window as #tmp
maphandle #tmp, #cogs
call tbNumberCG "#wheel", 6,185,40,10,60,25
checkbox #tmp.cb, "Checkbox", [], [], 185, 275, 100, 25
open "Window 2 (#wheel)" for window as #tmp
maphandle #tmp.cb, #wheel.cb
maphandle #tmp, #wheel
#cogs.tb03 "Hello "
#wheel.tb04 "world!"
#wheel.cb "set"
wait
sub tbNumberCG x$,lmt,j,k,l,m,n
for x = 1 to lmt
var$ = x$ + ".tb0" + right$(str$(x),2)
textbox #tmp.tmp, j, (k*x)+l0, m, n
stylebits #tmp.tmp, _ES_NUMBER, 0, 0, 0
maphandle #tmp.tmp, var$
next x
end sub Richard.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #19 on: Aug 18th, 2016, 11:41pm » |
|
The 'window' maphandle must be AFTER the window is open! That's what I missed. Thanks.
r.m.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #20 on: Aug 19th, 2016, 12:37am » |
|
Please look at this code. (It is a complete program.) r.m.
Code:
nomainwin
WindowWidth = 380 : WindowHeight = 450
'putting the two commands in this locations works
call tbNumberCG "#cogs.tb", 6,185,40,10,60,25
maphandle #dmy, #cogs
statictext #cogs.statictext3, "Starting Inventory", 65, 50, 102, 20
statictext #cogs.statictext9, "Purchases", 100, 90, 64, 20
statictext #cogs.statictext12, "Cost of Labor", 80, 130, 99, 20
statictext #cogs.statictext15, "Materials, Supplies", 40, 170, 123, 20
statictext #cogs.statictext18, "Other Costs", 90, 210, 90, 20
statictext #cogs.statictext21, "Ending Inventory", 65, 250, 120, 20
statictext #cogs.statictext8, "C O G S", 105, 290, 99, 20
statictext #cogs.cogs, "0", 185, 290, 60, 25
'putting the two commands in this location, the statictexts do not show up
' call tbNumberCG "#cogs.tb", 6,185,40,10,60,25
' maphandle #dmy, #cogs
button #cogs.buOkay, " Accept ",[cogsAccept],UL,185,330
button #cogs.buExit, " End ",[cogsEnd],UL,185,370
Stylebits #cogs.buClear, 0, _WS_TABSTOP, 0, 0
stylebits #cogs, _DS_CENTER,0,0,0
open "COST OF GOODS SOLD: " + businessPropName$ for dialog_modal as #cogs
#cogs, "trapclose [cogsClose]"
#cogs, "font ms_sans_serif 10"
'putting this command here does not work - the textboxes do not show up
' maphandle #dmy, #cogs
#cogs.tb01, "!setfocus"
wait
sub tbNumberCG x$,lmt,j,k,l,m,n
for x = 1 to lmt
var$ = x$ + "0"+right$(str$(x),2)
textbox #dmy.tmp, j, (k*x)+l0, m, n
stylebits #dmy.tmp, _ES_NUMBER, 0, 0, 0
maphandle #dmy.tmp, var$
next x
end sub
[cogsClose]
close #cogs
end
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Grid of Textboxes using Windows API
« Reply #21 on: Aug 19th, 2016, 08:57am » |
|
on Aug 19th, 2016, 12:37am, Alincon wrote:| Please look at this code. |
|
You have put the window's MAPHANDLE before the OPEN (I explicitly told you that it must go after the OPEN). If it works it's only 'by accident' and I don't guarantee it will be reliable (LBB was not designed to support that method, and it won't work at all in LB).
I presume the reason you did it that way is that by doing so you save a lot of MAPHANDLE statements. I can see why that would be tempting, but by using undocumented features of the language you risk your code failing in the future.
So obviously it's up to you how you write your own programs but here is the code modified to work the way my example showed and the way LBB was designed to support (it uses more MAPHANDLEs than yours):
Code: nomainwin
WindowWidth = 380 : WindowHeight = 450
' it makes no difference whether you call the sub before the other controls:
call tbNumberCG "#cogs.tb", 6,185,40,10,60,25
statictext #dmy.statictext3, "Starting Inventory", 65, 50, 102, 20
statictext #dmy.statictext9, "Purchases", 100, 90, 64, 20
statictext #dmy.statictext12, "Cost of Labor", 80, 130, 99, 20
statictext #dmy.statictext15, "Materials, Supplies", 40, 170, 123, 20
statictext #dmy.statictext18, "Other Costs", 90, 210, 90, 20
statictext #dmy.statictext21, "Ending Inventory", 65, 250, 120, 20
statictext #dmy.statictext8, "C O G S", 105, 290, 99, 20
statictext #dmy.cogs, "0", 185, 290, 60, 25
' or whether you call the sub after the other controls:
' call tbNumberCG "#cogs.tb", 6,185,40,10,60,25
button #dmy.buOkay, " Accept ",[cogsAccept],UL,185,330
button #dmy.buExit, " End ",[cogsEnd],UL,185,370
Stylebits #dmy.buClear, 0, _WS_TABSTOP, 0, 0
stylebits #dmy, _DS_CENTER,0,0,0
open "COST OF GOODS SOLD: " + businessPropName$ for dialog_modal as #dmy
' In LBB you need one MAPHANDLE per control:
maphandle #dmy.statictext3, #cogs.statictext3
maphandle #dmy.statictext9, #cogs.statictext9
maphandle #dmy.statictext12, #cogs.statictext12
maphandle #dmy.statictext15, #cogs.statictext15
maphandle #dmy.statictext18, #cogs.statictext18
maphandle #dmy.statictext21, #cogs.statictext21
maphandle #dmy.statictext8, #cogs.statictext8
maphandle #dmy.buOkay, #cogs.buOkay
maphandle #dmy.buExit, #cogs.buExit
maphandle #dmy.cogs, #cogs.cogs
' The window's MAPHANDLE goes after the OPEN:
maphandle #dmy, #cogs
#cogs, "trapclose [cogsClose]"
#cogs, "font ms_sans_serif 10"
#cogs.tb01, "!setfocus"
wait
sub tbNumberCG x$,lmt,j,k,l,m,n
for x = 1 to lmt
var$ = x$ + "0"+right$(str$(x),2)
textbox #dmy.tmp, j, (k*x)+l0, m, n
stylebits #dmy.tmp, _ES_NUMBER, 0, 0, 0
maphandle #dmy.tmp, var$
next x
end sub
[cogsClose]
close #cogs
end Richard.
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline


Gender: 
Posts: 210
|
 |
Re: Grid of Textboxes using Windows API
« Reply #22 on: Aug 19th, 2016, 09:25am » |
|
Alincon, please ask your question. I have looked your code; so what?
Now how I understand it: (I could be wrong of cource) problem to be solved: need to create controls in a loop. This needs some window handle.
Richard's way in Rep#18: you use #tmp everythere creating all the controls and it doesn't matter where you create controls in a loop - before or after statictext creted manually you use maphandle on controls created in a loop after opening window, you MAPHANDLE it too Afther you happily use new handle(s).
Now what you've done: you create controls (in a loop ) for #dmy window, and MAPHANDLE them to #cogs then maphandle #dmy, #cogs (without #dmy existing!) then keep adding controls to #cogs And it seems working. Ok, great - it works so use it.
But then it happens that something breaks if your move "maphandle #dmy, #cogs" to different place - well, noone promised you it will work. Supported approach is in reply #18, use it, and MAPHANDLE window after opening.
Just my 0.02$
EDIT of course ninja'd by Richard ;)
EDIT2 I think if you are not going to change statictext you don't need any of Code:maphandle #dmy.statictext3
|
| « Last Edit: Aug 19th, 2016, 09:30am by tsh73 » |
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Grid of Textboxes using Windows API
« Reply #23 on: Aug 19th, 2016, 2:43pm » |
|
on Aug 19th, 2016, 09:25am, tsh73 wrote:I think if you are not going to change statictext you don't need any of Code:maphandle #dmy.statictext3 |
|
Very good point! Indeed (and this is true in LB as well) if you don't need to access the control after the window is created you don't even need to give it an 'extension':
Code: statictext #w, "Static, unchanging, text", 10, 10, 200, 25
open "Test" for window as #w
wait Richard.
|
|
Logged
|
|
|
|
Alincon
Full Member
member is offline


Posts: 147
|
 |
Re: Grid of Textboxes using Windows API
« Reply #24 on: Aug 19th, 2016, 4:20pm » |
|
I am not trying to break any rules or use undocumented features. Certainly Richard, as the creator of LBB, knows more about it than I. tsh73 is also a respected programmer in both LB and LBB. I do not wish to argue with or upset either one.
Nevertheless, the code I showed earlier works as the included comments state, at least on my machine.
I understood Richard's insistence that the 'window' maphandle instruction should be placed AFTER the open statement. But, in my code, on my machine, that just does not work.
The only combination that does work on my machine is to place the call to the sub, and the 'windows' maphandle command BEFORE the statictext items, and BEFORE the 'open' statement.
"Your results may differ"
r.m.
|
|
Logged
|
|
|
|
tsh73
Full Member
member is offline


Gender: 
Posts: 210
|
 |
Re: Grid of Textboxes using Windows API
« Reply #25 on: Aug 19th, 2016, 5:57pm » |
|
Alincon, line by line: Quote:| I am not trying to break any rules or use undocumented features. |
|
I myself see nothing bad in using undocumented features. If they work, that is.
Quote:| I do not wish to argue with or upset either one. |
|
LOL This is programmer's forum. People come not to quarrel, but to help. (ideally it is)
Quote:I understood Richard's insistence that the 'window' maphandle instruction should be placed AFTER the open statement. But, in my code, on my machine, that just does not work. |
|
You agree that Richard likely "knows more about it" But following his advice "just does not work." I see two possible reasons: 1) somewhere you made a mistake in coding. It happens. You might find it. If you post more code, we might help you (or might not). 2) your code is correct but there is an error in LBB. In this case, Richard probably very interested in finding it out . But he would needs an example that shows this error - that is, your code.
Now, if you interested in finding things out, post your code that didn't work.
If you found a way around it and don't mind leaving this mystery - use your workaround.
|
|
Logged
|
|
|
|
|