Solved

After OnOK

Posted on 2002-04-13
8
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6939641
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
ID: 6949274
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
ID: 6949535
>>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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Shielsy
ID: 6950199
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
 

Author Comment

by:Smave
ID: 6950207
>>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
ID: 6951270
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
ID: 6952034
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
ID: 6952134
>>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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

707 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