CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    Join Date
    Jan 2016
    Posts
    61

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by kiwagh105@gmail.com View Post
    in CMyDialog1 class file:
    m_intVariable =7;

    and in CMyDialog2 class file:
    int value;
    CMyDialog1 dlg;
    value= dlg.m_intVariable ;

    if we do not call DoModal method before assignment then dlg.m_intVariable is empty.

    please give me simple solution for this.
    I did not get that class example

  2. #17
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by kiwagh105@gmail.com View Post
    in CMyDialog1 class file:
    m_intVariable =7;

    and in CMyDialog2 class file:
    int value;
    CMyDialog1 dlg;
    value= dlg.m_intVariable ;

    if we do not call DoModal method before assignment then dlg.m_intVariable is empty.

    please give me simple solution for this.
    Please, read the http://www.flounder.com/dlgctl.htm
    You will find the solution there.
    Victor Nijegorodov

  3. #18
    Join Date
    Jan 2016
    Posts
    61

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by VictorN View Post
    Please, read the http://www.flounder.com/dlgctl.htm
    You will find the solution there.

    I tried but not able to implement. Please It will be great-full if some one send me small project zip for following task.

    1]I want to set one value to the variable on Dialogbox1 class file.
    2] I want to access that value on second dialogbox, without showing that dialogbox.

  4. #19
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by kiwagh105@gmail.com View Post
    I tried but not able to implement. Please It will be great-full if some one send me small project zip for following task.

    1]I want to set one value to the variable on Dialogbox1 class file.
    2] I want to access that value on second dialogbox, without showing that dialogbox.
    Just look at the post#10!
    You have to create a member variable in your dialog class (say it is a CMyDialog class, so use class Wizard and create the variable, say it is int m_intVariable)
    Then you write to set the variable:
    Code:
    CMyDialog dlg;
    dlg.m_intVariable = 7;
    Now you can call the DoModal to let the user interact with your dialog and after dialog will be closed you'll be able to get (probably, changed value of m_intVariable back:
    Code:
    CMyDialog dlg;
    dlg.m_intVariable = 7;
    if(dlg.DoModal() == IDOK)
    {
           int newValue = dlg.m_intVariable;
    }
    Victor Nijegorodov

  5. #20
    Join Date
    Jan 2016
    Posts
    61

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by VictorN View Post
    Just look at the post#10!
    You have to create a member variable in your dialog class (say it is a CMyDialog class, so use class Wizard and create the variable, say it is int m_intVariable)
    Then you write to set the variable:
    Code:
    CMyDialog dlg;
    dlg.m_intVariable = 7;
    Now you can call the DoModal to let the user interact with your dialog and after dialog will be closed you'll be able to get (probably, changed value of m_intVariable back:
    Code:
    CMyDialog dlg;
    dlg.m_intVariable = 7;
    if(dlg.DoModal() == IDOK)
    {
           int newValue = dlg.m_intVariable;
    }

    User breakpoint called from code at 0x758248be error showing after calling DoModal.

    This is third Dialogbox which I opened, periviously two dialogbox already opened.

    Mens 1 Main Dialogbox1 then I called second dialogbox2 using DoModal Method. And this is Third Dialogbox3 which I called.
    Is this error because of this?

  6. #21
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by kiwagh105@gmail.com View Post
    User breakpoint called from code at 0x758248be error showing after calling DoModal.
    Sounds that something is wrong in your "third Dialogbox" class implementation!

    Quote Originally Posted by kiwagh105@gmail.com View Post
    Mens 1 Main Dialogbox1 then I called second dialogbox2 using DoModal Method. And this is Third Dialogbox3 which I called.
    Is this error because of this?
    No. See above.
    What is the exact error message you see? Note that you can just press Ctrl+C to copy the whole content of the dialog box message and then post it to the Forum.
    Victor Nijegorodov

  7. #22
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by kiwagh105@gmail.com View Post
    User breakpoint called from code at 0x758248be error showing after calling DoModal.

    This is third Dialogbox which I opened, periviously two dialogbox already opened.

    Mens 1 Main Dialogbox1 then I called second dialogbox2 using DoModal Method. And this is Third Dialogbox3 which I called.
    Is this error because of this?
    No telling what's wrong from that description. Time to use your debugger to find out. It should be taking you to the error when it occurs.

  8. #23
    Join Date
    Feb 2016
    Posts
    16

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    I tried but not able to implement. Please It will be great-full if some one send me small project zip for following task.

    1]I want to set one value to the variable on Dialogbox1 class file.
    2] I want to access that value on second dialogbox, without showing that dialogbox
    comletely wrong unless you mean static variables
    Instead of trying to acces private variables of another class
    better try to obtain current object of that class and invoke it's(public) functons

    //CClass.cpp
    ...

    //Main.cpp global scope ,CClass.h included
    CClass cl;
    ...

    //CClassZ.cpp
    #include "CClass.h"
    extern CClass cl;

    CClassZ::Somestuff()
    {
    cl.whatsoever
    }

    BUT you cant do it this way with MFC dialogs(coz CDialog-derived constructor does need intra-instance stuff and fails at global scope)
    so..
    //CDialClass.cpp
    ...

    //Main.cpp global scope ,CDialClass.h included
    HWND hd;

    CDialApp::InitInstance()
    {
    CDialClass cl;
    ...
    //after cl window is created somehow
    hd=cl.m_hWnd;
    //you can do this also inside CDialClass ithelf with hd=this->m_hWnd;
    }
    ...

    //CDialClassZ.cpp
    #include "CDialClass.h"
    extern HWND hd;

    CDialClassZ::Somestuff()
    {
    //hard
    ((CDialClass *)CDialog::FromHandle(hd))->whatsoever;
    }
    Last edited by Alexeyn; March 1st, 2016 at 09:09 AM.

  9. #24
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by Alexeyn View Post
    comletely wrong unless you mean static variables
    Instead of trying to acces private variables of another class
    better try to obtain current object of that class and invoke it's(public) functons
    There's really no need to bump old threads with answers that don't make sense or have nothing to do with the original question.

  10. #25
    Join Date
    Feb 2016
    Posts
    16

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Really?
    You all just cant answer

  11. #26
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by Alexeyn View Post
    Really?
    You all just cant answer
    Did you read the thread? His question was answered by several of us.

  12. #27
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by Alexeyn View Post
    comletely wrong unless you mean static variables
    Instead of trying to acces private variables of another class
    better try to obtain current object of that class and invoke it's(public) functons

    //CClass.cpp
    ...

    //Main.cpp global scope ,CClass.h included
    CClass cl;
    Next time when you will be going to answer... please, read the Announcement: Before you post...., particularly the section about code tags.
    Victor Nijegorodov

  13. #28
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by Alexeyn View Post
    comletely wrong unless you mean static variables
    Instead of trying to acces private variables of another class
    better try to obtain current object of that class and invoke it's(public) functons

    //CClass.cpp
    ...

    //Main.cpp global scope ,CClass.h included
    CClass cl;
    ...

    //CClassZ.cpp
    #include "CClass.h"
    extern CClass cl;

    CClassZ::Somestuff()
    {
    cl.whatsoever
    }

    BUT you cant do it this way with MFC dialogs(coz CDialog-derived constructor does need intra-instance stuff and fails at global scope)
    so..
    //CDialClass.cpp
    ...

    //Main.cpp global scope ,CDialClass.h included
    HWND hd;

    CDialApp::InitInstance()
    {
    CDialClass cl;
    ...
    //after cl window is created somehow
    hd=cl.m_hWnd;
    //you can do this also inside CDialClass ithelf with hd=this->m_hWnd;
    }
    ...

    //CDialClassZ.cpp
    #include "CDialClass.h"
    extern HWND hd;

    CClassZ::Somestuff()
    {
    //hard
    ((CDialClass *)CDialog::FromHandle(hd))->whatsoever;
    }
    The more you add the worse it gets. I really can't even tell what you're trying to say here, how it helps the OP, or how it's an improvement over the previous answers.

  14. #29
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: pass variable value from one dialogbox to other/ one class to other class in vc++

    Quote Originally Posted by Alexeyn View Post
    Really?
    You all just cant answer
    Neither you could. The real problem of OP is being unable to explain what he really wants. And answer to question that sounds gibberish is initially prone to sound gibberish. Exactly like your answer does.
    Last edited by Igor Vartanov; March 2nd, 2016 at 08:17 AM.
    Best regards,
    Igor

Page 2 of 2 FirstFirst 12

Tags for this Thread

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