Search code examples
c++visual-c++mfcdialoginputbox

Input Box in an MFC CWinApp


I want to use a simple input box in vc++ mfc. I did created a dialog called IDD_DIALOG1, and added a text box. I added a public variable for the input box and created a class call CInputDlg. Now I use the following code but I face with error:

CInputDlg dialog;
if (dialog.DoModal() == IDOK) 
{
    m[nodeTemp][i] = weight;
}

the error is:

Error   2   error C2065: 'CInputDlg' : undeclared identifier    c:\users\omid\documents\visual studio 2008\projects\shortest path\shortest path\shortest pathdlg.cpp    294

what's the problem? can anyone help me please?


Solution

  • At the top of the file containing this code (it looks like you've named it shortest pathdlg.cpp):

    CInputDlg dialog;
    if (dialog.DoModal() == IDOK) 
    {
        m[nodeTemp][i] = weight;
    }
    

    You need to add an #include statement that tells the compiler you'll be using things defined in a different source code file. In this case, you need to add the header file that defines the class CInputDlg. Presumably that file is called InputDlg.h. If so, you can simply add the following line:

    #include "InputDlg.h"
    

    For more information, please read this MSDN article about #include Directives in C++