Solved

After OnOK

Posted on 2002-04-13
8
298 Views
Last Modified: 2013-11-20
Hello;

I have wrtten a CDialog box that collects data from user inputs.

Conditions: After the user clicks the OK button I need to have a long integer passed to a child window of the CMainFrame.

The child window contains a form based on CDaoRecordset.

The long integer will be used as such:
    SetAbsolutePosition(long x);

Question: How do I pass the long int to the child window?

I hear I could send the child window a message, but I don't know how to implement that.

Thanx
Dave
0
Comment
Question by:Smave
  • 4
  • 3
8 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
There are lots of ways to do it.  But the easiest would be in the code that starts the CDialog box.  Right after the call to DoModal returns, that code could pass the information to the window that needs the information.

What kind of window is that?  Is it a CView-derived window?  A Status bar? what?  It is usually easiest to just create a member function in that windows's class and then call that member function.

What part of this is giving you trouble?

-- Dan

0
 

Author Comment

by:Smave
Comment Utility
The MFC project has an MDI interface.

The dialog box is called by clicking on a toolbar button that is part of the MainFrame.

The information that I need to get out of the dialog box is a long integer.  I believe that a dialog box will only return an interger, so that's not an option.

I have created a global variable (a member variable on theApp) that I can use.

The view I need to pass the long integer to is based on CDaoRecordset.  The long integer will be used to goto a spacific record using the m_pSet->SetAbsolutePosition(long int) function.

I hope this helps.

Dave
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
>>I believe that a dialog box will only return an interger, so that's not an option.

A 'long int' is the same as a 'long', which is the same as an 'int'  All are 32-bit signed values.

Thus, the value obtained in the dialog box is in the correct format.  If you have that value in a member variable of the CDialog-derived object, then it is a very simple matter to place it into the global variable that you have described or, upon return from the dlg.DoModal(), just place it into the member variable of the View.

>> The view I need to pass the long integer to is based on CDaoRecordset.  

This is unlikely.  More likely you have derived from CDaoRecordView.

-=-==-=-=-=--=

I still don't understand where you are having trouble.  Forget about the dialog for the moment... Imagine that you have a global variable named gnCurRec and that variable somehow changes value.  Is the problem that you don't know how to tell the View to use that value and obtain and display the record to which it corresponds?

-- Dan
0
 

Expert Comment

by:Shielsy
Comment Utility
In OnOK() set a member variable within the CDialog box e.g. m_iInt = 1;

After DoModal() returns, you can simply access the value in CMainFrame e.g.

CMyDlg dlg;
if (dlg.DoModal()==IDOK)
    int iInt = dlg.m_iInt; // <- get the value here
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Smave
Comment Utility
>>Is the problem that you don't know how to tell the View
>>to use that value and obtain and display the record to
>>which it corresponds?

Yes and no.

No, because I know how to use the m_pSet->SetAbsolutePosition(long int) function.

Yes, because I don't know how to "trigger" a member function in the CDaoRecordView class to find the spcified record.

Let me see if I can simplify my problem:
-- I have a long int that is a member variable in the MainFrame class of an MDI project.
-- This long int will be used to find a record on a form based on CDaoRecordView.

thanx
Dave
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Check out the member function CDaoRecordView::OnMove() it provides a standard way to move to the first, last, previous, or next record.  You can find the source sode for this function in a file naamed DAOVIEW.CPP in the MFC/SRC folder.  To move to any arbitrary record, just do the same thing it does:  call

    m_pSet->SetAbsolutePosition( n );
    UpdateDate( FALSE );

-- Dan
0
 

Author Comment

by:Smave
Comment Utility
I figured it out.

In StdAfx.h I added:
#define WM_GOTO_ABSPOS     WM_USER + 7

In the OnOK function of the dialog box class I added:
::PostMessage(theApp.m_hWnd_Browser,WM_GOTO_ABSPOS,lKey,1);

    (m_hWnd_Browser is a global variable.  When the form
     is loaded it's HWND is stored here for later use)

In the CDaoRecordView derived class, CBBView I added:
ON_MESSAGE(WM_GOTO_ABSPOS, CBBView::D_OnRcvdAbsPos)
in MESSAGE_MAP

The problem was I used to have it coded like so:
ON_MESSAGE(WM_GOTO_ABSPOS, D_OnRcvdAbsPos)
thus the function was never called.
However, I don't know why it was never called.  Maybe someone can answer that.

thanx
Dave
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
Comment Utility
>>I don't know why it was never called.  
ON_MESSAGE is a macro and the parameters need to be just right.

Your method may work, but it is overly complex.  You could just create a member function in the View and call it directly upon return from DoModal().

-- Dan
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now