Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

After OnOK

Posted on 2002-04-13
8
Medium Priority
?
355 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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

578 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