Cuong Nguyen -- cuong@enterprise.bidmc.harvard.edu
Monday, March 17, 1997
[Mini-digest: 6 responses]
There are different ways to do it, one of it is:
CDocument * pDoc;
pDoc = (CDocument *)((CFrameWnd *)
AfxGetMainWnd())->GetActiveDocument();
You can change CDocument & CFrameWnd in the casts to your type of
document and main frame.
simon.feltman@juno.com wrote:
>
> Environment: VC++ 4.1, Win95
>
> Hi all,
> How can I get a pointer to my document from within a
> modeless dialog? The reason for doing this is because I
> have a TabCtrl as the view with modeless dialogs created
> in the view but attached to the TabCtrl. I need to update the
> document and set the modified flag when the user changes
> something in the dialog.
>
> Another way I thought of doing it was to catch the save or
> saveas message from within the view and then update the
> document with the data from the dialogs, but then I could not
> get the document to catch the message and I would not be
> able to set the modified flag in the document.
>
> Any comments, ideas or solutions would be greatly
> appreciated.
>
> Thanks in advance,
> -Simon
-----From: ahofmann@ndc.co.il
Why not use:
AfxGetMainWnd() to get the minframe window, then from that:
p_MainWnd->GetActiveDocument();
______________________________ Reply Separator _________________________________
Subject: Document / View, modeless dialogs
Author: PC:simon.feltman@juno.com at INTERNET2
Date: 3/17/97 4:21 PM
Environment: VC++ 4.1, Win95
Hi all,
How can I get a pointer to my document from within a
modeless dialog? The reason for doing this is because I
have a TabCtrl as the view with modeless dialogs created
in the view but attached to the TabCtrl. I need to update the
document and set the modified flag when the user changes
something in the dialog.
Another way I thought of doing it was to catch the save or
saveas message from within the view and then update the
document with the data from the dialogs, but then I could not
get the document to catch the message and I would not be
able to set the modified flag in the document.
Any comments, ideas or solutions would be greatly
appreciated.
Thanks in advance,
-Simon
-----From: Syed
At 01:08 AM 3/14/97 PST, you wrote:
>Environment: VC++ 4.1, Win95
>
>Hi all,
> How can I get a pointer to my document from within a
>modeless dialog? The reason for doing this is because I
>have a TabCtrl as the view with modeless dialogs created
>in the view but attached to the TabCtrl. I need to update the
>document and set the modified flag when the user changes
>something in the dialog.
>
If it's the only document in the app (SDI), then it is easy.
Try this out:-
CMyDoc* pDoc = (CMyDoc*)(GetParentFrame()->GetActiveDocument();
If your app is MDI-kind, you may have to play around with document template.
I never do this, so I cannot give more info.
-----From: RIchard
Get a pointer to the frame window thru AfxGetMainWnd () tyhen using this
pointer use the CFrameWnd function GetActiveDocument() which will pass a
pointer to the doc. This method works anywhere to get the document
pointer.
-----From: "Dmitry A. Dulepov"
[Mailer: "Groupware E-Mail". Version 1.03.000]
> [From: simon.feltman@juno.com
>
>Environment: VC++ 4.1, Win95
>
>Hi all,
> How can I get a pointer to my document from within a
>modeless dialog? The reason for doing this is because I
>have a TabCtrl as the view with modeless dialogs created
>in the view but attached to the TabCtrl. I need to update the
>document and set the modified flag when the user changes
>something in the dialog.
>
> Another way I thought of doing it was to catch the save or
>saveas message from within the view and then update the
>document with the data from the dialogs, but then I could not
>get the document to catch the message and I would not be
>able to set the modified flag in the document.
>
> Any comments, ideas or solutions would be greatly
>appreciated.
>
>Thanks in advance,
>-Simon
> [From: simon.feltman@juno.com
>
>Environment: VC++ 4.1, Win95
>
>Hi all,
> How can I get a pointer to my document from within a
>modeless dialog? The reason for doing this is because I
>have a TabCtrl as the view with modeless dialogs created
>in the view but attached to the TabCtrl. I need to update the
>document and set the modified flag when the user changes
>something in the dialog.
>
> Another way I thought of doing it was to catch the save or
>saveas message from within the view and then update the
>document with the data from the dialogs, but then I could not
>get the document to catch the message and I would not be
>able to set the modified flag in the document.
>
> Any comments, ideas or solutions would be greatly
>appreciated.
>
>Thanks in advance,
>-Simon
COUCKE Ignace -- ccs.coucke.i@alpha.ufsia.ac.be
Thursday, March 20, 1997
[Mini-digest: 2 responses]
Environment: VC++ 4.2b, Win95
Hello Simon,
I'm working at the moment on an application which uses exactly the
same thing: a view with a TabCtrl in it. My solution is quite
simple: When I call the constructor of the modeless dialog I pass it
a pointer to the view. If you then save this pointer in a member
variable you're able to call functions like 'GetDocument().
This still left me with one problem: at the moment my data was
serialized DoDataExchange doesn't seems to be called, which made that
the data being saved wasn't 'up to date'. I'm relatively new to
MFC (in fact this is my first MFC project) and maybe I overlooked
something.
I solved this by sending a user defined message to the view in the
CMainFrame class:
BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM
lParam)
{
CView *pView = GetActiveView();
if(pView != NULL)
pView->SendMessage(UDM_UPDATEDOCDATA);
return CFrameWnd::OnCommand(wParam, lParam);
}
In my view class this message is mapped to a function which calls
UpdateData(TRUE) for the TabWindow which is open at that moment. This
function makes that my document data is always up to date whenever the
user does something else than editing data. If you want some more
control you can add an extra condition: if wParam is Save or SaveAs:
send the message.
If you're going to work with a TabCtrl I'd also like to point out
the excellent classes I downloaded from
'http://ourworld.compuserve.com/homepages/lurker/MFC.htm'. These
classes, written by Jeremy Glick and modified by Chris Scott, extend
the CTabCtrl so that it works like a CPropertySheet. I find them
easier and better to use than the original CTabCtrl class.
Finally, just a couple of days ago I heard about another solution:
construct your modeless dialogs not as a CDialog class but as a
CFormView and then add them to the Document/View using AddView.
It seems to be possible to insert them in a TabCtrl the same way as
inserting a normal dialog. Then it should be possible to use the
normal doc/view functions as GetDocument. I didn't try this out
yet.
Ignace,
Ignace Coucke,
UFSIA
Belgium
ignace.coucke@ufsia.ac.be
-- original message --
> From: simon.feltman@juno.com
> To: mfc-l@netcom.com
> Date: Fri, 14 Mar 1997 01:08:16 PST
> Subject: Document / View, modeless dialogs
> Reply-to: mfc-l@netcom.com
> Environment: VC++ 4.1, Win95
>
> Hi all,
> How can I get a pointer to my document from within a
> modeless dialog? The reason for doing this is because I
> have a TabCtrl as the view with modeless dialogs created
> in the view but attached to the TabCtrl. I need to update the
> document and set the modified flag when the user changes
> something in the dialog.
>
> Another way I thought of doing it was to catch the save or
> saveas message from within the view and then update the
> document with the data from the dialogs, but then I could not
> get the document to catch the message and I would not be
> able to set the modified flag in the document.
>
> Any comments, ideas or solutions would be greatly
> appreciated.
>
> Thanks in advance,
> -Simon
>
-----From: mwelch@tsbbank.co.uk
Environment: MSVC2.2/4.2b NT3.51, 4.2flat Win95
I experienced major problems with modeless dialogs in an MDI application=20
which I discussed with the MFC-Lers some months ago. It might be worth=20
looking in the archives for the subject "Nasty Doc\View Problem". To be=20
frank, I never resolved the issue - its still on my todo list.
Basically I wanted to send messages from the modeless dialog to the topmost=
=20
MDIChildWnd/Doc or view. The problem is that GetActiveDocument(),=20
GetActiveView() etc. returns NULL because the modeless dialog is active. I=20
also wanted to do other things, such as if there were no views open at all=20
then I wanted the CWinApp to trap the message and create a new MDI child=20
window.
As I said, I didn't really get this working so I modified the UI to avoid=20
the problem.
Anyway:
>> How can I get a pointer to my document from within a
>> modeless dialog? The reason for doing this is because I
>> have a TabCtrl as the view with modeless dialogs created
>> in the view but attached to the TabCtrl. I need to update the
>> document and set the modified flag when the user changes
>> something in the dialog.
Why don't you add a CDocument pointer as a member of your modeless dialog=20
class? This is what I had to do to get a partial solution to the problems I=
=20
mentioned above.
HTH,
Martin.
---------------------------------------------------------------------------
This email is only for the use of the addressee. It may contain information
which is legally privileged, confidential and exempt from disclosure.
If you are not the intended recipient you are hereby notified that any
dissemination, distribution, or copying of this communication and its=20
attachments is strictly prohibited. If you receive this communication in=20
error, please email nadmin@tsbbank.co.uk.
---------------------------------------------------------------------------