리지스트리 이용하기
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);

와 같이 하면 제대로 된 디렉토리에서 값을 읽어온다. 만약 값을 찾지 못했을 경우에는 마지막 인자가
기본값으로 설정된다.

 


이것은 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);
}

+ Recent posts