Click here to Skip to main content
12,831,626 members (28,547 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 23 Feb 2004

Save and restore dialog controls' states

, 28 Feb 2004
Rate this:
Please Sign up or sign in to vote.
A simple but universal way to save and restore state of dialog controls

Sample image


In some (or most?) cases, when we are using dialog windows to communicate with the user, we need to save/restore state of checkboxes, edit controls, radio buttons, etc. There are several possibilities of how to do it. You can program functions newly for every dialog window or use "universal" solution. I created for myself one simple class that I am using in most cases with no changes. All that you will need to implement this function into your application is to add five lines of code to your dialog source file.

Using the code

First of all, if you want to use CDialogSettings class in your application, you must include these header files:

#include "stdafx.h"
#include "resource.h"
#include "dlgset.h"    <= CDialogSettings class

To restore dialog controls' states (text of edit controls, checked/unchecked state of checkboxes, etc.) we will need to add the following two lines of code to the dialog initialization routine. If you are creating a non-MFC application, insert CDialogSettings class here:

INT_PTR CALLBACK dialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  switch (uMsg) {
        CDialogSettings ds(hwndDlg);

If you are creating an MFC application, insert CDialogSettings class here:

BOOL CDlgSetExampleDlg::OnInitDialog()
  CDialogSettings ds(m_hWnd);


Code that will store dialog controls' state (CDialogSettings class uses registry) you can add into the IDOK handler (you need to save settings only if the user confirms dialog), or into the WM_DESTROY / OnDestroy routine. In the non-MFC application, it will look like this:

        CDialogSettings ds(hwndDlg);

and in the MFC application:

void CDlgSetExampleDlg::OnDestroy() 
  CDialogSettings ds(m_hWnd);


That's all. I hope, you find this class useful.

This demo project (and also article) was created using umdev - multi-compiler IDE.


  • 24. February 2004 - First release.
  • 1. March 2004 - Updated project.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Slovakia Slovakia
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow to make this project support unicode? Pin
kehehee216-Oct-14 18:41
memberkehehee216-Oct-14 18:41 
QuestionCasting error Pin
infinity25729-Mar-12 5:16
memberinfinity25729-Mar-12 5:16 
QuestionCompiler error [modified] Pin
Wild Thing26-Feb-07 7:54
memberWild Thing26-Feb-07 7:54 
AnswerRe: Compiler error Pin
Wild Thing26-Feb-07 8:12
memberWild Thing26-Feb-07 8:12 
GeneralGreat Code! Pin
multivitaminmehrfruchtsaft22-Sep-06 0:52
membermultivitaminmehrfruchtsaft22-Sep-06 0:52 
GeneralPerfect! Pin
fengyunxiao14-Jan-05 18:18
memberfengyunxiao14-Jan-05 18:18 
GeneralNice code Pin
Sumit Kapoor25-Oct-04 23:00
memberSumit Kapoor25-Oct-04 23:00 
GeneralProject doesn't work Pin
ritika.pande@wipro.com29-Feb-04 19:28
memberritika.pande@wipro.com29-Feb-04 19:28 
GeneralRe: Project doesn't work Pin
Anonymous29-Feb-04 20:23
sussAnonymous29-Feb-04 20:23 
GeneralRe: Project doesn't work Pin
ianw.moore2-May-04 22:31
memberianw.moore2-May-04 22:31 
GeneralRe: Project doesn't work Pin
Anonymous2-May-04 23:32
sussAnonymous2-May-04 23:32 
GeneralMFC: small correction Pin
allelimo28-Feb-04 3:56
memberallelimo28-Feb-04 3:56 
GeneralRe: MFC: small correction Pin
uemaker28-Feb-04 4:24
memberuemaker28-Feb-04 4:24 
GeneralComments on the code Pin
khb25-Feb-04 21:45
memberkhb25-Feb-04 21:45 
GeneralRe: Comments on the code Pin
uemaker25-Feb-04 21:55
memberuemaker25-Feb-04 21:55 
GeneralRe: Comments on the code Pin
uemaker25-Feb-04 23:45
memberuemaker25-Feb-04 23:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 29 Feb 2004
Article Copyright 2004 by uemaker
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid