After OnOK

Posted on 2002-04-13
Medium Priority
Last Modified: 2013-11-20

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.

Question by:Smave
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
LVL 49

Expert Comment

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


Author Comment

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.

LVL 49

Expert Comment

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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf


Expert Comment

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

Author Comment

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.

LVL 49

Expert Comment

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

Author Comment

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:

    (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:

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

LVL 49

Accepted Solution

DanRollins earned 300 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

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 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