私はこのMFCダイアログプログラムを使用しています。ダイアログが書き込まれましたが、ダイアログからダイアログにデータを渡すのが難しくなりました。 CWinAppから派生したクラスで_dlgDataHandlerを設定し、この型へのポインタの "新しい"ステートメントを作成しました。MFC ::構造体を使用してデータを渡す
//.......SRK.hファイル
class CSRK_App : public CWinApp
{
public:
CFSB_App();
// added the following data structure for data passing withing the program
typedef struct _dlgDataHandler {
char RepetitionRadio[24];
// another member
// yet another member and so on as necessary
} *dlgDataHandlerPtr;
// extern dlgDataHandlerPtr dlgDataHandler;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSRK_App)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CSRK_App)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// ....... SRK.cpp 2/3程度このブロックで作成した新しいのdataHandlerへのポインタダイアログの.cppファイルでダウン
// CSRK_App initialization
BOOL CSRK_App::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.
//SetRegistryKey(_T("Local AppWizard-Generated Aplications"));
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
//CSRK_Dlg dlg;
CDialogMain dlg("SRK - Beta"); // added 12/27 **
m_pMainWnd = &dlg;
//const char* m_pszHelpFilePath = NULL;
//free((void*)m_pszHelpFilePath);
//m_pszHelpFilePath=_tcsdup(_T("c:\SRKHelp.rtf"));
// the following line added to allocate memory for the structure
dlgDataHandlerPtr dlgDataHandler = new _dlgDataHandler;
dlg.SetWizardMode(); // added 12/27 **
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;
}
方法は、5つがありますが、私はAFX変数「M_」からデータを取得し、これのdataHandler構造(またはそれのような別の1)にロードできるようにする必要があります他のダイアログやプログラムの部分、特にすべてのダイアログデータ収集が完了したときの実際のコードで使用できるようにします。誰かがAfxGetApp()を使って現在のインスタンスを処理できると言ったが、彼らが何を話しているのか分からない。そして、はい、私は多くのフォーラムでそれを読んだことがあります。私はさらにこれがおそらく最善の方法ではないことを認識しています。私はMFC/OOPをいつでも利用できるようにしようとしていますが、単純なデータを収集して渡す方法を理解すれば基本的なプロセスを手に入れようとしています。
私はさらに、AfxGetApp()を呼び出すことで、CSRK_Appのメンバーを手助けする方法がわかりません。それはCWinAppsのパブリックメンバーを継承しましたが、AfxGetapp()はCSRK_Appに何があるのかわかりません...できますか?
ありがとうございます。私はこれがそれを行うための貧しい方法だと思います。私は実際にあなたがそれを記述したのとまったく同じ別のクラスを自分のファイルに使用しようとしました。私の最大の問題は、クラスのインスタンス化のようなものをどこに置いて、常に稼働しているかを理解することでした。私は決してその上のハンドルを維持するように見えることができませんでした。 1つのダイアログから別のダイアログに移動したときのように、データクラスのスコープが失われてしまいました。そのクラスに戻ろうとすると、ゴミや何かが出てしまいました。だから私は疑わしい構造を試した。私にとって最も難しいことは、MFCですべてがどこにあるのかを知ることです –