資源簡(jiǎn)介
在子窗口中調(diào)用父窗口的成員函數(shù)的方法
1、用FindWindow("類名(可以是派生類)","窗口標(biāo)題")或GetParent(),二者均能返回父窗口句柄,并能直接使用其成員函數(shù)。但是此法只能調(diào)用CWnd類里的成員函數(shù),而不能調(diào)用自己創(chuàng)建的派生類中的函數(shù)。
2、在子窗口的初始化函數(shù)里加上父窗口的指針 ,然后在子窗口的類中使用全局變量保存父窗口的指針。如:
父窗口類為CMyDlg(父類為CDialog),子窗口類為CMySon(父類為CDialog),則在CMyDlg::OnInitDialog()中初始化子窗口對(duì)象m_myson=new CMySon(this);(m_myson為在父窗口中聲明的成員),然后在MySon.cpp中的開始處聲明全局變量CMyDlg *parent;(在MySon.h中要加入MyDlg.h頭文件),最后在CMySon的構(gòu)造函數(shù)中定義parent=(CMyDlg*)pParent;
好了,現(xiàn)在你可以在子窗口中隨時(shí)調(diào)用父窗口函數(shù)了!
代碼片段和文件信息
//?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;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????143464??2009-05-30?15:08??IndepentList\Debug\IndepentList.exe
?????文件?????312040??2009-05-30?15:08??IndepentList\Debug\IndepentList.ilk
?????文件??????15681??2009-05-30?14:19??IndepentList\Debug\IndepentList.obj
?????文件????5502076??2009-05-30?14:18??IndepentList\Debug\IndepentList.pch
?????文件?????541696??2009-05-30?15:08??IndepentList\Debug\IndepentList.pdb
?????文件???????2696??2009-05-30?14:43??IndepentList\Debug\IndepentList.res
?????文件??????28933??2009-05-30?14:45??IndepentList\Debug\IndepentListDlg.obj
?????文件??????18070??2009-05-30?15:08??IndepentList\Debug\MyList.obj
?????文件?????106002??2009-05-30?14:18??IndepentList\Debug\StdAfx.obj
?????文件?????238592??2009-05-30?15:08??IndepentList\Debug\vc60.idb
?????文件?????372736??2009-05-30?15:08??IndepentList\Debug\vc60.pdb
?????文件???????6649??2009-05-30?14:18??IndepentList\Debug\wmpcdrom.obj
?????文件???????5743??2009-05-30?14:18??IndepentList\Debug\wmpcdromcollection.obj
?????文件??????13421??2009-05-30?14:18??IndepentList\Debug\wmpclosedcaption.obj
?????文件??????15291??2009-05-30?14:18??IndepentList\Debug\wmpcontrols.obj
?????文件???????7490??2009-05-30?14:18??IndepentList\Debug\wmpdvd.obj
?????文件???????5992??2009-05-30?14:18??IndepentList\Debug\wmperror.obj
?????文件???????8386??2009-05-30?14:18??IndepentList\Debug\wmperroritem.obj
?????文件??????23875??2009-05-30?14:18??IndepentList\Debug\wmpmedia.obj
?????文件??????15046??2009-05-30?14:18??IndepentList\Debug\wmpmediacollection.obj
?????文件??????25746??2009-05-30?14:18??IndepentList\Debug\wmpnetwork.obj
?????文件??????54658??2009-05-30?14:18??IndepentList\Debug\wmppla
?????文件???????4971??2009-05-30?14:18??IndepentList\Debug\wmppla
?????文件??????17304??2009-05-30?14:18??IndepentList\Debug\wmpplaylist.obj
?????文件???????4748??2009-05-30?14:18??IndepentList\Debug\wmpplaylistarray.obj
?????文件??????10013??2009-05-30?14:18??IndepentList\Debug\wmpplaylistcollection.obj
?????文件??????20729??2009-05-30?14:18??IndepentList\Debug\wmpsettings.obj
?????文件???????5342??2009-05-30?14:18??IndepentList\Debug\wmpstringcollection.obj
?????文件??????35688??2009-05-30?14:43??IndepentList\IndepentList.aps
?????文件???????1216??2009-05-30?15:08??IndepentList\IndepentList.clw
............此處省略62個(gè)文件信息
評(píng)論
共有 條評(píng)論