MFC: Update Variables from Control in Dialog

Reference from

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
    var_from_edit_control += var_from_edit_control;
  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.

在〈MFC: Update Variables from Control in Dialog〉中有 1 則留言


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