Author Topic: Visual C++ problem, please help  (Read 3408 times)

vvalentine

  • *
  • Posts: 633
    • View Profile
Visual C++ problem, please help
« on: 2003-02-05 03:16:55 »
Well, I'm a noob when it comes to MFC.  I just starting programming with MFC a couple of weeks ago, and there are still many things I don't know.

Here is my problem.

I'm trying to pass int and double variables from dialog to dialogs, and every time I try to make a non-mfc class I keep getting errors.  So far I know how to pass strings from one dialog to another dialog, but I need to pass variables.  I was also thinking of using pointers to pass the variables, but I still kept getting other errors.  If you guys can give me a code example, that would be truly appreciated.  My head hurts, and I'm running out of time.  I've been able to solve many of the obstacles I've had coding the program, but unfortunately I haven't found any tuturials for this next problem.

So if you guys can help me, and spare me some sanity, it will really help.  Thanks in advance.

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
Visual C++ problem, please help
« Reply #1 on: 2003-02-05 11:54:25 »
You should be more specific about the errors.

To pass a value is easy thing. Lets say you have a dialog class defined, it has its own file.cpp and file.h; in file.h there should be something like:
Code: [Select]
class CXXXXXDlg : public CDialog {
public:
CXXXXXXDlg(CWnd* pParent = NULL);

 blablabla
}

add there something like
Code: [Select]
public: double d;
public - everything after it is accessible from outside the dialog.
example:
Code: [Select]
class CXXXXXDlg : public CDialog {
public:
CXXXXXXDlg(CWnd* pParent = NULL);
public:
  double  d;
  int   i;

 blablabla
}


then, when you use the dialog values are passed like:
(static version)
Code: [Select]

   ....
  CXXXXXDlg   dlg;
  dlg.d = 1.5;
  dlg.i = 5;
  dlg.DoModal();
  ....

(dynamic)
Code: [Select]

   ....
  CXXXXXDlg   *dlg;

  dlg = new CXXXXXDlg;
  dlg->d = 1.5;
  dlg->i = 5;
  dlg->Create();
  ....


and inside the dialog you can access the variables just like
Code: [Select]
if ( d > 5.0 )
   i = 2;


but be more specific on the errors. Copy and paste them here.

vvalentine

  • *
  • Posts: 633
    • View Profile
Visual C++ problem, please help
« Reply #2 on: 2003-02-05 18:25:20 »
LOL, Oh man, I can't believe it's that easy, I feel dumb.  Well, I kinda worked around that problem in a lame way.  Since the only thing I was able to pass was char strings, I kinda make check statements for each string.

Well, one error I had got was during the linking process that array[3][4][5][6] was defined in another object.  But I figured that one fast though, I remembered I had defined it somewhere else and so I went and deleted those definitions in the other cpp file.

The other error I kept getting was that I was trying to send variables to a non-mfc class (one not created by classwizard), but with the example you gave me, I see there is no need for me to create another class.

Well, I'm almost done with the project, I launched myself at doing the program using mcf instead of just console having the chance of failing, even more without knowing anything about programming using the mfc classes.  Well, thanks for the help, I really appreciate it.

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
Visual C++ problem, please help
« Reply #3 on: 2003-02-06 11:13:21 »
If you dont have need to use Mfc classes you dont have to use them. That way i showed you works in any class.

vvalentine

  • *
  • Posts: 633
    • View Profile
Visual C++ problem, please help
« Reply #4 on: 2003-02-06 11:46:07 »
I know that's the way you use them with other classes, but I've never used mfc classes and I though objects were handled differently.  And since I'm doing the program with dialogs, I guess I would have the need to use the mfc classes.  Thanks for advice though.