CWinApp
.SetRegistryKey()
.WriteProfileInt()
.WriteProfileString()
.GetProfileInt()
.GetProfileString()
다음은 HKEY_CURRENT_USER\Software\VCGuide\Draw\ 에 저장
BOOL CDrawApp::InitInstance()
{
...
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("VCGuide"));
...
}
class CDrawView : public CView
{
...
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDrawView)
public:
...
virtual void OnInitialUpdate();
protected:
...
//}}AFX_VIRTUAL
...
// Generated message map functions
protected:
//{{AFX_MSG(CDrawView)
...
afx_msg void OnSelectPenThickness(UINT nID);
afx_msg void OnUpdatePenThickness(CCmdUI* pCmdUI);
afx_msg void OnPenColor();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int m_nPenThickness;
COLORREF m_PenColor;
...
};
BEGIN_MESSAGE_MAP(CDrawView, CView)
//{{AFX_MSG_MAP(CDrawView)
...
ON_COMMAND_RANGE(ID_PEN_1PIXEL, ID_PEN_3PIXEL, OnSelectPenThickness)
ON_UPDATE_COMMAND_UI_RANGE(ID_PEN_1PIXEL, ID_PEN_3PIXEL, OnUpdatePenThickness)
ON_COMMAND(ID_PEN_COLOR, OnPenColor)
//}}AFX_MSG_MAP
// Standard printing commands
...
END_MESSAGE_MAP()
CDrawView::CDrawView()
{
// TODO: add construction code here
m_nPenThickness = 2;
m_PenColor = RGB(0, 0, 0);
...
}
...
void CDrawView::OnInitialUpdate()
{
...
// TODO: Add your specialized code here and/or call the base class
m_nPenThickness = AfxGetApp()->GetProfileInt("Pen", "Thickness", 2);
m_PenColor = (COLORREF)AfxGetApp()->GetProfileInt("Pen", "Color", 0);
...
}
void CDrawView::OnSelectPenThickness(UINT nID)
{
// TODO: Add your command handler code here
m_nPenThickness = nID - ID_PEN_1PIXEL + 1;
AfxGetApp()->WriteProfileInt("Pen", "Thickness", m_nPenThickness);
...
}
void CDrawView::OnUpdatePenThickness(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nPenThickness == (int)(pCmdUI->m_nID - ID_PEN_1PIXEL + 1));
}
void CDrawView::OnPenColor()
{
// TODO: Add your command handler code here
...
AfxGetApp()->WriteProfileInt("Pen", "Color", (int)m_PenColor);
...
}