Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can I use AfxGetMainWnd()? It didn't work when I write like this:
C++
//in CLinkListDlg class:   

CString strName=((CAddDlg*)AfxGetMainWnd()->GetActiveWindow())->m_str_name;
Posted
Updated 31-Jul-10 0:32am
v2
Comments
Sandeep Mewara 31-Jul-10 6:30am    
Keep patience. People will respond as they get time. No point in posting junks as an answer to it.
Richard MacCutchan 31-Jul-10 6:59am    
What didn't work? What result did you expect? Try explaining your problem in more detail and maybe someone can help you.
raju melveetilpurayil 31-Jul-10 13:54pm    
did you understand someone put a code like this?

Why don't you just create a static class and put the variable in there (don't forget to make it public static as well). Then you can get to it from anyplace in the program.
 
Share this answer
 
Comments
zhangyanlin 31-Jul-10 19:59pm    
it is a variable of a editbox,so I can not do that
If you have two dialogues that have to communicate why not do something radical like pass the address of the one data has to be fetched from to the constructor of the one that wants to consume the data?

Then you don't have to mess about calling global functions, casting (you might like to use static_cast<> if you're hellbent on casting) and the code will work if you ever need to change the dialogue that's the main application window.

Once you've got that working the next thing to consider is whether the consuming dialogue actually needs to know everything about the producing dialogue. If it doesn't you can introduce another interface between the two dialogues that just supplies the data you need. This is really cool as it improves your ability to test your code by just giving the consuming dialogue the minimum it needs to do it's job.

Cheers,

Ash
 
Share this answer
 
If the application is not supposed to be multithreaded and fairly simple, using good old global static variables will get you by this.

For data exchange, use the relevant event handlers.

Since you haven't posted anything but just a line of code, out of context, I assume that what you need is simple.
 
Share this answer
 
You may have a look at the following oldie-goldie article: "Dialogs Communication"[^].
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900