Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

After OnOK

Posted on 2002-04-13
8
Medium Priority
?
353 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
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…

597 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