共用方式為


CWinApp::WriteProfileInt

呼叫此成員函式指定的值寫入至應用程式的註冊或 .INI 檔的指定區段。

BOOL WriteProfileInt(
   LPCTSTR lpszSection,
   LPCTSTR lpszEntry,
   int nValue 
);

參數

  • lpszSection
    為指定包含項目的這個部分的 NULL 結尾字串的點。 如果區段不存在,則會建立它。 本節中的名稱是大小寫無關,字串可以是大寫和小寫字母的任何組合。

  • lpszEntry
    out 包含輸入要寫入值的 NULL 結尾字串的點。 如果項目不存在於指定的部分,則會建立它。

  • nValue
    包含要寫入的值。

傳回值

如果不是零,則成功,則為 0。

範例

這個範例會使用 CWinApp* pApp = AfxGetApp(); 取得說明 WriteProfileStringWriteProfileIntGetProfileStringGetProfileInt 可以從任何函式使用在 MFC 應用程式的 CWinApp 方法的類別。

CWinApp* pApp = AfxGetApp();

CString strSection       = _T("My Section");
CString strStringItem    = _T("My String Item");
CString strIntItem       = _T("My Int Item");

pApp->WriteProfileString(strSection, strStringItem, _T("test"));

CString strValue;
strValue = pApp->GetProfileString(strSection, strStringItem);
ASSERT(strValue == _T("test"));

pApp->WriteProfileInt(strSection, strIntItem, 1234);

int nValue;
nValue = pApp->GetProfileInt(strSection, strIntItem, 0);
ASSERT(nValue == 1234);

如需其他範例,請參閱 CWinApp::GetProfileInt範例。

需求

Header: afxwin.h

請參閱

參考

CWinApp 類別

階層架構圖

CWinApp::GetProfileInt

CWinApp::WriteProfileString

CWinApp::SetRegistryKey