Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MFC program, how to pass data between different dialog?

Tags:

c++

session

mfc

In web development, when we want to pass something between different pages, we might use the Session to save the data. But in MFC, what can we use to store these things?

Thanks!

like image 984
MemoryLeak Avatar asked Apr 28 '26 16:04

MemoryLeak


1 Answers

Typical MFC Applications will have a Document-View-Frame architecture. Data is stored in the Document object, and accessed globally. You can access it anywhere via AfxGetMainWnd().

AfxGetApp() will also get you a pointer to your main application, which is another good spot to store data if you're not using a Document View architecture. If there is a lot of data, you can construct a class to hold the data, then add an instance as a member variable to the CWinApp in your project.

Another option, which I don't recommend but I have seen, is to have the dialogs themselves as member variables in the CWinApp, and then each dialog can reference the other. Basically, the user clicks 'ok', but then the dialog disappears, but is not deleted. This means all the data they entered is still accessable via the dialog variable.

like image 101
Kieveli Avatar answered Apr 30 '26 07:04

Kieveli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!