在子窗口中调用父窗口的成员函数的
在子窗口中调用父窗口的成员函数的方法
1、用FindWindow("类名(可以是派生类)","窗口标题")或GetParent(),二者均能返回父窗口句柄,并能直接使用其成员函数。但是此法只能调用CWnd类里的成员函数,而不能调用自己创建的派生类中的函数。
2、在子窗口的初始化函数里加上父窗口的指针 ,然后在子窗口的类中使用全局变量保存父窗口的指针。如:
父窗口类为CMyDlg(父类为CDialog),子窗口类为CMySon(父类为CDialog),则在CMyDlg::OnInitDialog()中初始化子窗口对象m_myson=new CMySon(this);(m_myson为在父窗口中声明的成员),然后在MySon.cpp中的开始处声明全局变量CMyDlg *parent;(在MySon.h中要加入MyDlg.h头文件),最后在CMySon的构造函数中定义parent=(CMyDlg*)pParent;
好了,现在你可以在子窗口中随时调用父窗口函数了!
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 143464 2009-05-30 15:08 IndepentListDebugIndepentList.exe
文件 312040 2009-05-30 15:08 IndepentListDebugIndepentList.ilk
文件 15681 2009-05-30 14:19 IndepentListDebugIndepentList.obj
文件 5502076 2009-05-30 14:18 IndepentListDebugIndepentList.pch
文件 541696 2009-05-30 15:08 IndepentListDebugIndepentList.pdb
文件 2696 2009-05-30 14:43 IndepentListDebugIndepentList.res
文件 28933 2009-05-30 14:45 IndepentListDebugIndepentListDlg.obj
文件 18070 2009-05-30 15:08 IndepentListDebugMyList.obj
文件 106002 2009-05-30 14:18 IndepentListDebugStdAfx.obj
文件 238592 2009-05-30 15:08 IndepentListDebugvc60.idb
文件 372736 2009-05-30 15:08 IndepentListDebugvc60.pdb
文件 6649 2009-05-30 14:18 IndepentListDebugwmpcdrom.obj
文件 5743 2009-05-30 14:18 IndepentListDebugwmpcdromcollection.obj
文件 13421 2009-05-30 14:18 IndepentListDebugwmpclosedcaption.obj
文件 15291 2009-05-30 14:18 IndepentListDebugwmpcontrols.obj
文件 7490 2009-05-30 14:18 IndepentListDebugwmpdvd.obj
文件 5992 2009-05-30 14:18 IndepentListDebugwmperror.obj
文件 8386 2009-05-30 14:18 IndepentListDebugwmperroritem.obj
文件 23875 2009-05-30 14:18 IndepentListDebugwmpmedia.obj
文件 15046 2009-05-30 14:18 IndepentListDebugwmpmediacollection.obj
文件 25746 2009-05-30 14:18 IndepentListDebugwmpnetwork.obj
文件 54658 2009-05-30 14:18 IndepentListDebugwmpplayer4.obj
文件 4971 2009-05-30 14:18 IndepentListDebugwmpplayerapplication.obj
文件 17304 2009-05-30 14:18 IndepentListDebugwmpplaylist.obj
文件 4748 2009-05-30 14:18 IndepentListDebugwmpplaylistarray.obj
文件 10013 2009-05-30 14:18 IndepentListDebugwmpplaylistcollection.obj
文件 20729 2009-05-30 14:18 IndepentListDebugwmpsettings.obj
文件 5342 2009-05-30 14:18 IndepentListDebugwmpstringcollection.obj
文件 35688 2009-05-30 14:43 IndepentListIndepentList.aps
文件 1216 2009-05-30 15:08 IndepentListIndepentList.clw
............此处省略62个文件信息
// IndepentList.cpp : Defines the class behaviors for the application.
//
#include “stdafx.h“
#include “IndepentList.h“
#include “IndepentListDlg.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CIndepentListApp
BEGIN_MESSAGE_MAP(CIndepentListApp CWinApp)
//{{AFX_MSG_MAP(CIndepentListApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP CWinApp::onhelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIndepentListApp construction
CIndepentListApp::CIndepentListApp()
{
// TODO: add construction code here
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CIndepentListApp object
CIndepentListApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CIndepentListApp initialization
BOOL CIndepentListApp::InitInstance()
{
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
CIndepentListDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed return FALSE so that we exit the
// application rather than start the application‘s message pump.
return FALSE;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 143464 2009-05-30 15:08 IndepentListDebugIndepentList.exe
文件 312040 2009-05-30 15:08 IndepentListDebugIndepentList.ilk
文件 15681 2009-05-30 14:19 IndepentListDebugIndepentList.obj
文件 5502076 2009-05-30 14:18 IndepentListDebugIndepentList.pch
文件 541696 2009-05-30 15:08 IndepentListDebugIndepentList.pdb
文件 2696 2009-05-30 14:43 IndepentListDebugIndepentList.res
文件 28933 2009-05-30 14:45 IndepentListDebugIndepentListDlg.obj
文件 18070 2009-05-30 15:08 IndepentListDebugMyList.obj
文件 106002 2009-05-30 14:18 IndepentListDebugStdAfx.obj
文件 238592 2009-05-30 15:08 IndepentListDebugvc60.idb
文件 372736 2009-05-30 15:08 IndepentListDebugvc60.pdb
文件 6649 2009-05-30 14:18 IndepentListDebugwmpcdrom.obj
文件 5743 2009-05-30 14:18 IndepentListDebugwmpcdromcollection.obj
文件 13421 2009-05-30 14:18 IndepentListDebugwmpclosedcaption.obj
文件 15291 2009-05-30 14:18 IndepentListDebugwmpcontrols.obj
文件 7490 2009-05-30 14:18 IndepentListDebugwmpdvd.obj
文件 5992 2009-05-30 14:18 IndepentListDebugwmperror.obj
文件 8386 2009-05-30 14:18 IndepentListDebugwmperroritem.obj
文件 23875 2009-05-30 14:18 IndepentListDebugwmpmedia.obj
文件 15046 2009-05-30 14:18 IndepentListDebugwmpmediacollection.obj
文件 25746 2009-05-30 14:18 IndepentListDebugwmpnetwork.obj
文件 54658 2009-05-30 14:18 IndepentListDebugwmppla
文件 4971 2009-05-30 14:18 IndepentListDebugwmppla
文件 17304 2009-05-30 14:18 IndepentListDebugwmpplaylist.obj
文件 4748 2009-05-30 14:18 IndepentListDebugwmpplaylistarray.obj
文件 10013 2009-05-30 14:18 IndepentListDebugwmpplaylistcollection.obj
文件 20729 2009-05-30 14:18 IndepentListDebugwmpsettings.obj
文件 5342 2009-05-30 14:18 IndepentListDebugwmpstringcollection.obj
文件 35688 2009-05-30 14:43 IndepentListIndepentList.aps
文件 1216 2009-05-30 15:08 IndepentListIndepentList.clw
............此处省略62个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)