July 13, 2024, 07:31:30 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Need some help with my first GUI.

Started by Jim Scott, January 17, 2007, 11:52:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jim Scott

I'm finally getting a handle on the tools for making a GUI.  I've got the layout for the program I'm writing pretty well set in the following code.  It uses Buttons above a list of Tabs.  The buttons are to operate on data contained in the selected tab.  I need each tab to be able to have a different listview object (different number of fields, different information to list, different ordering etc).

/* A GUI for Rancho Oso's Who's Here Program
   Compile as Windows.exe
James R. Scott
Jan 17, 2007
*/

Def win as Window
Def tc, Run as Int
Def Caption as String
Def Left, Top, Width, Hieght as UInt
Def tbArray[11] as Int
Def StatusBarBoxes[4] as Int
' Button Identifiers
Const idSearch = 0x100
Const idButton_1 = 0x101
Const idButton_2 = 0x102
Const idReload = 0x103
Const idPrint = 0x104
Const idQuit = 0x105
' Identifiers for the Status Bar, Toolbar, and the Tab Areas
Const idStatusBar = 100
Const idToolbar = 101
Const idTab = 102
' Identifiers for the Tabs
Const idAllCampers = 0
Const idCampsites = 1
Const idCampersToFind = 2
Const idRentals = 3
Const idRVStorage = 4
Const idHorseBoarder = 5
Const idGuestTracker = 6
' External functions
Declare IMPORT,GetSysColor(nIndex as INT),UINT
Declare "user32",CreateWindowExA(ex:int,class:string,name:string,style:int,x:int ,y:int,x1:int,y1:int,parent:UINT,id:int,hinstance:int,ed:int),uint
Declare "user32",DestroyWindow(wnd:uint),int
' I'm not sure what these are for yet
setid "WS_VISIBLE",0x10000000
setid "WS_CHILD",0x40000000
' Have no idea what these mean, but they are required
Const TCM_INSERTITEM = 0x1307
Const TCN_SELCHANGE = -550-1
Const TCM_GETCURSEL = 4875

Run = 1
' Define the main window
OPENWINDOW win,0,0,900,800,@NOAUTODRAW|@SIZE|@MINBOX|@MAXBOX|@SYSMENU,0,"Who's @ Rancho Oso",&handler
SETWINDOWCOLOR win,GetSysColor(15)

' Add a status window for messages
Control win,@STATUS," Welcome to Who's @ Rancho Oso",@Border,0,0,0,0,idStatusBar
StatusBarBoxes = 400,600,700,-1
ControlCMD win,idStatusBar,@SWSETPANES,4,StatusBarBoxes

'create a toolbar. It will send its messages to the main window
tbArray = 0,idSearch,0,idButton_1,idButton_2,0,idReload,0,idPrint,0,idQuit
If LOADTOOLBAR(win,"",idToolbar,tbArray,11,@TBTOP|@Border) Then
CONTROLCMD win,idToolbar,@TBSETLABELS,"Search|Button 1|Button 2| Reload Data |Print List|Quit||"
CONTROLCMD win,idToolbar,@TBENABLEBUTTON,idButton_1,FALSE
CONTROLCMD win,idToolbar,@TBENABLEBUTTON,idButton_2,FALSE
EndIf
GetSize(win,Left,Top,Width,Hieght)
tc=CreateTabControl(win,idTab,3,45,Width-13,Hieght-99)

AddTab(tc,idAllCampers,"All Campers")
AddTab(tc,idCampsites,"Camp Sites")
AddTab(tc,idCampersToFind,"Campers To Find")
AddTab(tc,idRentals,"Rentals")
AddTab(tc,idRVStorage,"RV Storage")
AddTab(tc,idHorseBoarder,"Horse Boarders")
AddTab(tc,idGuestTracker,"Guest Tracker")

WaitUntil Run = 0
DeleteTabControl(tc)
CloseWindow win
END


Sub handler
Select @CLASS
Case @IDCLOSEWINDOW
Run = 0
Case @IDSIZE
ResizeAll()
Case @IDCONTROL
Select @NOTIFYCODE
    Case TCN_SELCHANGE
