请问高手:如何在窗口函数中,调用应用数程序中的一般函? 请问高手:如何在窗口函数中,调用应用数程序中的一般函?在就是我对窗口函数的理解还很模糊,窗口函数同应用程序之间是进程调用的关系吗?是不是需要宣布远程指针指向应用程序对象,以及应用程序函数?实例的句柄是不是指向对象的指针? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void CTestvcsott1View::OnDoubleclickedButton3() { // TODO: Add your control notification handler code here void (CTestvcsott1App::*p2)(); p2=&CTestvcsott1App::testcontrolapp; AfxMessageBox("OnDoubleclickedButton3 ok");} 你说的窗口函数是类成员函数?你在view类的成员函数里调用这个 CTestvcsott1App::testcontrolapp ?这个testcontrolapp是静态的成员函数吗?是public的吗?不是静态的就要用CTestvcsott1App类的对象或指针去调用,不是public的无法访问 是不是有一个对象CTestvcsott1App theApp;?如果是,那你可以直接调用的说。如果testcontrolapp是其公有的成员函数,你可以直接这样调用:theApp.testcontrolapp();不过你要在调用之前让编译器知道存在一个名为theApp的对象,所以,你最好在头文件中加上:extern CTestvcsott1App theApp; 应用类是这样的: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// Attributespublic: CTestvcsott1Doc* GetDocument();// Operationspublic:// 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// Implementationpublic: virtual ~CTestvcsott1View();#ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const;#endifprotected:// Generated message map functionsprotected: //{{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");} 多谢普东东pdd123! 按照你的方法已经成功! 图像xyz空间转Lab空间,公式? 关于在windows平台下开发网游服务器 主对话框中添加子对话框 关于完成端口有多个客户端连接时所产生的问题??? 多个对话框的问题 如何让VC程序支持UNICODE编码? VC++中如何使用api函数GetVersionEx? 关于xml保存问题,100分相送~ 数据库的访问 有偿合作曲线字体生成算法 数据库的连接后 登陆的安全验证问题 二维图片进行三维重建的问题
{
// TODO: Add your control notification handler code here
void (CTestvcsott1App::*p2)();
p2=&CTestvcsott1App::testcontrolapp;
AfxMessageBox("OnDoubleclickedButton3 ok");}
你在view类的成员函数里调用这个 CTestvcsott1App::testcontrolapp ?这个testcontrolapp是静态的成员函数吗?是public的吗?不是静态的就要用CTestvcsott1App类的对象或指针去调用,不是public的无法访问
如果是,那你可以直接调用的说。如果testcontrolapp是其公有的成员函数,你可以直接这样调用:
theApp.testcontrolapp();
不过你要在调用之前让编译器知道存在一个名为theApp的对象,所以,你最好在头文件中加上:
extern CTestvcsott1App theApp;
{
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");}