mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx

上传人:b****5 文档编号:15168151 上传时间:2023-07-02 格式:DOCX 页数:7 大小:16.61KB
下载 相关 举报
mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx_第1页
第1页 / 共7页
mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx_第2页
第2页 / 共7页
mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx_第3页
第3页 / 共7页
mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx_第4页
第4页 / 共7页
mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx_第5页
第5页 / 共7页
mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx_第6页
第6页 / 共7页
mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx_第7页
第7页 / 共7页
亲,该文档总共7页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx

《mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx》由会员分享,可在线阅读,更多相关《mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx(7页珍藏版)》请在冰点文库上搜索。

mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHow d.docx

mfc如何在文档cxxx类或框架cmainframe类中获得视类cmyviewHowd

mfc如何在文档(cxxxdoc)类或框架(cmainframe)类中获得视类(cmyview(HowdoesMFCgetavisualclassinthedocument(cxxxdoc)classorCMainFrameclass(cmyview))

HowdoesMFCgetavisualclassinthedocument(CXXXDoc)classorCMainFrameclass(CMyView.txt)

HowdoesMFCgettheviewclass(CMyView)pointerinthedocument(CXXXDoc)classortheframework(CMainFrame)class?

Inthedocumentclass,justusethe(multidocument,singledocument,alittlesimpler)

POSITION(pos=this->GetFirstViewPosition);//towriteinthedocumentclass,toreplacethisdocumentpointercanbeinotherclasses

While(POS)

{

CView*pView=this->GetNextView(POS);

}

Intheframeworkclass,justselectthedocumentobject,andthenusethecodeabove

Here'sanaspectofgettinganotherobjectfromanobject(excerptfromMFC)

Themethodofobtaininganotherobjectfromanobject

Thememberfunctionsusedbytheobjecttobeobtainedbythisobject

CDocumentobjectviewlistGetFirstViewPosition,GetNextView

DocumenttemplateGetDocTemplate

CViewobjectdocumentobjectGetDocument

BorderwindowGetParentFrame

CMDIChildWndor

CFrameWndobjectactivityviewGetActiveView

ActivevisualdocumentGetActiveDocument

CMDIFrameWndobject,activedocument,borderwindow,MDIGetActive

UseGetActiveView()intheframeworkclass;

Inthedocumentclass(CMainFrame*)(AfxGetApp()->m_pMainWnd))->GetActiveView();

HowdoesMFCgetthepointertotheViewclassunderCMainFrame?

UsingtheGetActiveView()function

HowdoordinaryclassesinMFCgetpointerstotheviewclass?

HowdoIgetpointerstotheviewclassintheclass(Generic)?

I'vetriedthat:

CMainFrame*p=(CMainFrame*)AfxGetMainWnd();

CView,*pv=p->GetActiveView();

Accordingtoyourusage,that'sallright!

IsthistheViewthathasn'tbeencreatedyet,soPVisempty?

.

CMainFrame*m_pfm=(CMainFrame*)AfxGetApp()->m_pMainWnd;

...*m_pView=(*)m_pfm->GetActiveView();

Onelessword:

AfxGetApp()

CMainFrame*p=(CMainFrame*)AfxGetApp()->m_pMainWnd;

CView*pv=(CView*)p->GetActiveView();

Upstairsinchargeofbuildinganalysis,asequenceoffunctioncalls,notwhatisPreCreateWindoworCXXXApp,theconstructoroftheCXXXFrameInitInstance,themainwindowtemplatedidnotfinishforthemanipulationoftheCView.

Asdfasdf

HowdoIreturnapointertoaclassinMFC,suchasCWIN,view,andsoon!

IntheCViewclass,callthis->GetDocument()togetdoc.

IntheCDocumentclass,callGetFirstViewPosition()andGetNextView()togetalltheview.

Inotherclasses,onemethodistopassthepointerinforthecalltouse.

Also,yougetCWinAppwithAfxGetApp(),thenGetFirstDocTemplatePosition()andGetNextDocTemplate()togetthedoctemplate,andthencallGetFirstDocPosition()andGetNextDoc()togetthedoc.

HowdoIgetthepointeroftheViewclass(this)orthepointerofthewholedialogboxintheOnDrawfunctionorthe***Dlgfunction?

Inasingledocument,youcanusethefollowingmethods:

Thefilewhereyouwanttogetthepointernowcontainstwofilesatthestart:

Viewofthemainframeclassheaderfile,thatis,#include"MainFrm.h""

Viewclassheaderfile,thatis,#include"XXView.h""

Thenaddthefollowingstatementatthepointwhereyouwanttoaccessthem_pSet

CMainFrame*frm=(CMainFrame*)AfxGetApp()->m_pMainWnd;

CXXView*pView=(CXXView*)frm->GetActiveView();

PView,thatis,theViewclasspointer

Butisn'titeasierforyoutousethis?

