c++ - How do I can call each other function in the different view in MFC? -
i have make view in dialog in mfc. , want call function dialog view. how can call each other function in different view?
here code have attached link
void cmfc_test5dlg::ondropfiles(hdrop hdropinfo) { int nfiles; char szpathname[max_path]; cstring strfilename; nfiles = ::dragqueryfile( hdropinfo, 0xffffffff, szpathname, max_path ); { ::dragqueryfile(hdropinfo, 0, szpathname, max_path); } ::dragfinish(hdropinfo); cdialog::ondropfiles(hdropinfo); dodisplayimage(); <---here call function. cdialogex::ondropfiles(hdropinfo); }
and here function
void ctestview::dodisplayimage() { cdc *pdc = getdc(); if (pdc != null && m_image.isvalid() ) { crect rectclient; getclientrect(rectclient); pdc->fillsolidrect(rectclient,pdc->getbkcolor()); // set windows bitmap header bitmapinfoheader bmi; bmi.bisize = sizeof(bitmapinfoheader); // size of structure bmi.biwidth = m_image.columns(); // bitmaps width in pixels bmi.biheight = (-1)*m_image.rows(); // bitmaps height n pixels bmi.biplanes = 1; // number of planes in image bmi.bibitcount = 32; // number of bits per pixel bmi.bicompression = bi_rgb; // type of ...
and dodisplayimage function called here
void ctestview::ondraw(cdc* pdc) { cdocument* pdoc = getdocument(); // todo: add draw code here dodisplayimage(); }
but, know, problem can't call dodisplayimage() in void cmfc_test5dlg::ondropfiles(hdrop hdropinfo) function want szpathname of ondropfiles function in dodisplayimage.
what should solving problems?
update 1
there error when make following.
1>d:\work\mfc_test5\mfc_test5\testview.h(29): error c2143: syntax error : missing ';' before '*' 1>d:\work\mfc_test5\mfc_test5\testview.h(29): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1>d:\work\mfc_test5\mfc_test5\testview.h(29): error c4430: missing type specifier - int assumed. note: c++ not support default-int 1> 1>build failed.
in testview.h,
#pragma once // ctestview view class ctestview : public cscrollview { declare_dyncreate(ctestview) protected: ctestview(); // protected constructor used dynamic creation virtual ~ctestview(); public: #ifdef _debug virtual void assertvalid() const; #ifndef _win32_wce virtual void dump(cdumpcontext& dc) const; #endif #endif protected: virtual void ondraw(cdc* pdc); // overridden draw view virtual void oninitialupdate(); // first time after construct declare_message_map() public: ctestview* ptestview; <---- right? };
here code have attached link
update2
i have done following.
// mfc_test5dlg.h : header file // #pragma once #include "afxcmn.h" // cmfc_test5dlg dialog class ctestview;//adding class cmfc_test5dlg : public cdialogex { // construction public: cmfc_test5dlg(cwnd* pparent = null); // standard constructor ctestview* ptestview;//adding // dialog data enum { idd = idd_mfc_test5_dialog }; protected: virtual void dodataexchange(cdataexchange* pdx); // ddx/ddv support cmfc_test5dlg::cmfc_test5dlg(cwnd* pparent /*=null*/) : cdialogex(cmfc_test5dlg::idd, pparent) , m_cstring(_t("")) { m_hicon = afxgetapp()->loadicon(idr_mainframe); ptestview = null; //adding }
but can't understand @ part how implement in case.
you have set ptestview each time dialog created. example: void ctestview::foo() { cmfc_test5dlg dlg(...); dlg.ptestview = this; dlg.domodal(); }
in mfc's document/view architecture not call view's method outside.
the way view draw through document updating content , invoking updateallviews(), possibly hint (for optimization).
Comments
Post a Comment