Sver
Full Member
Posts: 145
|
Post by Sver on Mar 14, 2020 9:18:26 GMT -5
Is it possilble to change the #win.1 to #win.2, #win.3,................#win.10
nomainwin
WindowHeight=660
'---------------
for i=1 to 10
a=a+50
textbox #win.1, 30, a, 120, 30
next i
open "test" for window as #win
#win, "trapclose [quit]"
wait
'-------------------
[quit]
close #win
end
|
|
|
Post by metro on Mar 14, 2020 11:08:39 GMT -5
That's a nice code, possible, when they textboxes already exist. (after open a window) I am curious if there is a faster and shorter way to create more textboxes, before open a window. Of course i can make a lot of lines. (1 to 20) Do you mean when coding your program? If so this maybe useful
'GUI Helper written by Jim Brossman maeknarr@yahoo.com 'Released into the public domain 'Version 1.0 1/21/2008 'This program is useful when trying to create multiple controls 'at one time without having to use the copy section in FreeForm. 'Instructions for the program are at the end of the program. GLOBAL rownumber nomainwin WindowWidth = 600 WindowHeight = 800 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) statictext #main, "How Many", 15, 5, 85, 25 textbox #main.tb1, 130, 0, 40, 25 stylebits #main.tb1,_ES_NUMBER,0,0,0 'Set textbox to accept whole numbers only statictext #main, "Length", 15, 40, 85, 25 textbox #main.tb2, 130, 35, 40, 25 stylebits #main.tb2,_ES_NUMBER,0,0,0 statictext #main, "Height", 15, 75, 85, 25 textbox #main.tb3, 130, 70, 40, 25 stylebits #main.tb3,_ES_NUMBER,0,0,0 statictext #main, "Starting X Location", 15, 105, 85, 40 textbox #main.tb4, 130, 105, 40, 25 stylebits #main.tb4,_ES_NUMBER,0,0,0 statictext #main, "Starting Y Location", 15, 142, 85, 40 textbox #main.tb5, 130, 140, 40, 25 stylebits #main.tb5,_ES_NUMBER,0,0,0 statictext #main, "Spacing", 15, 180, 85, 25 textbox #main.tb6, 130, 175, 40, 25 stylebits #main.tb6,_ES_NUMBER,0,0,0 statictext #main, "Window Handle", 15, 215, 110, 25 textbox #main.tb7, 130, 210, 100, 25 button #main.b2,"Create Textboxes",[textboxes], UL, 410, 2, 140, 25 button #main.b1,"Create Buttons",[buttons], UL, 410, 32, 140, 25 button #main.b3,"Create Radiobuttons",[radiobuttons], UL, 410, 62, 140, 25 button #main.b4,"Create Checkboxes",[checkboxes], UL, 410, 92, 140, 25 button #main.b5,"Create Statictext",[statictext], UL, 410, 122, 140, 25 button #main.b6,"Clear All", [clearall],UL, 410, 152, 140, 25 button #main.b7,"Clip Boardl", [selectall],UL, 410, 182, 140, 25 texteditor #main.te, 10, 250, 575, 355 texteditor #main.ftr, 10, 610, 575, 125
open "GUI Helper" for window_nf as #main print #main, "font Arial 10 Bold" print #main, "trapclose [quit.main]" 'Get handles of textboxes. Needed to make Enter key move between boxes. hTextbox1=hwnd(#main.tb1) hTextbox2=hwnd(#main.tb2) hTextbox3=hwnd(#main.tb3) hTextbox4=hwnd(#main.tb4) hTextbox5=hwnd(#main.tb5) hTextbox6=hwnd(#main.tb6) hTextbox7=hwnd(#main.tb7)
[clearall] for hv=1 to 7 'Clear all text boxes var$="#main."+word$("tb1 tb2 tb3 tb4 tb5 tb6 tb7",hv) #var$ "" next 'Set the number of controls to create. These varibles will allow 'the user to create controls and then create more controls so the 'indexing will be done correctly. tbnumber=1 bnumber=1 rbnumber=1 cbnumber=1 stnumber=1 rownumber=1 'This varible is used in the texteditor to keep 'track of which line to print the output to. print #main.te,"!cls" call PrintHeader timer 50, [enterkey] 'Turn timer on so program checks for Enter key presses.
[loop] #main.tb1, "!setfocus" wait
[enterkey] 'Check to see if Enter key was pressed. CallDLL #user32, "GetAsyncKeyState",_VK_RETURN as long,fKeyPress as long if fKeyPress <0 then 'If Enter key is pressed calldll #user32,"GetFocus",textboxHandle as ulong 'Depending on which textbox has focus when Enter key is pressed 'set the focus to the next textbox. select case textboxHandle case hTextbox1 'If textbox 1 has focus, set focus to textbox 2. #main.tb2,"!setfocus" case hTextbox2 #main.tb3,"!setfocus" case hTextbox3 #main.tb4,"!setfocus" case hTextbox4 #main.tb5,"!setfocus" case hTextbox5 #main.tb6,"!setfocus" case hTextbox6 #main.tb7,"!setfocus" case hTextbox7 #main.tb7,"!setfocus" end select end if wait
[textboxes] 'Set control conditions for textboxes. gosub [checkdata] 'Check to see if all textboxes are filled in. if flag then wait 'If all textboxes are not filled in. control$="textbox" 'Name of control. extension$="tb" 'Extension of control. start=tbnumber 'Start set to number of controls desired. gosub [createcontrol] tbnumber=tbnumber+number 'Set number of controls to number already created. ' gosub [insertfooter] goto [loop]
[buttons] 'Set control conditions for buttons. gosub [checkdata] if flag then wait control$="button" extension$="b" start=bnumber gosub [createcontrol] bnumber=bnumber+number goto [loop]
[radiobuttons] 'Set control conditions for radioboxes. gosub [checkdata] if flag then wait control$="radiobutton" extension$="rb" start=rbnumber gosub [createcontrol] rbnumber=rbnumber+number goto [loop]
[checkboxes] 'Set control conditions for checkboxes. gosub [checkdata] if flag then wait control$="checkbox" extension$="cb" start=cbnumber gosub [createcontrol] cbnumber=cbnumber+number goto [loop]
[statictext] 'Set control conditions for statictext. gosub [checkdata] if flag then wait control$="statictext" extension$="st" start=stnumber gosub [createcontrol] stnumber=stnumber+number goto [loop]
[checkdata] 'Retreive data and check to see if all textboxes have been 'filled in before creating any controls. If a textbox is not 'filled in, focus will be set to that textbox. flag=0 'Flag set to 0, a 1 = some textbox is not filled in. #main.tb1, "!contents? number$":number=val(number$) if number$="" then #main.tb1, "!setfocus":flag=1:return #main.tb2, "!contents? length$" if length$="" then #main.tb2, "!setfocus":flag=1:return #main.tb3, "!contents? height$":height=val(height$) if height$="" then #main.tb3, "!setfocus":flag=1:return #main.tb4, "!contents? xlocation$" if xlocation$="" then #main.tb4, "!setfocus":flag=1:return #main.tb5, "!contents? ylocation$":ylocation=val(ylocation$) if ylocation$="" then #main.tb5, "!setfocus":flag=1:return #main.tb6, "!contents? spacing$":spacing=val(spacing$) if spacing$="" then #main.tb6, "!setfocus":flag=1:return #main.tb7, "!contents? windowname$" if windowname$="" then #main.tb7, "!setfocus":flag=1 return
[createcontrol] 'Create controls
for a=start to start+number-1 select case extension$ 'Depending on the extension, set conditions. case "b" 'buttons label$=chr$(34)+"button"+str$(a)+chr$(34) 'CHR$(34)=" corner$=", [button"+str$(a)+"Click], UL, " case "rb" 'radiobuttons label$=chr$(34)+"radiobutton"+str$(a)+chr$(34) corner$=", [rb"+str$(a)+"Set], [rb"+str$(a)+"Reset], " case "cb" 'checkboxes label$=chr$(34)+"checkbox"+str$(a)+chr$(34) corner$=", [cb"+str$(a)+"Set], [cb"+str$(a)+"Reset], " case "tb" 'textboxes label$="" corner$="" case "st" 'statictext label$=chr$(34)+"statictext"+str$(a)+chr$(34) corner$=", " end select 'This line creates the text for the control line$=control$+" #"+windowname$+"."+extension$+str$(a)+_ ", "+label$+corner$+xlocation$+", "+str$(ylocation)+", "+length$+", "+height$ print #main.te, "!select ";1;" ";rownumber 'Set row in texteditor. print #main.te, "!insert line$" 'Print to the text editor. rownumber=rownumber+1 'Index row number ylocation=ylocation+height+spacing 'Calculate the next Y location. next return
[insertfooter] for a = 1 to 10 #main.te,"" next ftr$="open "+chr$(34)+"My New Program"+chr$(34)+" for Window as #"+windowname$ #main.te, ftr$
#main.te, "WAIT" #main.te, "#";windowname$; "," ;chr$(34);"!trapclose [quit]";chr$(34)
#main.te," [quit]" #main.te," close #";windowname$ #main.te, "end"
return [selectall] gosub [insertfooter] #main.te, "!selectall" ; #main.te,"!copy" ; wait
[quit.main] timer 0 'Turn the timer off. Just good practice. close #main END sub PrintHeader #main.te, "nomainwin" #main.te, "WindowWidth=900" #main.te, "WindowHeight=650" #main.te, "UpperLeftX=(DisplayWidth-WindowWidth)/2" #main.te, "UpperLeftY=(DisplayHeight-WindowHeight)/2" rownumber=6 end sub [Instructions] 'This program will allow the user to create multiple controls for textboxes, 'buttons, radiobuttons, checkboxes and static text lines. The text that identifies 'the button, statictext, radiobutton or checkboxes will ultimately have to 'be filled in by the user. That can be done in the text editor or when 'pasted to your program. 'The following text boxes will be used to determine how the controls are created. 'How Many - How many controls do you want to create. 'Length - What is the length of the control in pixels. ' Text boxes, buttons and statictext can be any length. ' radiobuttons and checkboxes must be long enough for the text. 'Height - How high do you want the control. Most should be at least 25 pixels 'Starting X location? - This will be the X position of the upper left corner ' of the first control. 'Starting Y Location? - This will be the Y position of the upper left corner ' of the first control. 'Spacing? - This will be the Y spacing between the remaining controls. 'Window Handle - This will be the handle of your window. DO NOT USE THE # SIGN.
'The buttons will create the output for the selected controls and print the text 'to the the texteditor. Each control will be indexed. For example, you can create '5 textbox controls and then 5 statictext controls. You can decide to create '5 more textboxes and they will be indexed correctly except you must change the 'Starting Y Location to reflect the correct Y position. That is the last textbox 'Y location plus the control height plus the spacing. 'After you create some or all of the controls, you can use the Edit menu to Select 'All of the output and then paste into your program. You can also select just some 'of the output and copy and paste just that into your program. You can also change 'the text of the controls before copying. 'The Clear All button will reset all variables and clear the texteditor. If you use 'this button, all indexing will be set to 1.
'I would suggest that a tkn is created and the program be added to the 'Setup - External Programs section so that it is available in the Run section. 'That will make it easy to use the program while writing your program and paste 'output into it.
|
|
|
Post by metro on Mar 14, 2020 11:35:30 GMT -5
or you could use API to create
'=================================================== ' CREATE TEXTBOX GRID CreateTextboxAPI_Grid_5.bas ' USING WINDOWS API '=================================================== ' modified from LB Newsletter API Corner ' with corrections by Cundo LB Conforum 19 July 2016 ' Further modifications by RNBW 21 July 2016 ' Some Mods by metro Jan 2019 '=================================================== dim newdat$(1000) Fname$="cowNumber , recogn , followNum , also , date , milkingTime , milkAmount , milkmeterNumber" nomainwin
line$(1)="106,Krokus,9,250,6-12-20018,18,15.2,1" line$(2)="88,Krokus,17,250,6-12-20018,18,6.8,1" line$(3)="68,Krokus,25,250,6-12-20018,18,8.6,1" line$(4)="91,Krokus,33,250,6-12-20018,18,8.4,1" line$(5)="67,Krokus,41,250,6-12-20018,19,17.0,1" line$(6)="62,Krokus,49,250,6-12-20018,19,8.0,1"
'LOAD INFO for a = 1 to 6 for q= 1 to 8 Ldat$(a,q)=WORD$(line$(a),q,",") next next
numFields=8 numRecs=6
MENU #1, "&File","&Read", [readIt],_ "E&xit", [quit]
[WindowSetup] WindowWidth = 840 : WindowHeight = 600 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2) ' ------------------------------------------------- ListBox #1.lb1, newdat$(), [selectlist], 40, 190, 645, 150 button #1.btn1 ," Save Data ",[button1Click], UL, 40, 350, 75, 25 OPEN "API Textbox Grid" FOR dialog AS #1 PRINT #1, "trapclose [quit]" #1.lb1,"Font Courier_New 10 BOLD " #1.lb1,"hide"
Global Style, Style1
startH = 40: startV = 40: hRow = 20 : width = 80 DIM hT(numRecs,numFields) FOR row = 1 to numRecs FOR col = 1 to numFields ' Set up the style for the Textboxes Style = _WS_CHILDWINDOW OR _WS_BORDER OR _WS_VISIBLE OR _WS_TABSTOP'_ES_RIGHT 'OR _ES_NUMBER hPos = startH + (col-1)*width vPos = startV + (row-1) * hRow hT(row,col) = CreateTextbox(hwnd(#1),hPos,vPos,width+1,hRow+1,Style) NEXT col NEXT row
'FILL GRID FOR row = 1 to numRecs FOR col = 1 to numFields Print SetText$(hT(row,col), Ldat$(row,col)) NEXT col NEXT row
call SetFocus hT(1,1)
WAIT
[quit] CLOSE #1: END
[readIt] handle = GetFocus() txt$ = GetWindowText$( handle ) NOTICE txt$ WAIT
[button1Click]
FOR row = 1 to numRecs FOR col = 1 to numFields NewLine$( row,col)=GetWindowText$( hT(row,col)) ' print NewLine$(row,col) newdat$(row)=newdat$(row)+","+NewLine$(row,col) ' newdat$(row)= AFTER$(newdat$(row),",") NEXT col NEXT row for z= 1 to numRecs newdat$(z)= AFTER$(newdat$(z),",") next
#1.lb1,"show" #1.lb1,"reload" z=1 redim newdat$(1000) Wait [selectlist]
WAIT
'-------------------------------------------- ' SUBs and FUNCTIONs '--------------------------------------------
' Get the focus in the Texbox Function GetFocus() CALLDLL #user32, "GetFocus",_ GetFocus AS uLONG END Function
' Set the focus in the Texbox SUB SetFocus hWnd CALLDLL #user32, "SetFocus",_ hWnd AS uLONG,_ result AS LONG END SUB
'Get the text entered into the Textbox FUNCTION GetWindowText$(hWnd) total = GetWindowTextLength(hWnd) Title$ = SPACE$(total) + CHR$(0): l= LEN(Title$)
CALLDLL #user32, "GetWindowTextA",_ hWnd AS uLONG,_ Title$ AS PTR,_ l AS LONG,_ result AS LONG GetWindowText$ = TRIM$(Title$) END FUNCTION
'Get the length of the text entered into Textbox FUNCTION GetWindowTextLength(hW) CALLDLL #user32, "GetWindowTextLengthA",_ hW AS uLONG,_ GetWindowTextLength AS LONG END FUNCTION
' Function to create Textbox FUNCTION CreateTextbox(hW, x, y, w, h, Style) Style = _WS_CHILDWINDOW OR _WS_BORDER _ OR _WS_VISIBLE hInst = GetWindowLong(hW, _GWL_HINSTANCE)
CALLDLL #user32, "CreateWindowExA",_ 0 AS LONG,_ "EDIT" AS PTR,_ "" AS PTR,_ Style AS LONG,_ x AS LONG,_ y AS LONG,_ w AS LONG,_ h AS LONG,_ hW AS uLONG,_ 0 AS LONG,_ hInst AS LONG,_ 0 AS LONG,_ CreateTextbox AS uLONG END FUNCTION
FUNCTION GetWindowLong(hW, type) CALLDLL #user32, "GetWindowLongA", _ hW AS uLONG,_ type AS LONG,_ GetWindowLong AS LONG END FUNCTION
function SetText$(hWnd , caption$) calldll #user32, "SendMessageA",_ hWnd as ulong,_ _WM_SETTEXT as long,_ 0 as long,_ caption$ as PTR,_ result as long end function
Sub SendMessageLong hWnd,msg,wParam,lParam CallDLL #user32, "SendMessageA",_ hWnd As uLong, _ msg As Long,_ wParam As Long,_ lParam As Long,_ re As Long end sub
|
|