InthesingledocumentofMFC,theviewwindowhandleproducedbyCtestviewisobtainedfromthetreeviewclassofaview

Getsthewindowhandleoftheviewinthesingledocumentframework.Askforapieceofcode.Checkonline,didnotgetitout.Whichbrotherhastimetowriteaparagraph?

.

You'renotclear.Therearemanywaystocarryitout.

YoucangettheviewpointerthroughtheglobalobjecttheApp,andthen

Viewpointer->GetSafeHwnd();getsthehandle.

Youcanalsosendcustommessagestosendthehandletothespecifiedwindowclass.

YoucanalsodefineaCviewpointerinyourstdafx.h,whichpointstotheViewclassduringtheinitializationprocess,andisusedinyourtreeview.

Youcanalsoreceiveahandleforthetreeviewclassdefinitionmethodbyitself,whencalled.

Notethatyoucanhandlethecreationsequence,orelseyouwillmakeanassertionerrorunderdebug.

Themethodisreallyalot.

Ifyoudonotusethedocument/viewstructure,thesingledocumentiscreatedinthebuildframewindow.Thereisavariablecalledm_wndView.Thisisthehandle.He'saCWndderivative.

Ifyouusethedocument/viewstructure,directGetActiveViewisfine.

Thereisonemorecase,ifyouusethesplitwindow.......

Whichfunctionhasbeenforgotten?

.Get***Paneseems..Checkit.

HowistheinitialtitleoftheviewwindowproducedbytheMFCsingledocumentCtestview?

Youcanmodifythecharacterfileintheresourcefile,specificallyhowtomodifytheInternetsearch,

AnothermethodistojoinreturninthePreCreateWindowfunctionoftheviewclass

M_strTitle=singledocumentheader";

Youstartedanotherthread,CMyApp.HowdoyouaccessmyViewclassinCMyApp?

IfIweretoregenerateaWinAppclassandcallAfxBeginThread((RUNTIME_CLASS)CMyApp)tostartanotherthread,thenhowdoIaccessmyViewclassinCMyApp?

Iaskedthequestioninthemorning,butnoonegavemetheanswer.Amastercanenlightenah

1.YoucanpassintheclassofthisViewasaparameter,whichistheeasiestsolution

2.

Youcangetitinthefollowingway

CWinApp*pA=AfxGetApp();

POSITION,pos=pA->GetFirstDocTemplatePosition();

CDocTemplate*pDT=pA->GetNextDocTemplate(POS);

Pos=pDT->GetFirstDocPosition();

CDocument*pD=pDT->GetNextDoc(POS);

Pos=pD->GetFirstViewPosition();

CView*pV=pD->GetNextView(POS);

Ofcourse,theprincipleisthatifyouhavemultipleView,orhaveDoc,orevenmultipleDocTemplate,youcanadjustitappropriately

Thesourcecode,Itried,andshouldbenoproblem

HowdoestheMFCsingledocumentgetahandletothewindowoftheViewview(thewindowproducedbytheCmyViewclassinstance)?

Inanotherviewclass

GetthroughtheAppclass

Headerfiledefinition:

CmyView,*GetmyView();

Realization:

CmyView*CmyApp:

:

GetmyView()

{

If(m_pDocManager)

{

POSITIONpos1=m_pDocManager->GetFirstDocTemplatePosition();

While(pos1)

{

CDocTemplate*pDocTemplate=m_pDocManager->GetNextDocTemplate(pos1);

If(pDocTemplate)

{

POSITIONpos2=pDocTemplate->GetFirstDocPosition();

While(pos2)

{

CDocument*pDoc=pDocTemplate->GetNextDoc(pos2);

If(pDoc)

{

POSITIONpos3=pDoc->GetFirstViewPosition();

While(pos3)

{

CView*pView=pDoc->GetNextView(pos3);

If(pView)

{

If(pView->IsKindOf(RUNTIME_CLASS(CmyView))

Return(CmyView*)pView;

}

}

}

}

}

}

}

ReturnNULL;

}

Addapoint,ifyouareasplitviewgeneratedbystaticsegmentation,canmakefulluseoftheGetPanefunction,suchasCSplitterWnd,CmyViewtogetthewindowhandleinCmylView(assumingCmyViewinsegmentationof0rowsand0columns):

CSplitterWnd*ps=(CSplitterWnd*)GetParent();

CmyView*pView=(CmyView*)(ps->GetPane(0,0));

PView->m_hWndgetsthehandletotheviewform

Simple:

becauseyouhavemorethanoneclassofview,onlythehandleofthewindowismeaningfulonlywhenyougettheViewview(thewindowproducedbytheCmyViewclassinstance)whenyourviewclassisactive!

Aslongasafunctioncanbesolved.

CView*GetActiveView()const;

GetActiveView()getsthecurrentactiveviewclasswindowhandle

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2