temp = GetSelectedTab(tc)
' ControlCMD win,idStatusBar,@SWSETPANETEXT,1,Str$(temp)
Select temp
Case idAllCampers
ControlCMD win,idStatusBar,@SWSETPANETEXT,1," All Campers Tab Selected"
Case idCampSites
ControlCMD win,idStatusBar,@SWSETPANETEXT,1," Campsites Tab Selected"
Case idCampersToFind
ControlCMD win,idStatusBar,@SWSETPANETEXT,1," Campers To Find Tab Selected"
Case idRentals
ControlCMD win,idStatusBar,@SWSETPANETEXT,1," Rentals Tab Selected"
Case idRVStorage
WindowOptions = @Border|@Size|@LVSSHOWSELALWAYS|@VSCROLL|@HSCROLL|@LVSREPORT
'CONTROL win,@LISTVIEW,"",0,0,500,600,WindowOptions,idRVStorage
ControlCMD win,idStatusBar,@SWSETPANETEXT,1," RV Storage Tab Selected"
Case idHorseBoarder
ControlCMD win,idStatusBar,@SWSETPANETEXT,1," Horse Boarders Tab Selected"
Case idGuestTracker
ControlCMD win,idStatusBar,@SWSETPANETEXT,1," Guest Tracker Tab Selected"
EndSelect
EndSelect
If @NOTIFYCODE = 0 /* ignore any tooltip messages */

Select @CONTROLID

Case idSearch
ControlCMD win,idStatusBar,@SWSETPANETEXT,0," You Pressed the Search Button"
Case idButton_1
ControlCMD win,IdStatusBar,@SWSETPANETEXT,0," You Pressed Button 1"
Case idButton_2
ControlCMD win,IdStatusBar,@SWSETPANETEXT,0," You Pressed Button 2"
Case idReload
ControlCMD win,IdStatusBar,@SWSETPANETEXT,0," You Pressed the Reload Button"
Case idPrint
ControlCMD win,IdStatusBar,@SWSETPANETEXT,0," You Pressed the Print Button"
Case idQuit
ControlCMD win,IdStatusBar,@SWSETPANETEXT,0," Pressed Quit"
Run = 0
EndSelect
EndIf
EndSelect
Return
EndSub

Sub ResizeAll
' The Get*Size functions return width and height instead of right and bottom
WINRECT rcClient,rcStatus,rcTab,rcTool
' Tell the status bar and the Toolbars to resize themselves
ControlCMD win,idStatusBar,@SWRESIZE
ControlCMD win,idToolbar,@TBRESIZE
GetClientSize win,rcClient.left,rcClient.top,rcClient.right,rcClient.bottom
GetSize win,rcStatus.left,rcStatus.top,rcStatus.right,rcStatus.bottom,idStatusBar
GetSize win,rcTool.left,rcTool.top,rcTool.right,rcTool.bottom,idToolBar
rcClient.bottom = rcClient.bottom - rcStatus.bottom - rcTool.bottom - 2
rcClient.top = rcTool.bottom + 2
rcClient.left = 3
rcClient.right = rcClient.right - 5
SetSize win,rcClient.left,rcClient.top,rcClient.right,rcClient.bottom,idTab

Return
EndSub

Sub CreateTabControl(parent:WINDOW,num:int,x:int,y:int,w:int,ht:int),UINT
tc = CONTROLEX(parent,"systabcontrol32","",x,y,w,ht,@EXCLIENTEDGE,0,num)
return tc
EndSub

Sub AddTab(hWnd:uint,index:int,text:string)
type TC_ITEM
def mask:int
def res1:int
def res2:int
def pszText:POINTER
def cchTextMax:int
def iImage:int
def lParam:int
endtype
def tie:TC_ITEM
tie.mask=1
'TCIF_TEXT=1
tie.pszText=text
tie.cchTextMax=len(text)
tie.iImage=-1
SendMessage(hWnd,TCM_INSERTITEM,index,tie)
Return
EndSub

Sub GetSelectedTab(hWnd:uint),INT
temp = SENDMESSAGE(hWnd,TCM_GETCURSEL,0,0)
Return temp
EndSub

Sub DeleteTabControl(hWnd:uint)
DestroyWindow(hWnd)
Return
EndSub


I have a couple of questions here.

Since the tabs don't have an id like a listview control within a dialog, how do I select a tab (bring it in focus) without using the mouse operated "GetSelectedTab()" function?

Where in the handler should I initialize each listview?

How do I get the listview controls to have the appropriate tab as a parent?

Am I going about this in the right way?

I know I'm asking a lot here.  I really feel like I'm getting somewhere with EBASIC.  The more I learn, the more I like it.
Jim Scott

ExMember001

here is the options dialog of my audio player
i use tab controls and listview,buttons ect


ExMember001


ExMember001

the trick is to create all controls, but dont show them.
When the tab control get selchange, restore the controls
then hide again when the tab change

Jim Scott

KrYpT,

Thanks for the reply.  I can sort of follow the code you attached.  I'll look at closer.

Jim
Jim Scott