dialog box to get the view class pointer

Source: Internet
Author: User

Workaround: Open dialog in the menu of the view class and return the value of dialog to the view class

Solution:

Set dialog class to Judge,view class as Cvmfcview

1.judge.h defines a c****view* class variable: ccvmfcview* pmain;
2. Add function Onshowdialog (ccvmfcview* pview) in the Judge class instead of DoModal

void Cjudge::onshowdialog (ccvmfcview* pview)
{
	pmain=pview;
	DoModal ();
}
This will replace the Pmain with PView. So how do you pass the Cvmfcview object pointer to PView? See the next step.

The menu response function in 3.CVMFCView is written

void Ccvmfcview::onselectresult ()
{
	Cjudge dlg;
	Dlg. Onshowdialog (this);
}
Done.
The function of the view class in the dialog box Judge.cpp can be called directly using Pmain.

====================================================================

There's also a way to get the view class pointer, but sometimes it's not work, because the view class pointer might point to a null value if the fetch method is wrong

cmainframe*   pframe= (cmainframe*) AfxGetMainWnd ();   
    clistctrlview* PView = (clistctrlview*) Pframe->getactiveview ();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.