Hello,
Is it possible to create new tab children at run time? Sort of like FireFox?
For instance, if I want to use the same design for every tab child, when
the user wants another search can I create a new tab?
Thanks!
John
This is a little bit more complicated but I tried an example and it appeared to work. Try the following code. It will add a new Tab at the end of the tabcontrol, create a new child tab form, and finally set the tab in focus and display the child tab. The trick is that the hwnd of the child tab form is stored in the lparam of the tab.
Function FRMMAIN_CMDADDTAB_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
Local TCITEM As TC_ITEM
Local TabNum As Long
'add a new tab to the control
TabNum = FF_TabControl_GetTabCount (HWND_FRMMAIN_TABCONTROL1) 'this is already one based
FF_TabControl_AddTab HWND_FRMMAIN_TABCONTROL1, "Tab" & Format$(TabNum+1), TabNum
'redraw the tabcontrol to clean it up
FF_Control_Redraw HWND_FRMMAIN_TABCONTROL1
'add a new child tab form by storing the hwnd of the child form into the
'lparam of the tabcontrol.
TCITEM.Mask = %TCIF_PARAM 'get the dialog's window
TCITEM.lParam = frmTabChild_Show( hWndForm, %FALSE)
TabCtrl_SetItem HWND_FRMMAIN_TABCONTROL1, TabNum, TCITEM
'set focus to the new tab. Set the selected tab to -1. This ensures that
'when the SetTabFocus function is called that the notification for TCN_SELCHANGE
'will get fired (and the child tab form correctly shown and positioned).
FF_TabControl_SetSelectedTab HWND_FRMMAIN_TABCONTROL1, -1
FF_TabControl_SetTabFocus HWND_FRMMAIN_TABCONTROL1, TabNum
End Function
Hey Paul,
That works well--Thanks! I have been playing around with changing data on different tab children though and I'm having problems.
'------------------------------------------------------------------------------------------------------------------------
FUNCTION FORM1_COMMAND1_BN_CLICKED ( _
ControlIndex AS LONG, _ ' index in Control Array
hWndForm AS DWORD, _ ' handle of Form
hWndControl AS DWORD, _ ' handle of Control
idButtonControl AS LONG _ ' identifier of button
) AS LONG
FF_CONTROL_SETTEXT (HWND_FORM2_LABEL1, FORMAT$(FF_TABCONTROL_GETTABFOCUS (HWND_FORM1_TABCONTROL1)))
END FUNCTION
Form1 is my main form with the tab control. Form2 is the tab control child
that will be made into X number of children.
The button, on form1, changes the form2 label value. It works somewhat
well--it will change the text on different tab children--but it only changes
the text on the newest created tab child. I'm not sure how to interact
with previous tabchildren that were created.
Any ideas?
Thanks!
John
Your problem is that you are using the HWND value (i.e. HWND_FORM2_LABEL1) for the label. When you use multiple instances of the same Form you *must* use the IDC value in order to ensure that the correct control is selected. I believe that there is a topic in the help about this. Also, the MDI sample code that comes with FireFly reflects this.
So, in your example, you should do the following (notice the GetDlgItem):
FF_CONTROL_SETTEXT (GetDlgItem(HWND_FORM2, IDC_FORM2_LABEL1), FORMAT$(FF_TABCONTROL_GETTABFOCUS (HWND_FORM1_TABCONTROL1)))
Ah! I see. Very cool. Thanks a lot Paul!
I'm having problems with this one again. I'm using the same form over
and over again in this tabcontrol, how do I determine the hWnd of the active tab? Like, in MDI you could send %WM_MDIGETACTIVE.
I've looked in Win32API, but the functions all seem to return the index of the tab in the control--not the handle.
Does this make sense?
Thanks!
John
Hi John,
In FireFly, the handle to the tab control child form is stored in the lParam of the tab control item for that particular page. The following should work:
Local TCITEM As TC_ITEM
Local TabNum As Long
' Determine the TabNum (i.e. the Tab index) that you need.
' TabCtrl_GetCurSel
TCITEM.Mask = %TCIF_PARAM
TabCtrl_GetItem HWND_FRMMAIN_TABCONTROL1, TabNum, TCITEM
' The hwnd of the child form should be in the lParam
MsgBox "hWnd=" & str$( TCITEM.lParam )
I haven't tested the above, but it should work (unless I have made a typo).