在View类里定义m_MyDialog;
在你想显示对话框的地方:
m_MyDialog.Create(IDD_ABOUTBOX, this);
m_MyDialog.ShowWindow(SW_SHOW);就出来了~~~我觉得VC很适合初学者~~~~~

解决方案 »

  1.   

    多谢指点。
    我运行了程序,什么现象都没有发生。
    如果想在程序一开始的时候就显示这个对话框,该怎么办?
    是在app中加命令吗?
      

  2.   

    而且wizzards通过
    enum { IDD = IDD_xxx_FORM };
    把这个对话框资源赋予了view
    怎样再在view中定义一个m_MyDialog?
      

  3.   

    你想一开始就显示对话框,只要在APP中写入
    CMyDialog m_MyDialog;
    m_MyDialog.Create(IDD_ABOUTBOX);
    m_MyDialog.ShowWindow(SW_SHOW);
      

  4.   

    CMyDialog m_MyDialog应赋予一定的生存期, 如果m_MyDialog不存在, 就谈不上对话框了~~~
      

  5.   

    可是wizards并没有生成CMyDialog类啊。
    以前我都是这么做的。
    可是这次对话框资源是属于View的。
      

  6.   

    View有一个dialog资源
    这是什么意思?难道资源还能归属某类不成?
      

  7.   

    告诉你方法吧, 然后你再找本书看看, 我觉得这里只是问问题的地方, 不是学校~~~:)
    在你的View类中定义成员CDialog m_MyDialog, 已经说得很清楚了`~`~~~回复人: zx_sanjin(1.5kg, 不赊账~~~) (2001-11-28 16:18:12)  得0分 
    在View类里定义m_MyDialog;
    在你想显示对话框的地方:
    m_MyDialog.Create(IDD_ABOUTBOX, this);
    m_MyDialog.ShowWindow(SW_SHOW);就出来了~~~ 
      

  8.   

    原来是CDialog,不是CmyDialog呀。
    但是怎么在程序一开始就显示呢?
      

  9.   

    我记得appwizzard生成的东东一开始就有个象Notepad一样的东西出来啊。
    可是这回什么都没有。
      

  10.   

    哈哈。最近没怎么弄。
    就是不知道该怎样在App里调用这个VIew。
    一运行就出错。
    “winocc.cpp有错”
    我没有用这个东东啊?
      

  11.   

    单步运行后,发现是app的这句
    if (!ProcessShellCommand(cmdInfo))
    出错。
      

  12.   

    你创建的有错吧~~Frame中的Create中有m_wndXXXView的Create吗? ???
    这么就了还没解决??>??
      

  13.   

    你不会是想在app中直接调用view吧?还是想调用view里面的对话框成员阿?
      

  14.   

    单步运行,发现是这句错了:
    return _AfxDispatchCmdMsg(this, nID, nCode,
    lpEntry->pfn, pExtra, lpEntry->nSig, pHandlerInfo);
      

  15.   

    在使用AppWizard建立工程的最后一步在下拉框中选择CFormView而不是默认的CView
      

  16.   

    我KAO,你建立好PRoject后,应该自动给你加上About对话啊如果不行,可以在CWinApp::InitInstance中加上CMyAboutDialogue Mydlg;
    Mydlg.DoModal();
      

  17.   

    About是自动生成的。
    但是我要的那个没有。
      

  18.   

    建议 rush表达清除,你到底想干什么。我想可能是
    一,使用 CFormView作为基类来生成 doc/view程序,那么,就会自动产生一个大概叫做IDD_FORM_DIALOG的对话框资源
    二,如果使用 CView 作为基类,那么就不会自动产生,而要手工添加对话框资源
    如果是在程序主框架启动前就调用对话框资源,如果没有在对话框资源(IDD_FORM_DIALOG)里面添加控件,在 processshellcommand出错的机会就小,如果还不行,就查一下这个资源的属性和一般的对话框资源有什么不同
    呵呵,其实我不知道你想干什么,所以很难回答
      

  19.   

    源程序如下:
    // StockServer.cpp : Defines the class behaviors for the application.
    //#include "stdafx.h"
    #include "StockServer.h"#include "MainFrm.h"
    #include "StockServerSet.h"
    #include "StockServerDoc.h"
    #include "StockServerView.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CStockServerAppBEGIN_MESSAGE_MAP(CStockServerApp, CWinApp)
    //{{AFX_MSG_MAP(CStockServerApp)
    ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    // Standard file based document commands
    ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
    ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
    // Standard print setup command
    ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CStockServerApp constructionCStockServerApp::CStockServerApp()
    {
    // TODO: add construction code here,
    // Place all significant initialization in InitInstance
    }/////////////////////////////////////////////////////////////////////////////
    // The one and only CStockServerApp objectCStockServerApp theApp;/////////////////////////////////////////////////////////////////////////////
    // CStockServerApp initializationBOOL CStockServerApp::InitInstance()
    {
    //AfxMessageBox("Socket Init ...");
    //Initialize Socket for network connection
    //if (!AfxSocketInit())
    //{
    // AfxMessageBox("Socket Init Error!");
    // return FALSE;
    // }

    AfxEnableControlContainer(); // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.#ifdef _AFXDLL
    Enable3dControls(); // Call this when using MFC in a shared DLL
    #else
    Enable3dControlsStatic(); // Call this when linking to MFC statically
    #endif // Change the registry key under which our settings are stored.
    // TODO: You should modify this string to be something appropriate
    // such as the name of your company or organization.
    SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings();  // Load standard INI file options (including MRU) // Register the application's document templates.  Document templates
    //  serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CStockServerDoc),
    RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CStockServerView));
    AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
    if (!ProcessShellCommand(cmdInfo))
    return FALSE; // The one and only window has been initialized, so show and update it.
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    // CStockServerView sv;// int nResponse=sv.DoModal();// if (nResponse=IDOK)
    // {
    //
    // }
    // else
    // {
    // } return TRUE;
    }
    /////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    // No message handlers
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()// App command to run the dialog
    void CStockServerApp::OnAppAbout()
    {
    CAboutDlg aboutDlg;
    aboutDlg.DoModal();
    }/////////////////////////////////////////////////////////////////////////////
    // CStockServerApp message handlers
      

  20.   

    CView 不是CDialog的派生类,不能够用 DoModal来调用,用Create也许行,不过太麻烦了。不知道你想干什么,最好还是用其他的方法来实现。
    即使调用成功了,在实现对CView的操作时设及到doc/view结构的话也会出错。
      

  21.   

    另外,如果是用得CFormView生成的程序,那么会有一个对话框,调用对话框的方法:
    CDialog myDialog;
    myDialog.Create(...IDD_VIEW_FORM..);(资源好象是叫这个名字)
      

  22.   

    其实我的目的非常简单,就是要在程序开始的时候,出现一个对话框。
    由于某些原因,wizards生成时没有选用Dialog类,而是选用了View/Set类。
      

  23.   

    在View.cpp中代码如下:CStockServerView::CStockServerView()
    : CRecordView(CStockServerView::IDD)
    { //{{AFX_DATA_INIT(CStockServerView)
    m_pSet = NULL;
    //}}AFX_DATA_INIT
    // TODO: add construction code here
    CDialog m_MyDialog; m_MyDialog.Create(IDD_STOCKSERVER_FORM, this);
    m_MyDialog.ShowWindow(SW_SHOW);
    }
      

  24.   

    其实我的目的非常简单,就是要在程序开始的时候,出现一个对话框。
     
    如果是这样的话,
    CStockServerApp::InitInstance()
    {...
     CDialog m_MyDialog;
     m_MyDialog.DoModal();
     
     return TRUE;
    }
    不就可以了吗?
     
      

  25.   

    ?呵呵,对话框你也不会用啊,在资源管理里面,右键-》插入对话框,然后双击生成的对话框,派生一个CDialog的子类CMyDlg,然后
    CStockServerApp::InitInstance()
    {...
    CMyDlg myDialog;
    myDialog.DoModal();return TRUE;
    }
    你可能是想在对话框里面得到某个参数,这样,就可以在CSingleDocTemplate* pDocTemplate;以前调用对话框,把参数传递到需要的地方
      

  26.   

    嘿嘿,VC不太熟,请多指教。
    在View里面这样做不行吗?
    为什么一定要在App里面调用对话框?