Post by Ronnie on Sept 16, 2018 10:09:14 GMT -5
Hi
I am trying to utilize some tab code to create a program with a text and list box (please see code below). I want the test box to be populated based on the list box and I thought I had it working with "selectionindex? index" but it does not seem to work. Also, I am trying to use both a mouse and Inkey with the list box and that too does not work. Any suggests will be appreciated. Thank You Ronnie
I am trying to utilize some tab code to create a program with a text and list box (please see code below). I want the test box to be populated based on the list box and I thought I had it working with "selectionindex? index" but it does not seem to work. Also, I am trying to use both a mouse and Inkey with the list box and that too does not work. Any suggests will be appreciated. Thank You Ronnie
'tab control demo
'use dialog_popup windows to hold controls set parent of popups to be main program window
'when tab is clicked, use MoveWindow to move popups on and off if a graphicbox is used, use GetParent on popup
'if graphicbox is used, restore parent of popup at close doesn't work properly with type window_popup
dim options$(10)
dim a1$(20)
dim a2$(20)
dim a3(20)
nomainwin
'constants:
TCIF.TEXT = 1
TCIF.IMAGE =2
TCS.MULTILINE = 512
TCM.INSERTITEMA = 4871
TCM.GETCURSEL = 4875
TCM.SETCURSEL = 4876
tabID = 1 'current tab
oldTab = 0 'previously selected tab
struct TCITEM,_
mask as ulong,_
dwState as ulong,_
dwStateMask as ulong,_
pszText$ as ptr,_
txtMax as long,_
iImage as long,_
lParam as long
'initialize DLL
calldll #comctl32, "InitCommonControls", ret as void
WindowWidth=700:WindowHeight=410
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
BackgroundColor$ = "darkblue"
ForegroundColor$ = "blackd"
'example controls:
'first page
call Openfile
listbox #tab1.lb, a1$(), [selectionMade], 20, 30, 200, 330
Stylebits #tab1.tx, _ES_MULTILINE, _ES_AUTOHSCROLL OR _ES_AUTOVSCROLL, 0, 0
textbox #tab1.tx, 224, 30, 410, 330
Button #tab1.b1, "Button 1", [buttonOne], UL, 395, 370, 90, 24
open "Inkey$ example" for graphics as #graph
open "" for window_popup as #tab1
print #tab1.lb, "font Ariel 12 bold" ' font text box
print #tab1.tx, "!font Ariel 12 bold" ' font text box
#tab1.lb "singleclickselect [selectionMade]"
'second page
Textbox #tab2.t2, 40, 40, 180, 30
Button #tab2.b2, "Button 2", [buttonTwo], UL, 40, 80, 85, 24
open "" for window_popup as #tab2
'third page
graphicbox #tab3.g, 0, 0, 350, 210
open "" for window_popup as #tab3
'main program window
WindowWidth = 700:WindowHeight = 500 ' whole window
open "Tab Demo" for window_nf as #1
print #1, "trapclose [quit]"
print #1, "font ms_sans_serif 12"
#tab2.t2 "Second Tab Page!"
print #tab3.g, "down; fill blue; color white"
print #tab3.g, "backcolor blue"
print #tab3.g, "place 30 50;\Third page!\Click Me!"
print #tab3.g, "flush"
print #tab3.g, "setfocus; when leftButtonDown [mouseClick]"
hwndParent = hwnd(#1) 'retrieve window handle
hTab1=hwnd(#tab1):hTab2=hwnd(#tab2):hTab3=hwnd(#tab3)
dim winTab(3) 'hold tab window handles in array
winTab(0)=hTab1
winTab(1)=hTab2
winTab(2)=hTab3
'because of graphicbox, get parent on third tab window for use later
hTab3Parent=GetParent(hTab3)
'set popups to be children of main program window
for i = 0 to 2
call SetParent hwndParent,winTab(i)
next
'move child windows
gosub [clear]
call MoveWindow hTab1, 20,40,650,410 ' first set up
' Get window instance handle
CallDLL #user32, "GetWindowLongA",_
hwndParent As ulong,_ 'parent window handle
_GWL_HINSTANCE As long,_'flag to retrieve instance handle
hInstance As ulong 'instance handle
' Create control
style = _WS_CHILD or _WS_CLIPSIBLINGS or _WS_VISIBLE _
or TCS.MULTILINE
calldll #user32, "CreateWindowExA",_
0 As long,_ ' extended style
"SysTabControl32" as ptr,_ ' class name
"" as ptr,_
style as long,_ ' style
10 as long,_ ' left x
10 as long,_ ' top y
675 as long,_ ' width internal fram
450 as long,_ ' height
hwndParent as ulong,_ ' parent hWnd
0 as long,_
hInstance as ulong,_ ' hInstance
"" as ptr,_
hwndTab as ulong ' tab control handle
'set mask and fill struct members:
TCITEM.mask.struct = TCIF.TEXT or TCIF.IMAGE
TCITEM.iImage.struct = -1 'no image
TCITEM.pszText$.struct = "Introduction"
'TCITEM.txtMax.struct=len("First Tab")+1 'used when retrieving text, not needed here
'add first tab:
calldll #user32, "SendMessageA",_
hwndTab as ulong,_
TCM.INSERTITEMA as long,_
0 as long,_ 'zero-based, so 0=first tab
TCITEM as struct,_
ret as long
'add second tab:
TCITEM.pszText$.struct = "Second Tab"
'TCITEM.txtMax.struct=len("Second Tab")+1 'used when retrieving text, not needed here
calldll #user32, "SendMessageA",_
hwndTab as ulong,_
TCM.INSERTITEMA as long,_
1 as long,_ 'zero-based, so 1=second tab
TCITEM as struct,_
ret as long
'add third tab:
TCITEM.pszText$.struct = "Third Tab"
'TCITEM.txtMax.struct=len("Third Tab")+1 'used when retrieving text, not needed here
calldll #user32, "SendMessageA",_
hwndTab as ulong,_
TCM.INSERTITEMA as long,_
2 as long,_ 'zero-based, so 2=third tab
TCITEM as struct,_
ret as long
calldll #gdi32, "GetStockObject",_
_DEFAULT_GUI_FONT as long, hFont as ulong
'set the font to the control:
CallDLL #user32, "SendMessageA",_
hwndTab As ulong,_ 'tab control handle
_WM_SETFONT As long,_ 'message
hFont As ulong,_ 'handle of font
1 As long,_ 'repaint flag
ret As long
timer 300, [checkForTab]
calldll #user32, "SetFocus",hwndParent as ulong,re as ulong
wait
[quit]
timer 0
call SetParent hTab3Parent, hTab3
close #1:close #tab1:close #tab2:close #tab3:end
[checkForTab] 'see if selected tab is the same as previously selected tab and
'change controls if tab has changed
timer 0 'turn off timer
'get the current tab ID
calldll #user32, "SendMessageA",_
hwndTab as ulong,_ 'tab control handle
TCM.GETCURSEL as long,_ 'message to get current selection
0 as long, 0 as long,_ 'always 0's
tabID as long 'returns selected tab ID
if tabID <> oldTab then 'change page displayed
oldTab = tabID 'for next check of selected tab
gosub [clear]
call MoveWindow winTab(tabID), 20,40,650,410
end if
' print #1, "refresh"
timer 300, [checkForTab] 'reactivate timer
wait
[buttonOne]
timer 0
notice "First page."
timer 300, [checkForTab]
wait
[buttonTwo]
timer 0
#tab2.t2 "!contents? txt$"
notice "Textbox contents: ";txt$
timer 300, [checkForTab]
wait
[mouseClick]
timer 0
notice "Mouse clicked on third page."
timer 300, [checkForTab]
wait
[clear] 'hide all windows
for i = 0 to 2
call MoveWindow winTab(i), 3000,3000,550,410
next
return
[selectionMade] ' Test Key board input
key$=Inkey$
select case key$
case "_VK_UP"
notice "red"
case "green","yellow"
print "green or yellow"
case else
print "color unknown"
end select
print #tab1.lb, "selectionindex? index"
i = val("selectionindex?index'")+1
a$ = a2$(i)
print #tab1.tx, a$
wait
Function GetParent(hWnd)
calldll #user32, "GetParent",hWnd as ulong,_
GetParent as ulong
End Function
Sub Openfile
tab$ = chr$(9)
i = 0
open "c:\users\ronnie\\desktop\test2.txt" for input as #datafile
while eof(#datafile) = 0
i = i +1
line input #datafile, csvLine$
a1$(i) = (word$(csvLine$, 1, "^"))
a2$(i) = word$(csvLine$, 2, "^")
a3(i) = val(word$(csvLine$, 3, "^"))
wend
close #datafile
End Sub
Sub SetParent hWnd,hWndChild
CallDLL #user32, "SetParent", hWndChild As uLong,_
hWnd As uLong, result As uLong
style = _WS_CHILD or _WS_VISIBLE
CallDLL #user32, "SetWindowLongA",_
hWndChild As ulong, _GWL_STYLE As long,_
style As Long, r As long
End Sub
Sub MoveWindow hWnd,x,y,w,h
CallDLL #user32, "MoveWindow",hWnd As uLong,_
x As Long, y As Long,w As Long, h As Long,_
1 As Boolean, r As Boolean
End Sub