home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*\
- | UIReg.cpp - DevUI(tm) string list profile functions |
- | From Developing User Interfaces for Microsoft Windows |
- | Copyright (c) 1999, Everett N. McKay |
- \*---------------------------------------------------------------------------*/
-
- #include "stdafx.h"
- #include "DevUI.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- // effect: Similar to WriteProfileString, but for CStringLists.
- HRESULT McSetProfileStringList (LPCTSTR section, LPCTSTR entryPrefix,
- const CStringList &list)
- {
- CWinApp *pApp = AfxGetApp();
- CString entry, ep;
- POSITION pos;
- int i, length, oldLength, retVal;
-
- ASSERT_VALID(pApp);
- ASSERT_VALID(&list);
- ASSERT(section != 0);
- ASSERT(entryPrefix != 0);
-
- // get old list length and set new length
- ep = (CString)entryPrefix;
- entry = ep + _T("Count");
- oldLength = pApp->GetProfileInt(section, entry, 0);
- length = list.GetCount();
- retVal = pApp->WriteProfileInt(section, entry, length);
-
- // set new items
- for (i = 0, pos = list.GetHeadPosition();
- pos != 0;
- i++, list.GetNext(pos))
- {
- entry.Format(_T("%s%d"), ep, i + 1);
- retVal = pApp->WriteProfileString(section, entry, list.GetAt(pos));
- }
-
- // remove unused old items
- if (oldLength > length)
- {
- for (i = length; i < oldLength; i++)
- {
- entry.Format(_T("%s%d"), ep, i + 1);
- pApp->WriteProfileString(section, entry, 0);
- }
- }
-
- return (retVal > 0) ? NO_ERROR : E_FAIL;
- }
-
- // effect: Similar to GetProfileString, but for CStringLists.
- HRESULT McGetProfileStringList (LPCTSTR section, LPCTSTR entryPrefix,
- CStringList &list)
- {
- CWinApp *pApp = AfxGetApp();
- CString entry, ep, s;
- int i, length;
-
- ASSERT_VALID(pApp);
- ASSERT_VALID(&list);
- ASSERT(section != 0);
- ASSERT(entryPrefix != 0);
-
- // get length
- ep = (CString)entryPrefix;
- entry = ep + _T("Count");
- length = pApp->GetProfileInt(section, entry, 0);
-
- // clear list
- list.RemoveAll();
-
- // load list
- for (i = 0; i < length; i++)
- {
- entry.Format(_T("%s%d"), ep, i + 1);
- s = pApp->GetProfileString(section, entry, 0);
- list.AddTail(s);
- }
-
- return NO_ERROR;
- }
-
-