Bad example if you want to access Controls from different Tabs
Posted by hoschy
on 07/18/2006 05:36am
It works quite nice, BUT
I want to access lets say a editcontrol in one tab from the main dialog, its just not possible.
ItB4s better to use the main Dialog for Initialization and stuff, this way you can access all editcontrols in the main Dialog. And this is what most users want i think.
All that needs to be done is add OnCancel() event handlers for all the child dialogs/forms.And within this get the Parent dialog pointer and distroy the dialog. For key press (enter) have an event handler OnOK for each child dialogs.
I ran across this on Google Groups it works well:
In your tab class code use the following line to get a hook to the main dialogs member variables and functions
CMyTabExampleDlg* pMainWnd = (CMyTabExampleDlg*) AfxGetMainWnd();
pMainWnd will then give you access to main dialog
If you put the focus to any control whithin the tab area so that the OK or CANCEL button is not selected and you hit the enter key the tab page will disappear.
I think that the reason for this is that WM_ERASEBKGND will be sent to the child window (tab page) without a WM_PAINT after the key has been pressed.
I don't think it is a good way just to ignore any WM_ERASEBKGND messages by implementing WindowProc(...), so does anybody know a better solution ?
RE: Strange behaviour on keypress (enter-/esc key)
Posted by JOC_Consulting
on 12/18/2009 06:05pm
I noticed the same problem of the Enter/Esc key causing the tab page dialog to disappear. According to the "Property Sheet as the View Window of a CFrameWnd" article at http://support.microsoft.com/kb/161886 , the reason is that the Enter and Esc keys, in MFC, are normally routed to OnOK and OnCancel, respectively. This article includes sample code that shows not only how to deal with the Enter and Esc keys, but also how to implement using Ctrl + Tab to go to the next tab page and Shift + Ctrl + Tab to go the previous tab page. My application has only 2 tabs so it hard to tell for sure, but this code seems to work properly.
RE:- Strange behaviour on keypress (enter-/esc key)
Posted by LalitSRana
on 04/22/2005 01:42am
You can think of changing this behaviour by blocking these two keys.
BOOL CDeltaLOCDlg::PreTranslateMessage(MSG* pMsg)
// TODO: Add your specialized code here and/or call the base class
if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
Firstly, many thanks to Ben Hill for showing me how to use the Tab Control. Like Alexis Giotis I also want to select a tab programmatically. Eventually I worked out how to do it by adding the another member function
void SelectTab(int nextTab);
to the CMyTabCtrl class declaration and the following definition
However, I can only get this to work when it is added after the line
in CMyTabExampleDlg::OnInitDialog() which, although it can be used to change the initial tab, it is not what I want.
If I use, say, m_tabMyTabCtrl.SelectTab(2); in another class (associated with a Check dialog with code in a TabCheck.cpp file) then I get an error message on compilation indicating that m_tabMyTabCtrl is not a class. I think that I have included all of the appropriate .h files in the .cpp file.
This is all tied up with file scope. Please be kind to me as this is only my second C++ program! Although I am an experienced Fortran, Visual Basic programmer, C is new to me (and I am struggling).
I have studied your code, and implemented it sucessfully in a dialog however...
I am writing a control panel applet, and when used, none of the controls in the 'sub' dialogs seem to get focus or have the ability to respond when clicked.
I personally belive this has somthing to do with implementing this code in a dll however, I am not sure. Any ideas?
Posted by Sam Hobbs
on 03/26/2004 08:21pm
I think the parent of the dialogs for the tabs is supposed to be the same parent as the tab control; that is not logical but Windows is not always logical. In this sample, the parent is the tab control.
Very great job with the tabcontrol, but one minor problem I can't fix.
If you move the tabs to the bottom, everything is great, except when you add an "&"-sign anywhere in your text. The moment you press the specific tab, the text bumps up a bit. It looks a bit silly.
I had create a main Dialog with a button that will show a sub dialog when click.
I create the tabControl in this sub Dialog. The funny thing is; I had no problem with one tab link to a child dialog. Problem occur when I try to add more tabs link to more child dialogs. The application die everytime I try to access the sub dialog. Worst, there is no error msg. I don't know where to trace my problem. Can somebody out there assist me?