Author |
Topic: Variable Number Of Rows Of Texboxes (Read 2351 times) |
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Variable Number Of Rows Of Texboxes
« Thread started on: Apr 1st, 2015, 5:35pm » |
|
This is a new thread and follows Richard Russell's comments at Re: Banned from the LB Community Forum « Reply #19 on: 03/20/2015 at 17:39:56 » and « Reply #26 on: 03/23/2015 at 09:49:40 ».
Richard I have followed your advice in using MAPHANDLE. Because I had varying column widths in my table I had to set up 5 sets of FOR...NEXT loops to deal with it, but it appears to work. My next problem was that I didn't want a gap to appear between the table and any following controls. I used some of my old code to resolve that.
My next problem is that I need to scroll the window because it is not big enough to hold all of the controls. Alyce Watson directed me (in LB Conforums) to some MIDI API code. I've not yet come to terms with the Windows API (must do!) and I couldn't get it to work. I'm trying to sort that, but maybe you might have further ideas. The code I've written to date is shown below:
Code:
' SIMPLE BEAM ANALYSIS
' Using LB Booster - 1 April 2015
' Table based on code provided by Richard Russell
' The code currently leaves a big space above the table,
' but this will be filled by other controls, etc, in
' due course.
' This code removes the problem of the texteditor position
' remaining fixed when the number of rows in the table is
' reduced, so eliminating an increasing gap between table
' and text editor.
' Unfortunately, this code only works with LBB, not with LB.
' The next problem to solve is how to scroll the window,
' because the text editor and any following controls will not
' fit thw window size.
' Alyce Watson kindly pointed out a solution using a MIDI API
' but whilst it worked for the example she pointed to, with
' my lack of knowledge of the Windows API, I was unable to get
' it to work. BUT I'm working on it!!!
input "Number of Rows in Table: "; NumOfRows
'NumOfRows = 8
NOMAINWIN
[WindowSetup]
WindowWidth = 1032 : WindowHeight = 650
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
' -------------------------------------------------
vpos = 10: sp = 20: TopOfTable = vpos+sp*16: colWide = 65
BMSF = TopOfTable + ((NumOfRows+1)*sp) + sp
MENU #m, "&File" , "E&xit", [quit]
' SET UP THE CONTROLS FOR THE TABLE"
'Table Heading 1
STYLEBITS #m.top11, _ES_CENTER, _WS_BORDER,0,0
TextboxColor$ = "cyan"
TEXTBOX #m.top11, 10, TopOfTable, 65, 20
STYLEBITS #m.top12, 0, _WS_BORDER,0,0
TEXTBOX #m.top12, 10+65, TopOfTable, 380, 20
STYLEBITS #m.top13, _ES_CENTER, _WS_BORDER,0,0
TEXTBOX #m.top13, 455, TopOfTable, colWide, 20
STYLEBITS #m.top14, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX #m.top14, 455+colWide, TopOfTable, colWide, 20
STYLEBITS #m.top15, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX #m.top15, 455+colWide*2, TopOfTable, colWide, 20
STYLEBITS #m.top16, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX #m.top16, 455+colWide*3, TopOfTable, colWide, 20
STYLEBITS #m.top17, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX #m.top17, 455+colWide*4, TopOfTable, colWide, 20
STYLEBITS #m.top18, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX #m.top18, 455+colWide*5, TopOfTable, colWide, 20
STYLEBITS #m.top19, _ES_CENTER, _WS_BORDER, 0, 0
TEXTBOX #m.top19, 455+colWide*6, TopOfTable, 75, 20
'First column (Load Reference)
for row = 1 to NumOfRows
for col = 1 to 1
stylebits #m.tb, _ES_CENTER, _WS_BORDER, 0, 0
TextboxColor$ = "cyan"
textbox #m.tb, 10, TopOfTable + row*20, 65, 20
maphandle #m.tb, "#m.tb";row;col
next col
next row
'Second Column (Description)
for row = 1 to NumOfRows
for col = 2 to 2
stylebits #m.tb, _ES_CENTER, _WS_BORDER, 0, 0
TextboxColor$ = "white"
textbox #m.tb, 10+65, TopOfTable + row*20, 380, 20
maphandle #m.tb, "#m.tb";row;col
next col
next row
'Columns 3 and 4
for row = 1 to NumOfRows
for col = 3 to 4
stylebits #m.tb, _ES_CENTER, _WS_BORDER, 0, 0
TextboxColor$ = "white"
textbox #m.tb, col*65+(455-65*3), TopOfTable + row*20, 65, 20
maphandle #m.tb, "#m.tb";row;col
next col
next row
'Columns 5 to 8 (Numerical values)
for row = 1 to NumOfRows
for col = 5 to 8
stylebits #m.tb, _ES_RIGHT, _WS_BORDER, 0, 0
TextboxColor$ = "white"
textbox #m.tb, col*65+(455-65*3), TopOfTable + row*20, 65, 20
maphandle #m.tb, "#m.tb";row;col
next col
next row
' Column 9 (Total Loads)
for row = 1 to NumOfRows
for col = 9 to 9
stylebits #m.tb, _ES_RIGHT, _WS_BORDER, 0, 0
TextboxColor$ = "white"
textbox #m.tb, (10+65+380)+(col-3)*65, TopOfTable + row*20, 75, 20
maphandle #m.tb, "#m.tb";row;col
next col
next row
' Set up the position of the text editor control below the table
posBelow=TopOfTable+(9-1)*sp+sp+15
STATICTEXT #m.lbl1, "BM and SF", 130, BMSF, 80, 20
TEXTEDITOR #m.txtEd1, 130, BMSF+sp, 175, 200
open "SIMPLE BEAM ANALYSIS" for window as #m
#m.tb42 "Some text"
#m.tb67, 99.00
#m.tb89, "Last cell"
' Enter headings in header row
#m.top11, "Load No."
#m.top12, "Description"
#m.top13, "DL or LL"
#m.top14, "Type"
#m.top15, "Ldg"
#m.top16, "W or H"
#m.top17, "A"
#m.top18, "C"
#m.top19, "TOTAL LOAD"
' Enter Load No. in column 1
#m.tb11, "Load 1"
#m.tb21, "Load 2"
#m.tb31, "Load 3"
#m.tb41, "Load 4"
#m.tb51, "Load 5"
#m.tb61, "Load 6"
#m.tb71, "Load 7"
#m.tb81, "Load 8"
wait
#m.tbn "!setfocus"
wait
[quit]
close #m
end
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #1 on: Apr 1st, 2015, 6:50pm » |
|
on Apr 1st, 2015, 5:35pm, RNBW wrote:Because I had varying column widths in my table I had to set up 5 sets of FOR...NEXT loops to deal with it |
|
I don't think you did. How about this as an alternative:
Code:for row = 1 to NumOfRows
for col = 1 to 9
TextboxColor$ = "white"
select case col
'First column (Load Reference)
case 1: xpos = 10 : width = 65
TextboxColor$ = "cyan"
'Second Column (Description)
case 2: xpos = 75 : width = 380
'Columns 3 to 8
case 3,4,5,6,7,8: xpos = col*65+(455-65*3) : width = 65
' Column 9 (Total Loads)
case 9: xpos = (10+65+380)+(col-3)*65 : width = 75
end select
if col < 5 then
stylebits #m.tb, _ES_CENTER, _WS_BORDER, 0, 0
else
stylebits #m.tb, _ES_RIGHT, _WS_BORDER, 0, 0
end if
textbox #m.tb, xpos, TopOfTable + row*20, width, 20
maphandle #m.tb, "#m.tb";row;col
next col
next row
Quote:My next problem is that I need to scroll the window because it is not big enough to hold all of the controls. Alyce Watson directed me (in LB Conforums) to some MIDI API code. |
|
Scrolling Windows controls is rather uncommon, and as far as I'm aware the only 'official' solution is to use a Pager Control:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb760855.aspx
I've not tried doing that myself. The use of an MDI window as suggested by Alyce is interesting; I don't know whether that usage is supported by Microsoft and therefore how reliable it might or might not be. I'd be inclined to try the Pager Control first.
Richard.
|
|
|
|
RobM
Junior Member
member is offline
Posts: 91
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #2 on: Apr 1st, 2015, 10:38pm » |
|
Not sure I completely understand what you need but maybe you can modify this as needed. It uses API created textboxes in a graphics window that can be scrolled. In the program where I use this I also have it set to scroll with the mouse wheel via the WMliberty dll.
Code: nomainwin
WindowWidth=500:WindowHeight=440
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
graphicbox #grid.gb, 5, 25, 453, 290
button #grid.continue, "Get Contents Textbox 5", [ContinueSettings], UL, 10, 360, 150, 25
button #grid.close, "close", [close], UL, 230, 360, 70, 25
stylebits #grid.gb, 0, 0, _WS_EX_CONTROLPARENT, 0
open "Grid" for dialog_modal as #grid
#grid, "trapclose [close]"
hWnd=hwnd(#grid)
#grid.gb, "fill white"
NumSettings=30
graphicheight=290
scrollrange=abs((NumSettings*22)-graphicheight+4)
#grid.gb, "vertscrollbar on 0 ";scrollrange
'create grid
fontheight=16
facename$ = "Arial"
FontHandle=CreateFont(fontheight,facename$)
gbh=hwnd(#grid.gb)
Hwn=hwnd(#grid)
dim TbHandles$(NumSettings*2)
y=0
Tab=1
NoTab=0
for x=1 to NumSettings
handle=TextboxChildH(Hwn, gbh, 0, y, 300, 22, FontHandle, 1, 0, NoTab)
TbHandles$(x)=TbHandles$(x);handle;" "
handle=TextboxChildH(Hwn, gbh, 300, y,130, 22, FontHandle, 0, 1, Tab)
TbHandles$(x)=TbHandles$(x);handle;" "
y=y+22
next x
'fill grid
call SetWindowText "Label 1", val(word$(TbHandles$(1),1))
call SetWindowText str$(1), val(word$(TbHandles$(1),2))
call SetWindowText "Label 2", val(word$(TbHandles$(2),1))
call SetWindowText str$(2), val(word$(TbHandles$(2),2))
call SetWindowText "Label 3", val(word$(TbHandles$(3),1))
call SetWindowText str$(3), val(word$(TbHandles$(3),2))
call SetWindowText "Label 4", val(word$(TbHandles$(4),1))
call SetWindowText str$(4), val(word$(TbHandles$(4),2))
call SetWindowText "Label 5", val(word$(TbHandles$(5),1))
call SetWindowText str$(5), val(word$(TbHandles$(5),2))
call SetWindowText "Label 6", val(word$(TbHandles$(6),1))
call SetWindowText str$(6), val(word$(TbHandles$(6),2))
call SetWindowText "Label 7", val(word$(TbHandles$(7),1))
call SetWindowText str$(7), val(word$(TbHandles$(7),2))
call SetWindowText "Label 8", val(word$(TbHandles$(8),1))
call SetWindowText str$(8), val(word$(TbHandles$(8),2))
call SetWindowText "Label 9", val(word$(TbHandles$(9),1))
call SetWindowText str$(9), val(word$(TbHandles$(9),2))
call SetWindowText "Label 10", val(word$(TbHandles$(10),1))
call SetWindowText str$(10), val(word$(TbHandles$(10),2))
goto [MainLoop]
[MainLoop]
calldll #kernel32, "Sleep", 10 as long, re as void
scan
goto [MainLoop]
[ContinueSettings]
text$=GetContent$(5,2)
notice text$
goto [MainLoop]
[close]
close #grid
end
sub SetWindowText text$, handle
text$=text$+chr$(0)
calldll #user32, "SetWindowTextA",_
handle as ulong,_
text$ as ptr,_
ret as long
end sub
function GetContent$(row,column)
handle=val(word$(TbHandles$(row),column))
calldll #user32, "GetWindowTextLengthA",_
handle as ulong,_ 'handle of control
numChars as long 'number of characters
GetContent$=space$(numChars)+Chr$(0)
lenEntry= Len(GetContent$)
calldll #user32, "GetWindowTextA",_
handle as ulong,_
GetContent$ as ptr,_
lenEntry as long,_
ret as long
GetContent$=trim$(GetContent$)
end function
function TextboxChildH(Hwn, gbh, xOrg, yOrg, boxWidth, boxHeight, FontHandle, readonly, center, tab)
Type = _GWL_HINSTANCE
calldll #user32, "GetWindowLongA",_
Hwn as ulong,_ 'handle of window that will contain controls
Type as long,_ 'flag for word value desired=instance handle
hInstance as ulong 'instance handle of window is returned
classname$="EDIT"+chr$(0)
winname$=""
dwStyle=_WS_CHILDWINDOW or _WS_BORDER or _WS_VISIBLE or _ES_AUTOHSCROLL
if readonly then dwStyle=dwStyle or _ES_READONLY
if center then dwStyle=dwStyle or _ES_CENTER
if tab then dwStyle=dwStyle or _WS_EX_CONTROLPARENT
calldll #user32, "CreateWindowExA",_
0 as long,_ 'extended style
classname$ as ptr,_ 'class name
winname$ as ptr,_ 'title or string
dwStyle as ulong,_ 'window style
xOrg as long,_ 'x org
yOrg as long,_ 'y org
boxWidth as long,_ 'width
boxHeight as long,_ 'height
Hwn as ulong,_ 'parent window
0 as ulong,_ 'handle to menu = 0 for class menu
hInstance as ulong,_ 'instance handle of parent window
"" as ptr,_ 'always NULL
TextboxChildH as ulong 'returns handle of this control
calldll #user32, "SendMessageA", _
TextboxChildH as ulong, _ 'handle of control
_WM_SETFONT as long,_ 'message
FontHandle as ulong, _ 'handle of font
1 as long,_ 'repaint flag
result as void
calldll #user32 , "SetParent" ,_
TextboxChildH AS ulong ,_
gbh AS ulong ,_
result AS long
'fix z-order for tabbing
flags = _SWP_NOMOVE or _SWP_NOSIZE
calldll #user32, "SetWindowPos", _
TextboxChildH as ulong, _
_HWND_BOTTOM as long, _
0 as long, _
0 as long, _
0 as long, _
0 as long, _
flags as long, _
result as void
end function
function CreateFont(fontheight,facename$)
calldll #gdi32, "CreateFontA",_
fontheight as long, fontwidth as long,_
escapement as long, orientation as long,_
_FW_NORMAL as long, italic as long,_
underline as long, strikeout as long,_
CharSet as long, OutputPrecision as long,_
ClipPrecision as long, Quality as long,_
PitchAndFamily as long,facename$ as PTR,_
CreateFont as ulong 'returns handle to font
end function
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #3 on: Apr 1st, 2015, 10:59pm » |
|
on Apr 1st, 2015, 10:38pm, RobM wrote:Not sure I completely understand what you need but maybe you can modify this as needed. |
|
That code doesn't work in LBB (it doesn't scroll) so unless it can be modified to do so it would perhaps be better to post it at the LB forum. In fact I have no idea how or why it scrolls in LB (even though it does); can you explain?
I also have the same question for you as I do for the OP: couldn't you use a standard List View (Report Style) control instead?
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774735.aspx
Richard.
|
|
|
|
RobM
Junior Member
member is offline
Posts: 91
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #4 on: Apr 1st, 2015, 11:57pm » |
|
Quote:That code doesn't work in LBB (it doesn't scroll) so unless it can be modified to do so it would perhaps be better to post it at the LB forum. |
|
I checked to see if it ran in LBB but must not have checked if it scrolled. I must have assumed it would. I just tried adding in the WMLiberty calls to see if it would scroll with the mouse wheel but it still doesn't work.
Quote:In fact I have no idea how or why it scrolls in LB (even though it does); can you explain? |
|
Not really, it is just something I tried and it seemed to work for my needs.
Quote:I also have the same question for you as I do for the OP: couldn't you use a standard List View (Report Style) control instead? |
|
I probably could but at the time this was written (about 8 years ago) I wasn't as familiar with all of the different types and styles of controls that Windows has to offer.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #5 on: Apr 2nd, 2015, 12:47am » |
|
on Apr 1st, 2015, 11:57pm, RobM wrote:Not really, it is just something I tried and it seemed to work for my needs. |
|
The graphics window seems to be behaving as a kind of container control, a bit like the Pager Control I referenced in my reply to the OP. Why a LB graphics window would behave that way I have no idea; LBB's certainly doesn't - I wouldn't even know how to achieve it!
Your solution may well be suitable for the OP, all things considered, but he will have to revert to using LB 4.04 to take advantage of it.
Quote:I probably could but at the time this was written (about 8 years ago) I wasn't as familiar with all of the different types and styles of controls that Windows has to offer. |
|
One reason why a List View might not be suitable is that it's used for display rather than for entry (the fields are read-only). I don't know whether that is an issue for the OP.
It's a pity Win32 doesn't offer a general purpose grid control, of the kind one might want for a spreadsheet (.NET does, but that's not usable from LB/LBB). There are third-party offerings but I haven't tried any of those.
Richard.
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #6 on: Apr 3rd, 2015, 09:46am » |
|
Here is a complete scrolling solution. Enjoy!
Richard.
Code:' SIMPLE BEAM ANALYSIS
' Using LB Booster - 3 April 2015
' Table based on code provided by Richard Russell
' Scrolling code added by Richard Russell
' The code currently leaves a big space above the table,
' but this will be filled by other controls, etc, in
' due course.
'input "Number of Rows in Table: "; TotalRows
TotalRows = 12
VisibleRows = 6
NOMAINWIN
[WindowSetup]
WindowWidth = 1032 : WindowHeight = 650
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
' -------------------------------------------------
vpos = 160 : rowHigh = 20 : TopOfTable = vpos
BMSF = TopOfTable + ((VisibleRows+1)*rowHigh) + rowHigh
MENU #m, "&File" , "E&xit", [quit]
' SET UP THE CONTROLS FOR THE TABLE"
'Table Heading 1
TextboxColor$ = "cyan"
STYLEBITS #m.top1, _ES_CENTER + _ES_READONLY, _WS_BORDER,0,0
TEXTBOX #m.top1, 10, TopOfTable, 65, rowHigh
STYLEBITS #m.top2, _ES_READONLY, _WS_BORDER,0,0
TEXTBOX #m.top2, 10+65, TopOfTable, 380, rowHigh
STYLEBITS #m.top3, _ES_CENTER + _ES_READONLY, _WS_BORDER,0,0
TEXTBOX #m.top3, 455, TopOfTable, 65, rowHigh
STYLEBITS #m.top4, _ES_CENTER + _ES_READONLY, _WS_BORDER, 0, 0
TEXTBOX #m.top4, 455+65, TopOfTable, 65, rowHigh
STYLEBITS #m.top5, _ES_CENTER + _ES_READONLY, _WS_BORDER, 0, 0
TEXTBOX #m.top5, 455+65*2, TopOfTable, 65, rowHigh
STYLEBITS #m.top6, _ES_CENTER + _ES_READONLY, _WS_BORDER, 0, 0
TEXTBOX #m.top6, 455+65*3, TopOfTable, 65, rowHigh
STYLEBITS #m.top7, _ES_CENTER + _ES_READONLY, _WS_BORDER, 0, 0
TEXTBOX #m.top7, 455+65*4, TopOfTable, 65, rowHigh
STYLEBITS #m.top8, _ES_CENTER + _ES_READONLY, _WS_BORDER, 0, 0
TEXTBOX #m.top8, 455+65*5, TopOfTable, 65, rowHigh
STYLEBITS #m.top9, _ES_CENTER + _ES_READONLY, _WS_BORDER, 0, 0
TEXTBOX #m.top9, 455+65*6, TopOfTable, 75, rowHigh
for row = 1 to TotalRows
for col = 1 to 9
TextboxColor$ = "white"
select case col
'First column (Load Reference)
case 1: xpos = 0 : width = 65
TextboxColor$ = "cyan"
'Second Column (Description)
case 2: xpos = 65 : width = 380
'Columns 3 to 8
case 3,4,5,6,7,8: xpos = col*65+(445-65*3) : width = 65
' Column 9 (Total Loads)
case 9: xpos = (65+380)+(col-3)*65 : width = 75
end select
if col < 5 then
stylebits #m.tb, _ES_CENTER, _WS_BORDER, 0, 0
else
stylebits #m.tb, _ES_RIGHT, _WS_BORDER, 0, 0
end if
textbox #m.tb, xpos, row*rowHigh-rowHigh, width, rowHigh
maphandle #m.tb, "#m.tb";row;col
next col
next row
' Set up the position of the text editor control below the table
STATICTEXT #m.lbl1, "BM and SF", 130, BMSF, 80, rowHigh
TEXTEDITOR #m.txtEd1, 130, BMSF+rowHigh, 175, 200
STYLEBITS #m.gb1, _WS_CLIPCHILDREN + _WS_VSCROLL, 0, 0, 0
STYLEBITS #m.gb2, _WS_CLIPCHILDREN, _WS_BORDER, 0, 0
GRAPHICBOX #m.gb1, 9, TopOfTable+rowHigh, 930, VisibleRows*rowHigh
GRAPHICBOX #m.gb2, 0, 0, 910, TotalRows*rowHigh
open "SIMPLE BEAM ANALYSIS" for window as #m
hwm = hwnd(#m)
hwgb1 = hwnd(#m.gb1)
hwgb2 = hwnd(#m.gb2)
CALLDLL #user32, "SetParent", hwgb2 as ulong, hwgb1 as ulong, r as long
for row = 1 to TotalRows
for col = 1 to 9
h$ = "#m.tb";row;col
hwtb = hwnd(#h$)
CALLDLL #user32, "SetParent", hwtb as ulong, hwgb2 as ulong, r as long
next col
next row
#m.gb1 "vertscrollbar on 0 ";TotalRows*rowHigh
#m "refresh"
#m "trapclose [quit]"
#m.tb11 "!setfocus"
#m.tb42 "Some text"
#m.tb67, 99.00
#m.tb89, "Last cell"
' Enter headings in header row
#m.top1, "Load No."
#m.top2, "Description"
#m.top3, "DL or LL"
#m.top4, "Type"
#m.top5, "Ldg"
#m.top6, "W or H"
#m.top7, "A"
#m.top8, "C"
#m.top9, "TOTAL LOAD"
' Enter Load No. in column 1
for row = 1 to TotalRows
h$ = "#m.tb";row;"1"
#h$ "Load ";row
next row
timer 20, [scroll]
wait
[scroll]
calldll #user32, "GetScrollPos", hwgb1 as ulong, _
_SB_VERT as long, pos as long
if pos <> oldpos then
oldpos = pos
#m.gb2 "locate 0 ";-pos;" 910 ";TotalRows*rowHigh
#m "refresh"
end if
wait
[quit]
close #m
end
|
|
|
|
RobM
Junior Member
member is offline
Posts: 91
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #7 on: Apr 3rd, 2015, 2:21pm » |
|
Nice!
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #8 on: Apr 3rd, 2015, 4:28pm » |
|
[quote author=Richard Russell link=board=lblang&num=1427909734&start=6#0 date=1428054403]Here is a complete scrolling solution. Enjoy!
Richard.
Thanks for your solution, but I really need the whole window to scroll. Below is a solution based on a recommendation by Alyce Watson (http://lbpe.wikispaces.com/MDIScroll).
My intention is to develop a program to calculate bending moments and shear forces for a simply supported beam. This can then be further developed to produced code to design steel, timber and reinforced concrete beams. The code that I have produced only provides the table into which data will be entered by the user. This will then be used to calculate bending moments and shear forces at points along the beam and be presented in tabular form in a texteditor control (or some other method) below the table. This is why I need the whole window to be scrolled, rather than just the table.
Richard, am I right to develop the code in this section or would you prefer it elsewhere?
Code:
' SIMPLE BEAM ANALYSIS
' Using LB Booster - 3 April 2015
' Table based on code provided by Richard Russell
' The code currently leaves a big space above the table,
' but this will be filled by other controls, etc, in
' due course.
' Unfortunately, this code only works with LBB, not with LB.
' The next problem to solve is how to scroll the window,
' because the text editor and any following controls will not
' fit thw window size.
' Alyce Watson kindly pointed out a solution using a MIDI API
' The code below includes a scrolling solution based on the
' method suggested by Alyce Watson. This involves utilising
' a child window and can be found at:
' http://lbpe.wikispaces.com/MDIScroll
'-------------------------------------------------------------
' Enter the number of loads to be supported by the beam.
' At the moment no checks are made for controling the number
' to 8 or ensuring that only numeric characters are entered.
input "Number of loads on the beam (1 to 8): "; NumOfRows
' number greater than 8 can be entered, but 8 loads is
' usually plenty for a simple beam
'-------------------------------------------------------------
NOMAINWIN
[WindowSetup]
WindowWidth = 1032 : WindowHeight = 650
UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
childWide=1400 : childHigh=1000 'child window dims
'-------------------------------------------------------------
'menu #main, "File", "E&xit",[quit]
open "SIMPLE BEAM ANALYSIS" for window as #main
print #main, "trapclose [quit]"
print #main, "resizehandler [resize]"
hMain=hwnd(#main) 'main window handle
calldll #user32, "GetWindowLongA",_
hMain as uLong,_ 'handle of window
_GWl_HINSTANCE as long,_ 'flag for instance handle
hInstance as uLONG 'returns instance handle of window
dwStyle=_WS_CLIPCHILDREN OR _WS_CHILD OR _WS_VISIBLE OR _
_WS_BORDER or _WS_VSCROLL OR _WS_HSCROLL
'create an MDI Client Control
calldll #user32, "CreateWindowExA",_
0 as long,_ 'extended class style
"MDICLIENT" as ptr,_ 'class name
"" as ptr,_ 'title or string
dwStyle as long,_ 'window style
2 as long,_ 'x org
2 as long,_ 'y org
1021 as long,_ 'width
602 as long,_ 'height
hMain as ulong,_ 'parent window
0 as ulong,_ 'handle to menu = 0 for class menu
hInstance as ulong,_ 'instance handle of parent window
"" as ptr,_ 'always NULL
hMDI as ulong 'returns handle of MDI Client
vpos = 10: sp = 20: TopOfTable = vpos+sp*16: colWide = 65
BMSF = TopOfTable + ((NumOfRows+1)*sp) + sp
MENU #m, "&File" , "E&xit", [quit]
WindowWidth=childWide: WindowHeight=childHigh
' SET UP THE CONTROLS FOR THE TABLE"
'Table Heading 1
'The following is an alternative way of setting up the header row
'STYLEBITS #m.top11, _ES_CENTER, _WS_BORDER,0,0
'TextboxColor$ = "cyan"
'TEXTBOX #m.top11, 10, TopOfTable, 65, 20
'STYLEBITS #m.top12, 0, _WS_BORDER,0,0
'TEXTBOX #m.top12, 10+65, TopOfTable, 380, 20
'STYLEBITS #m.top13, _ES_CENTER, _WS_BORDER,0,0
'TEXTBOX #m.top13, 455, TopOfTable, colWide, 20
'STYLEBITS #m.top14, _ES_CENTER, _WS_BORDER, 0, 0
'TEXTBOX #m.top14, 455+colWide, TopOfTable, colWide, 20
'STYLEBITS #m.top15, _ES_CENTER, _WS_BORDER, 0, 0
'TEXTBOX #m.top15, 455+colWide*2, TopOfTable, colWide, 20
'STYLEBITS #m.top16, _ES_CENTER, _WS_BORDER, 0, 0
'TEXTBOX #m.top16, 455+colWide*3, TopOfTable, colWide, 20
'STYLEBITS #m.top17, _ES_CENTER, _WS_BORDER, 0, 0
'TEXTBOX #m.top17, 455+colWide*4, TopOfTable, colWide, 20
'STYLEBITS #m.top18, _ES_CENTER, _WS_BORDER, 0, 0
'TEXTBOX #m.top18, 455+colWide*5, TopOfTable, colWide, 20
'STYLEBITS #m.top19, _ES_CENTER, _WS_BORDER, 0, 0
'TEXTBOX #m.top19, 455+colWide*6, TopOfTable, 75, 20
' Set up header row controls
for row = 1 to 1
for col = 1 to 9
TextboxColor$ = "cyan"
select case col
case 1: xpos = 10 : width = 65
case 2: xpos = 75 : width = 380
case 3,4,5,6,7,8: xpos = col*65+(455-65*3) : width = 65
case 9: xpos = (10+65+380)+(col-3)*65 : width = 75
end select
select case col
case 1, 3, 4, 5, 6, 7, 8, 9:
stylebits #m.top, _ES_CENTER, _WS_BORDER, 0, 0
case 2:
stylebits #m.top, _ES_LEFT, _WS_BORDER, 0, 0
end select
textbox #m.top, xpos, TopOfTable, width, 20
maphandle #m.top, "#m.top";row;col
next col
next row
' Set up the textbox controls for the rows and columns
for row = 1 to NumOfRows
for col = 1 to 9
TextboxColor$ = "white"
select case col
'First column (Load Reference)
case 1: xpos = 10 : width = 65
TextboxColor$ = "cyan"
'Second Column (Description)
case 2: xpos = 75 : width = 380
'Columns 3 to 8
case 3,4,5,6,7,8: xpos = col*65+(455-65*3) : width = 65
' Column 9 (Total Loads)
case 9: xpos = (10+65+380)+(col-3)*65 : width = 75
end select
select case col
case 1, 3, 4:
stylebits #m.tb, _ES_CENTER, _WS_BORDER, 0, 0
case 2:
stylebits #m.tb, _ES_LEFT, _WS_BORDER, 0, 0
case 5, 6, 7, 8, 9:
stylebits #m.tb, _ES_RIGHT, _WS_BORDER, 0, 0
end select
textbox #m.tb, xpos, TopOfTable + row*20, width, 20
maphandle #m.tb, "#m.tb";row;col
next col
next row
' Set up the position of the text editor control below the table
posBelow=TopOfTable+(9-1)*sp+sp+15
STATICTEXT #m.lbl1, "BM and SF", 130, BMSF, 80, 20
TEXTEDITOR #m.txtEd1, 130, BMSF+sp, 175, 200
'open "SIMPLE BEAM ANALYSIS" for window as #m
open "" for window_popup as #m
print #m, "trapclose [quit]"
hChild=hwnd(#m) 'handle of popup window
calldll #user32, "SetParent",_
hChild as ulong,_ 'make popup the child
hMDI as ulong,_ 'make MDI the parent
result as long
'use MoveWindow to force window resize
'so scrollbars will show
CallDLL #user32, "MoveWindow",hMain As uLong,_
11 As Long, 11 As Long,_
1015 As Long, 633 As Long,_
1 As Boolean, r As Boolean
' Enter some values into table
#m.tb42 "Slab from Area A1"
#m.tb67, 99.00
#m.tb89, "Last cell"
#m.tb43, "DL"
#m.tb44, "UDL"
#m.tb45, "1.50"
#m.tb46, "3.00"
#m.tb47, "0.00"
#m.tb48, "2.75"
#m.tb49, "12.38"
' Enter headings in header row
#m.top11, "Load No."
#m.top12, "Description"
#m.top13, "DL or LL"
#m.top14, "Type"
#m.top15, "Ldg"
#m.top16, "W or H"
#m.top17, "A"
#m.top18, "C"
#m.top19, "TOTAL LOAD"
' Enter Load No. in column 1
#m.tb11, "Load 1"
#m.tb21, "Load 2"
#m.tb31, "Load 3"
#m.tb41, "Load 4"
#m.tb51, "Load 5"
#m.tb61, "Load 6"
#m.tb71, "Load 7"
#m.tb81, "Load 8"
#m.tbn "!setfocus"
wait
[resize]
newWide=WindowWidth-4
newHigh=WindowHeight-4
ret=MoveWindow(hMDI,2,2,newWide,newHigh)
ret=MoveWindow(hChild,0,0,childWide,childHigh)
wait
wait
[quit]
close #m
end
'-------------------------------------------------------------------
'Functions and Subroutines
'-------------------------------------------------------------------
Function MoveWindow(hWnd,x,y,wide,high)
CallDLL #user32, "MoveWindow",_
hWnd As uLong,_ 'handle
x As Long, y As Long,_ 'x,y pos
wide As Long,_ 'width
high As Long,_ 'height
1 As long,_ 'repaint flag
MoveWindow As long
end function
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #9 on: Apr 3rd, 2015, 5:23pm » |
|
on Apr 3rd, 2015, 4:28pm, RNBW wrote:Below is a solution based on a recommendation by Alyce Watson |
|
An issue with that solution is that the scrolling doesn't happen 'continuously' (although I don't know why not): when you drag the scroll box nothing happens until you release the mouse button - which means you don't know how far to scroll other than by trial-and-error.
I made a number of 'incidental' corrections to your code which you might want to incorporate in your version. For example in your code the header fields are editable by the user, which presumably isn't intentional.
Richard.
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #10 on: Apr 3rd, 2015, 8:15pm » |
|
I agree, it's not ideal, but not that important. The user will get used to the page and take that into account when scrolling with the thumb. Alternatively, finer scrolling can be done with the scroll buttons at top and bottom.
You mentioned that you had noticed that the table header descriptions can be changed by the user. Not a good idea. You didn't say how to prevent it, but I found a STYLEBITS that could deal with it _ES_READONLY. I changed the appropriate line of code to:
stylebits #m.top, _ES_CENTER OR _ES_READONLY, _WS_BORDER, 0, 0 OR stylebits #m.top, _ES_LEFT OR _ES_READONLY, _WS_BORDER, 0, 0
Ray
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #11 on: Apr 3rd, 2015, 8:32pm » |
|
on Apr 3rd, 2015, 8:15pm, RNBW wrote:You didn't say how to prevent it |
|
Yes I did: I said I had made the modification (and others) in my version of the program; you need only have looked there.
Ideally you should also remove the WS_TABSTOP style bit because despite being read-only the header fields are still included in the tab order, which isn't particularly useful.
Anyway I said I wouldn't be contributing to this forum any more, so I'll retreat to my comfort zone again.
Richard.
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #12 on: Apr 3rd, 2015, 9:14pm » |
|
Sorry, I didn't realise that you could alter earlier posted code insitu.
I'll look at your code.
I appreciate that you said you wouldn't be posting to this forum again, but I think I probably speak for all users and readers when I ask you to continue. Your experience and expertise is absolutely invaluable to us all.
|
|
Logged
|
|
|
|
RobM
Junior Member
member is offline
Posts: 91
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #13 on: Apr 4th, 2015, 01:19am » |
|
on Apr 3rd, 2015, 8:32pm, Richard Russell wrote:Anyway I said I wouldn't be contributing to this forum any more, so I'll retreat to my comfort zone again.
Richard. |
|
Confucius say: A programmer must program, else he will no longer be a programmer
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Variable Number Of Rows Of Texboxes
« Reply #14 on: Apr 5th, 2015, 09:54am » |
|
on Apr 1st, 2015, 10:38pm, RobM wrote:Not sure I completely understand what you need but maybe you can modify this as needed. It uses API created textboxes in a graphics window that can be scrolled. In the program where I use this I also have it set to scroll with the mouse wheel via the WMliberty dll. |
|
----------------------------------------------------------- I had a quick look at your code when you first posted it and decided it wouldn't easily serve my purpose. However, I've just looked at it again today and I can see some very useful code there, which I will probably be able to make use of in the future. So thank you very much for your post.
Ray
|
|
Logged
|
|
|
|
|