|
rp_suman wrote: Is it meaningful to use with RDW_INVALIDATE
Yes, ofcourse.
If you have new question, start new thread, users here usually doesn't turn back to to old posts( but I do in this case ) , unless got any email notification.
|
|
|
|
|
Thanks for help!
Wishing you a Happy New Year!!
Thanks & Regards,
Suman
|
|
|
|
|
I am using MFC. I want to add a tab control in an existing dialog box. I found this example:
http://www.codeproject.com/useritems/Simple_Tab_Control.asp
but it seems that you have to create a window for each tab, with the main Window having just the tab control. How can I add a tab control without having to redo what I already have?
|
|
|
|
|
The Windows tab common control provides the tabs but you still need to provide a window for each
tab.
What is it you are trying to do by adding a tab control without additional windows?
|
|
|
|
|
Well, not necessary WITHOUT additional windows, but place my existing dialog window inside a tab.
The reason I want to do that is because my app really will be performing the task of two related apps. So instead of having two seperate executables, I was thinking use two tabs, one for each "app".
|
|
|
|
|
Cool. You could make the dialogs modeless child dialogs if they aren't already (they could
even be the same class).
Instead of making the tab control a child of the dialog, make it a child of a simple frame
window. The frame window can hold the tab control and the dialogs and handle all the
associated resizing/repositioning. That gives you the option of a common toolbar and status
bar as well.
Just a thought.
|
|
|
|
|
how do I change my existing dialog (which is the main dialog window for the project) to a child? And how to I set another window (frame window) to be the new parent of the project?
Thanks
Also, would it be necessary for the main window to have OnInitDialog, OnSysCommand, OnPaint, and OnQueryDragIcon. In which case, I would have to add those functions in the new main window, and remove them from what is now the child window? And also transfering the system menu (including the about...)?
-- modified at 22:10 Monday 18th December, 2006
|
|
|
|
|
It'll just take a little rearranging....not too much code.
acerunner316 wrote: how do I change my existing
dialog (which is the main dialog window for the project) to a child? And how to I set another
window (frame window) to be the new parent of the project?
In your application class' InitInstance() override you probably have something like this:
CMyMainDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
...
You'd replace that with something like:
CMainFrame* pFrame = new CMainFrame;
if (!pFrame)
return FALSE;
m_pMainWnd = pFrame;
if (!Create(NULL, _T("Window Name"),
WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CRect(50,50,400,400), NULL, NULL, 0, NULL))
return FALSE;
...
CMainFrame would be a CFrameWnd-derived class. You can override CFrameWnd::OnCreateClient() and
in your implementation create the tab window and the two modeless dialogs.
All the necessary code for managing a tab control will need to be added as well.
acerunner316 wrote: Also, would it be necessary for
the main window to have OnInitDialog, OnSysCommand, OnPaint, and OnQueryDragIcon. In which case,
I would have to add those functions in the new main window, and remove them from what is now the
child window? And also transfering the system menu (including the about...)?
The main window has OnCreateClient(). Instead of OnInitDialog there's OnCreate() (handler for
WM_CREATE). Your dialog classes would stay the same. They still need their OnInitDialog()
overrides to initialize their controls and whatever else you do there. Same with OnPaint.
OnQueryDragIcon., OnSysCommand, and the about-window stuff would probably move to the frame
window class.
|
|
|
|
|
is it necessary to derive a CFrameWnd class? Is there anything wrong with creating a dialog window (called IDD_MAINFRAME) in resource editor and changing the first line of...
CMyMainDlg dlg;<br />
m_pMainWnd = &dlg;<br />
int nResponse = dlg.DoModal();<br />
if (nResponse == IDOK)<br />
...
...to CMainFrame dlg;? What's the benefit of CFrameWnd vs CDialog in my situation?
Also how does a child tab window handle OnCancel, OnDestroy, and PostNcDestroy. Do I even need that anymore?
-- modified at 15:05 Tuesday 19th December, 2006
|
|
|
|
|
Use whatever you want. They are all windows (have an HWND).
A dialog implies a dialog resource. If you are going to have a tab control with 2 tabs, each
containing a dialog then there is no reason to use a dialog to contain the tabs, inless you
have other controls placed around the tabs that are laid out in a DIALOG resource. If that's
the case then a dialog will work fine too.
The advantage of CFrameWnd over CWnd is the automagic handling of decorations - toolbar, status
bar, etc - and auto-sizing/positioning of an imbedded "client" window (around any decorations).
A CWnd will work fine. So will a dialog if that's what you need.
There's nothing wrong with handling it all yourself. You have complete control over all the
windows in your app.
|
|
|
|
|
I've successfully added a tab control with two dialog windows as child. The first tab is my original app that WAS my main window, and the second tab is a completely new dialog window (for now just has an editbox).
The code compiles and I can run it, and it opens with default on the first tab. But none of the controls from the first tab works properly. Debugger says access violation.
|
|
|
|
|
What type is the main window now?
acerunner316 wrote: But none of the controls from the first tab works properly. Debugger says access violation.
These two are maybe related? Where does the exception occur? If it's MFC can you trace the stack
back into your code?
Without seeing the code for how you create the two dialogs and how you handle placing them in the
tabs it's tough to guess
Mark
|
|
|
|
|
The main window is a CDialog, and so are the two child tab windows. All generated in resource editor.
I've removed theOnSysCommand, OnPaint, and OnQueryDragIcon from the original main window, and added into the new main window. OnInitDialog stayed but I removed the part that generates the about box. Not sure what to do about OnCancel, OnDestroy, and PostNcDestroy, so I left it as it is. To create the tabs I basically followed this example exactly (http://www.codersource.net/mfc_ctabctrl.html).
The error is "Unhandled exception in [myappname].exe (NTDLL.DLL): 0xC0000005: Access Violation."
Thanks.
|
|
|
|
|
acerunner316 wrote: The error is "Unhandled exception in [myappname].exe (NTDLL.DLL): 0xC0000005: Access Violation."
Right, but where? If it's not stopped on a line of your code can you view the stack trace and
find the last line of your code that executed before the exception?
|
|
|
|
|
Ok, I fixed the problem. For some reason, a clean and a rebuild fixed the problem.
But now another minor problem has arisen. I have a small popup loading dialog window that should be popping up centered relative to the main dialog window. (If you recall, you helped me with that in another forum thread.) Now with the tab, the popup window is created in the upper left corner of the tab window.
Here is how it is created.
EnableWindow(FALSE);<br />
pLoadingDlg = new CLoading;<br />
pLoadingDlg->Create(IDD_LOADING, this);
pLoadingDlg->ShowWindow(SW_SHOW);
I tried using this to move it.
CRect MainDialogRect, LoadDialogRect;<br />
GetClientRect(&MainDialogRect);<br />
pLoadingDlg->GetWindowRect(&LoadDialogRect);<br />
pLoadingDlg->MoveWindow((MainDialogRect.Width() - LoadDialogRect.Width()) / 2, <br />
(MainDialogRect.Height() - LoadDialogRect.Height()) / 2, <br />
LoadDialogRect.Width(), LoadDialogRect.Height());
But it just places the window at the correct location, but relative to the screen, and not to the main window.
Also the EnableWindow(FALSE); no longer works. Is it safe to use GetParent()->EnableWindow(FALSE); ?
-- modified at 16:02 Wednesday 20th December, 2006
|
|
|
|
|
What class is this called from (which window)?
EnableWindow(FALSE);
pLoadingDlg = new CLoading;
pLoadingDlg->Create(IDD_LOADING, this); //"this" or "GetParent()"
pLoadingDlg->ShowWindow(SW_SHOW);
|
|
|
|
|
it is called from what is now a child tab window. The code worked fine as the main dialog window until i started using tabs.
|
|
|
|
|
Does this work?
CRect MainDialogRect, LoadDialogRect;
GetParent()->GetClientRect(&MainDialogRect);
pLoadingDlg->GetWindowRect(&LoadDialogRect);
pLoadingDlg->MoveWindow((MainDialogRect.Width() - LoadDialogRect.Width()) / 2,
(MainDialogRect.Height() - LoadDialogRect.Height()) / 2,
LoadDialogRect.Width(), LoadDialogRect.Height());
|
|
|
|
|
Argg sorry - try this
CRect MainDialogRect, LoadDialogRect;
GetWindowRect(&MainDialogRect);
::MapWindowPoints(0, *this, (LPPOINT)&MainDialogRect, 2);
pLoadingDlg->GetWindowRect(&LoadDialogRect);
pLoadingDlg->MoveWindow((MainDialogRect.Width() - LoadDialogRect.Width()) / 2,
(MainDialogRect.Height() - LoadDialogRect.Height()) / 2,
LoadDialogRect.Width(), LoadDialogRect.Height());
Tab control doesn't really have a useful client rect so I've taken it's window rect (relative to
the screen) and mapped it to be relative to itself.
I think that will work...
|
|
|
|
|
Now that I think about it more, the MapWindowPoints() isn't necessary since you only need
the size of the tabs control, not it's position. You can probably eliminate that call.
The important part is using GetWindowRect instead of GetClientRect.
|
|
|
|
|
I still get the same result with that code. But that gave me an idea. Here's what I did to fix it.
CRect MainDialogRect, LoadDialogRect;
GetParent()->GetWindowRect(&MainDialogRect);
pLoadingDlg->GetWindowRect(&LoadDialogRect);
pLoadingDlg->MoveWindow(MainDialogRect.left + ((MainDialogRect.Width() - LoadDialogRect.Width()) / 2),
MainDialogRect.top + ((MainDialogRect.Height() - LoadDialogRect.Height()) / 2),
LoadDialogRect.Width(), LoadDialogRect.Height());
I found that I was always getting the correct coordinates, just relative to the wrong point (screen origin vs window origin). So I added the location of the main window to the coordinates.
|
|
|
|
|
Whatever works. Seems weird (obviously, or you would't have asked about it in the first
place) that you'd get screen-relative coordinates from GetClientRect()...
|
|
|
|
|
Yeah that IS very unusual. Maybe something to do with the fact that it's a tab window. Who knows what actually goes on in the GetClientRect() function. Maybe you do, but I sure don't. You are clearly much more experienced in VC++ than me.
|
|
|
|
|
acerunner316 wrote: Maybe you do, but I sure don't.
Not me.
I dug in my existing code and saw I was mapping the window rect points like that second code
I posted (in my case I handle the tab control and all the associated tab windows from the tab's
parent window class so it's a little different).
Regardless, the MoveWindow call should move the child window relative to it's parent's client area.
Beats me!
|
|
|
|
|
Another question, since the two tabs does very similar tasks and functions, is it possible to use the same dialog class for both tabs, but different resource dialog (ie IDD_TAB1 and IDD_TAB2 both associated with CTabDlg)? The layout will be different, but I will be reusing most of the same functions.
|
|
|
|