리지스트리 이용하기
Using registry key
InitInstance()에
...
SetRegistryKey(_T("My App"));
...
라고 하면
HKEY_CURRENT_USER\Software\My App\(Project name)
아래에 저장된다.
BOOL WriteProfileInt(<?XML:NAMESPACE PREFIX = O />
LPCTSTR lpszSection,
LPCTSTR lpszEntry,
int nValue
);
BOOL WriteProfileString(
LPCTSTR lpszSection,
LPCTSTR lpszEntry,
LPCTSTR lpszValue
);
UINT GetProfileInt(
LPCTSTR lpszSection,
LPCTSTR lpszEntry,
int nDefault
);
CString GetProfileString(
LPCTSTR lpszSection,
LPCTSTR lpszEntry,
LPCTSTR lpszDefault = NULL
);
예를 들어
WriteProfileInt(“Settings”, “Time”, 10);
과 같이 할 경우
HKEY_CURRENT_USER\Software\My App\(Project name)\Settings
에 Time 이라는 항목으로 10 의 값이 저장된다. 모든 함수들은 CWinApp 클래스 멤버함수이므로
이 함수들을 사용할 때는
AfxGetApp()->WriteProfileInt(“Settings”, “Time”, 10);
과 같은 형태로 사용해야 한다.
리지스트리에서 데이터를 읽으려고 하는 경우
int time = GetProfileInt(“Settings”, “Time”, 0);
와 같이 하면 제대로 된 디렉토리에서 값을 읽어온다. 만약 값을 찾지 못했을 경우에는 마지막 인자가
기본값으로 설정된다.
[출처] MFC Using registry key (리지스트리 사용)|작성자 xtElite
이것은 Demo only로 OnDraw에 이런 짓은 하지 말기를...
AfxGetApp()->WriteProfileXXX()
AfxGetApp()->GetProfileXXX()
함수 참조
void CGdiplusDemoView::OnDraw(CDC* pDC)
{
Graphics g(pDC->m_hDC);
CString sTest;
AfxGetApp()->WriteProfileString(L"Section", L"Entry", L"Value");
// Create font
FontFamily fontFamily(L"Arial");
Font font(&fontFamily, 24, FontStyleBold, UnitPixel);
// Create brush
SolidBrush brush(Color(255, 0, 0, 255));
// Center alignment
StringFormat stringFormat;
stringFormat.SetAlignment(StringAlignmentCenter);
stringFormat.SetLineAlignment(StringAlignmentCenter);
sTest = AfxGetApp()->GetProfileString(L"Section", L"Entry");
PointF pointF(100, 100);
g.DrawString(sTest, sTest.GetLength(), &font, pointF, &stringFormat, &brush);
}
'프로그래밍 > VC++ 개발 코딩' 카테고리의 다른 글
fopen 사용방법 (0) | 2014.01.17 |
---|---|
VS6.0 STL 사용 주의사항 (0) | 2014.01.17 |
Window Message 함수 설명 - MSDN (0) | 2014.01.17 |
TerminateThread 사용하는 경우 메모리 증가 처리방안 (0) | 2014.01.17 |
[본문스크랩] 쓰레드의 동기화 (0) | 2014.01.17 |