开发者

Pop up dialog from menu of main parent dialog(MFC)?

开发者 https://www.devze.com 2023-02-20 15:35 出处:网络
@oaimac, I am not able to read thevariable from dialog CSettings I am not sure what is is wrong in this code

@oaimac,

I am not able to read the variable from dialog CSettings

I am not sure what is is wrong in this code

void CCStatsDlg::OnClickSettings()
 {   

 CSettings dlg;

if (dlg.DoModal () == IDOK)

 //Problem is here I am not getting the expected value

   {
         int m_SampleNumber = dlg.getvalue ();
   }
}

This i am doing in CCStatsDlg class because i need to process CSettings dialog values here. m_SampleNumber is initialized to 1024 in the CCStatsDlg class constructor.below is the getvalue() in CSettings class

CSettings::CSettings(CWnd* pParent /*=NULL*/)
: CDialog(CSettings::IDD, pParent)

{

  SampleNumber =2048;

}

CSettings::~CSettings()

{
}

void CSettings::DoDataExchange(CDataExchange* pDX)

{
CDialog::DoDataExchange开发者_开发技巧(pDX);

DDX_Text(pDX, IDC_EDIT_SAMPLE1, SampleNumber);

}

int CSettings::getvalue()

  {

   return SampleNumber;

  } 

Even if i return 2048 as SampleNumber, m_SampleNumber in CCStatsDlg is not getting which is always 1024 which was initialized in constructor

So please help me out on this. Thanks


to do what you want :
x associate a function to the OnClick event of your Settings menu item (using the tabs of its property windows for example) -> this will generate automatically the function inside the MainFrm.h and .cpp files
x instantiate a member structure, or variables you want to get from your hardware inside your CCStatsDlg class .h and .cpp
x fill your variables inside the OnOK () function of your CCStatsDlg class
x add one or more functions inside your CCStatsDlg .h and .cpp files like :

int GetValue1()

x call your dialogbox with :

    CCStatsDlg dlg ();  
    if dlg.DoModal () == IDOK
    {
       // Here you can get your variables values once OK is clicked inside your dialog box
       int value1 = dlg.GetValue1 ()
    }

Hope this will help


so you need create new CDialog derived window and then show it.

Put this code to on click event:

CMySettingDialog dlg;
dlg.DoModal();

Some sample you can find here and here

0

精彩评论

暂无评论...
验证码 换一张
取 消