请问高手:如何在窗口函数中,调用应用数程序中的一般函?在就是我对窗口函数的理解还很模糊,窗口函数同应用程序之间是进程调用的关系吗?是不是需要宣布远程指针指向应用程序对象,以及应用程序函数?实例的句柄是不是指向对象的指针?

解决方案 »

  1.   

    void CTestvcsott1View::OnDoubleclickedButton3() 
    {
    // TODO: Add your control notification handler code here
    void (CTestvcsott1App::*p2)();           
    p2=&CTestvcsott1App::testcontrolapp; 
     
      AfxMessageBox("OnDoubleclickedButton3 ok");}
      

  2.   

    你说的窗口函数是类成员函数?
    你在view类的成员函数里调用这个 CTestvcsott1App::testcontrolapp ?这个testcontrolapp是静态的成员函数吗?是public的吗?不是静态的就要用CTestvcsott1App类的对象或指针去调用,不是public的无法访问
      

  3.   

    是不是有一个对象CTestvcsott1App theApp;?
    如果是,那你可以直接调用的说。如果testcontrolapp是其公有的成员函数,你可以直接这样调用:
    theApp.testcontrolapp();
    不过你要在调用之前让编译器知道存在一个名为theApp的对象,所以,你最好在头文件中加上:
    extern CTestvcsott1App theApp;
      

  4.   

    应用类是这样的:class CTestvcsott1App : public CWinApp
    {
    public:
    CTestvcsott1App();
         void oracleapp();                   
         void testcontrolapp();               
     void testoracle();                  
         void checkerr(int status, char *t_string);  // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CTestvcsott1App)
    public:
    virtual BOOL InitInstance();
    //}}AFX_VIRTUAL// Implementation
    //{{AFX_MSG(CTestvcsott1App)
    afx_msg void OnAppAbout();
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    但在视类中的Button3双击响应函数中,想用一般的近程指向CTestvcsott1App类的函数指针,在调用函数是编译出错,应该是说近程指针不匹配,怎样修改成远程指针定义?不是说CTestvcsott1App theApp;只能在程序中出现一次吗?class CTestvcsott1View : public CFormView
    {
    protected: // create from serialization only
    CTestvcsott1View();
    DECLARE_DYNCREATE(CTestvcsott1View)public:
    //{{AFX_DATA(CTestvcsott1View)
    enum{ IDD = IDD_TESTVCSOTT1_FORM };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA// Attributes
    public:
    CTestvcsott1Doc* GetDocument();// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CTestvcsott1View)
    public:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    virtual void OnInitialUpdate(); // called first time after construct
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CTestvcsott1View();
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endifprotected:// Generated message map functions
    protected:
    //{{AFX_MSG(CTestvcsott1View)
    afx_msg void OnDoubleclickedButton3();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    void CTestvcsott1View::OnDoubleclickedButton3() 
    {
    // TODO: Add your control notification handler code here
    void (CTestvcsott1App::*p2)();           
    p2=&CTestvcsott1App::testcontrolapp; 
            (*p2).testcontrolapp();     
      AfxMessageBox("OnDoubleclickedButton3 ok");}
      

  5.   

    多谢普东东pdd123! 按照你的方法已经成功!