CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2004
    Posts
    1,352

    Foriegn CFromView Class in Dialog Class.

    Anybody know of any articles that show how to use a Foriegn Class with in a Dialog Class?

    I got it to work, but I want to see if I'm overlooking anything?
    Rate this post if it helped you.

  2. #2
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Foriegn CFromView Class in Dialog Class.

    What do you mean by "Foriegn Class"?

  3. #3
    Join Date
    Jun 2004
    Posts
    1,352

    Re: Foriegn CFromView Class in Dialog Class.

    Accessing the members of another class with the help of ClassWizard.

    For Example:

    When doing a CRecordSetView you have access to the CRecordSet data members in class wizard.

    I use Formview with Dialog boxes. I want to be able to access the FormView datamembers directly from class wizard without having to define a member variable for the CDialog Class and then assigning the value to the CFormview member variable.

    If you do it right you classwizard will create the following:
    DDX_Text(pDX, IDC_EDIT_VAR1, m_pFView->m_csDg1Var1);
    in DoDataExchange,

    where:

    m_pFView
    is a pointer to the Formview class which called the CDialog class. I can then edit the Formview data members directly without having to create an extra variable and assignment statements.

    For Example I did the following:
    void CMyFormView::OnButtonDialog1()
    {
    // TODO: Add your control notification handler code here

    this->m_Dlg1.m_pFView = this;
    this->UpdateData();
    this->m_Dlg1.DoModal();
    this->UpdateData(FALSE);

    }
    And I'm able to access the Formview Vars and edit them directly. Classwizard will list all the CFormView Vars so I can edit them directly.

    I'm surprised that there is not much info on this approach to using CDialog since it is more effiecient (computing and memory wise) as well esier to code. I don't even have to filter ID_OK since the framework does it already. Data will only be updated if you hit OnOk.

    It's pretty cool.
    Rate this post if it helped you.

  4. #4
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Foriegn CFromView Class in Dialog Class.

    Intersting, I've never done it this way. What version of the VS do you use it with?

  5. #5
    Join Date
    Jun 2004
    Posts
    1,352

    Re: Foriegn CFromView Class in Dialog Class.

    VS6, it has a class wizard. I read that VS2003 and up don't have a class wizard, up until VS2010.

    However, if you do a CRECORDSETVIEW project it SHOULD have a foriegn class variable, that is where I got the idea. You might want to try that.

    You have to do a forward class definition though to implement the technique I talked about.

    I did the following:

    In my Dialog Header File
    class CMyFormViiew;

    In my Cpp file:
    #include "MyClassDoc.h"
    #include "MyFormView.h"

    When you declare the foriegn variable, classwizard will create the member variable.

    ..It works pretty cool, I'm surprised there is not much written about this approach.
    Rate this post if it helped you.

  6. #6
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Foriegn CFromView Class in Dialog Class.

    Quote Originally Posted by ADSOFT View Post
    VS6, it has a class wizard. I read that VS2003 and up don't have a class wizard, up until VS2010.
    They actually did away with it in VS2002 that followed VS6, and you're correct they resurrected it in VS2010. IMO, I really liked the class wizard in VS6 and was missing it a big time in VS2002, but as time passed (8 years for god's sake) I got used to the other way so now I'm not sure if I'd be going back to the wizard in VS2010 any time soon. The Add Member and Add Function replacements introuced in VS2002 that stayed until VS2008 are so fickle and unreliable that I learned to code most of my class members manually (without using any sort of IDE automation).

    Another thing that suffered a big time (in my opinion) is the Intellisense (since VS2003). Even though they added some good features to it (like the ability to unfold and view structures during debugging) it is still very slow to respond and at times doesn't show the correct or helpful info. I really want it to go back to the way it used to be in VS6 or VS2002.

    On the sidenote, I'm not sure that I'd be using VS2010 any time soon either. The reason is simple -- the CRT and MFC (that I'm using the most) are so bloated in size, plus the code VS2010 compiler makes is only compatible with Windows XP and up, so I'm going to stick with VS2008 w/o SP1 for awhile.

    A question I have to you, is it actually legal (or documented) to use class members like you do? It wouldn't cause some internal conflict with the MFC stuff itself, would it? (If you want to post a sample of what you're doing and I can test it to see if it works under VS2010)

  7. #7
    Join Date
    Jun 2004
    Posts
    1,352

    Re: Foriegn CFromView Class in Dialog Class.

    That's why I posted my approach to get opinions from others.

    I have a simple app(VS6 ) which might not be compatible with some of the newer VS versions.

    The more I think about it I don't think it should be a problem since the all you are really doing is
    DDX_Text(pDX, IDC_EDIT_VAR1, m_pFView->m_csDg1Var1);
    which should be ok because you are just pointing to a string.

    You can try this youself, create a pointer to another dialog box and access the member via a pointer, you should be able to update the varialbe.

    I do have a question for you though, in VS2003 and Up, when you do a CDAORECORDVIEW or CRECORDVIEW does VS give you a list of database fields when you are biniding variables to the Editbox's?
    Rate this post if it helped you.

  8. #8
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Foriegn CFromView Class in Dialog Class.

    Quote Originally Posted by ADSOFT View Post
    I do have a question for you though, in VS2003 and Up, when you do a CDAORECORDVIEW or CRECORDVIEW does VS give you a list of database fields when you are biniding variables to the Editbox's?
    Listen, I haven't done anything with databases for quite a long time. Either post a test project with what you mean, or give me the database specs you're using in your project?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured