MFC: Update Variables from Control in Dialog

Reference from

http://www.dreamincode.net/forums/topic/57443-mfc-length-converter-tutorial/


The following solution is suitable for users of VS2008

  1. Open Visual Studio 2008
  2. File->New->Project
  3. Choose MFC application
  4. Give a name to your project and click OK
  5. A dialog box pops up and click "Next" button
  6. Choose "Dialog Based", "Use MFC in a shared DLL" and "MFC standard" radio buttons, and then click Finish
  7. An empty dialog box shows in the IDE so you need to add some controls on this box
  8. In the Toolbox on the left, drag Edit Control on the dialog box, drag a Button on the box too
  9. Right click the dialog box and click Add Variable…
  10. A dialog, namely Add Member Variable Wizard – XXXX, pops up
  11. Make the checkbox next to Control variable having a tick
  12. Select the edit control you just added in Control ID
  13. Choose Variable in Category
  14. In the field of Variable name, input "var_from_edit_control"
  15. Select int in Variable type
  16. Press Finish
  17. Double-click the button, you created in the dialog box before
  18. In the Code View, insert the follow code
    UpdateData(true);
    var_from_edit_control += var_from_edit_control;
    UpdateData(false);
  19. Compile the project using Debug->Start Debugging
  20. The application is compiled and executes.
  21. Click on the button. The value in the textbox will increase by 1 each time.
本篇發表於 C++ 並標籤為 。將永久鏈結加入書籤。

MFC: Update Variables from Control in Dialog 有 1 則回應

  1. 红海滩 說道:

    每天来顶贴已经成了我的习惯,多谢经常的好文,加油!

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *