Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Horn

MFC: Data storage/transfer

This topic is 5959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m attempting to create tools for a video game that is currently in production. I''ve been struggling to get this one part working for a while but I haven''t had any luck with it. On a dialog box, there is a pull down menu and several edit boxes. What I''m trying to do is that when the selection in the pull down menu is changed, store the data in the edit boxes in the old selection and then load the data from the new selection into the edit boxes. What it does is whenever I change the selection, all the edit boxes are simply cleared. I''ve fooled around with different combinations of UpdateData(TRUE and FALSE) but I can''t get it to work. m_selected is initilized to zero when the dialog is first created. ships is an array of 10 objects which is defined as a public variable in the dialog box''s class.
  
ships[m_selected].cargospace = m_cargospace;
ships[m_selected].crewspace = m_crewspace;
ships[m_selected].is_active = m_active;
ships[m_selected].flagship = m_flagship;
ships[m_selected].maxspace = m_maxspace;
ships[m_selected].name = m_shipname;
UpdateData(0);

m_selected = m_alliance.GetCurSel();

m_cargospace = ships[m_selected].cargospace;
m_crewspace = ships[m_selected].crewspace;
m_active = ships[m_selected].is_active;
m_flagship = ships[m_selected].flagship;
m_maxspace = ships[m_selected].maxspace;
m_shipname = ships[m_selected].name;

UpdateData(FALSE);
Invalidate();
  

Share this post


Link to post
Share on other sites
Advertisement
UpdataData(TRUE) will transfer the data from the controls of your dialog to the variables (use this to get changes the user made).
UpdataData(FALSE) will transfer the data from your variables to the controls (use this to update the controls with new values you supply).


  
// get data from controls -> variables

UpdateData(TRUE);

// store data in previous selected combo box slot

ships[m_selected].cargospace = m_cargospace;
ships[m_selected].crewspace = m_crewspace;
ships[m_selected].is_active = m_active;
ships[m_selected].flagship = m_flagship;
ships[m_selected].maxspace = m_maxspace;
ships[m_selected].name = m_shipname;

// get new selection from ComboBox

m_selected = m_alliance.GetCurSel();

// update variables with corresponding data

m_cargospace = ships[m_selected].cargospace;
m_crewspace = ships[m_selected].crewspace;
m_active = ships[m_selected].is_active;
m_flagship = ships[m_selected].flagship;
m_maxspace = ships[m_selected].maxspace;
m_shipname = ships[m_selected].name;

// push data from variables -> controls

UpdateData(FALSE);

// calling invalidate will redraw the whole dialog which

// is not needed if you only want to update your controls

// Invalidate();



Note: calling GetCurSel() on the ComboBox will always get the current selection. This is not affected by UpdateData(), unless you have an int variable attached to it.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!