_OS/2 2.X INITIALIZATION FILES AND PROFILE MANAGEMENT_ by Derrel R. Blain, Kurt Delimon, Jeff English [LISTING ONE] void APIENTRY enum_app_names(HINI hini,USHORT usStringID) /*-----------------------------------------------------------------*\ This function will query the size required to hold all of the application names for the current INI file. If the file contains entries, a temporary block of memory is allocated and the application names are queried from PM. The strings are then added to the application name listbox and the memory is freed. The first entry in the listbox is selected, causing its owner, the client, to be notified. The client window will then fill the key name listbox by calling enum_key_name function. \*-----------------------------------------------------------------*/ { PVOID pData; PBYTE pCurrent; ULONG ulSize = 0L; if (PrfQueryProfileSize(hini,NULL,NULL,(PULONG)&ulSize) && ulSize) { DosSubAlloc(pMem,(PPVOID)&pData,ulSize); if(PrfQueryProfileString(hini,NULL,NULL,"No Entries",pData,ulSize)) { pCurrent = pData; WinEnableWindowUpdate(hAppLBox,FALSE); WinSendMsg (hAppLBox,LM_DELETEALL,NULL,NULL); while (*pCurrent) { WinSendMsg (hAppLBox,LM_INSERTITEM,(MPARAM)LIT_SORTASCENDING, (MPARAM)pCurrent); while(*pCurrent) pCurrent++; pCurrent++; } WinSendMsg (hAppLBox,LM_SELECTITEM,MPFROMSHORT(0), MPFROMSHORT(TRUE)); WinEnableWindowUpdate(hAppLBox,TRUE); if (usStringID) { WinLoadString (hab,0,usStringID,MAX_TITLE,szTitle); WinSetWindowText(hWndFrame,(PSZ)szTitle); } } DosSubFree(pMem,pData,ulSize); } else { WinAlarm(HWND_DESKTOP,WA_WARNING); WinEnableWindowUpdate(hAppLBox,FALSE); WinSendMsg (hAppLBox,LM_DELETEALL,NULL,NULL); WinSendMsg (hAppLBox,LM_INSERTITEM,(MPARAM)LIT_SORTASCENDING,"No Entries"); WinSendMsg (hAppLBox,LM_SELECTITEM,MPFROMSHORT(0),MPFROMSHORT(TRUE)); WinEnableWindowUpdate(hAppLBox,TRUE); // No entries exist force the data window to free up it's // data buffer and repaint. get_key_data("",""); WinInvalidateRect(hDataWnd,NULL,FALSE); } } void APIENTRY enum_key_name(PSZ pAppName) /*-----------------------------------------------------------------*\ This function will query the size required to hold all of the key names for the current application name in the current INI file. If the application name contains key strings, a temporary block of memory is allocated and the key names are queried from PM. The strings are then added to the application name listbox and the memory is freed. The first entry in the listbox is selected causing its owner, the client, to be notifed. The client window will then fill the data window by calling get_key_data. \*-----------------------------------------------------------------*/ { PVOID pData; PBYTE pCurrent; ULONG ulSize = 0L; if (PrfQueryProfileSize(hCurrentIni,pAppName,NULL,(PULONG)&ulSize) && ulSize) { DosSubAlloc(pMem,(PPVOID)&pData,ulSize); if(PrfQueryProfileString(hCurrentIni,pAppName,NULL,"No Entries", pData,ulSize)) { pCurrent = pData; WinEnableWindowUpdate(hKeyLBox,FALSE); WinSendMsg (hKeyLBox,LM_DELETEALL,NULL,NULL); while (*pCurrent) { WinSendMsg (hKeyLBox,LM_INSERTITEM,(MPARAM)LIT_SORTASCENDING, (MPARAM)pCurrent); while(*pCurrent) pCurrent++; pCurrent++; } WinSendMsg (hKeyLBox,LM_SELECTITEM,MPFROMSHORT(0), MPFROMSHORT(TRUE)); WinEnableWindowUpdate(hKeyLBox,TRUE); } DosSubFree(pMem,pData,ulSize); } else { WinEnableWindowUpdate(hKeyLBox,FALSE); WinSendMsg (hKeyLBox,LM_DELETEALL,NULL,NULL); WinEnableWindowUpdate(hKeyLBox,TRUE); // No entries exist force the data window to free up it's // data buffer and repaint. get_key_data("",""); WinInvalidateRect(hDataWnd,NULL,FALSE); } } void APIENTRY get_key_data(PSZ pAppName,PSZ pKeyName) /*-----------------------------------------------------------------*\ This function will attempt to query the keydata for the current application-key pair. If key data currently exists, it is freed before the new entry is queried. If successful, a message is sent to the client to update the key data window title with the size of the new data. The data window is invalidated. \*-----------------------------------------------------------------*/ { if (pKeyData) { DosSubFree(pMem,pKeyData,ulKeySize); pKeyData = NULL; ulKeySize = 0; } if (PrfQueryProfileSize(hCurrentIni,pAppName,pKeyName,(PULONG)&ulKeySize) && ulKeySize) { DosSubAlloc(pMem,(PPVOID)&pKeyData,ulKeySize); if(PrfQueryProfileData(hCurrentIni,pAppName,pKeyName,pKeyData, (PULONG)&ulKeySize)) { // Update the title WinSendMsg(hDataWnd,WM_UPDATE_TITLE,0L,0L); // Force the data window to repaint WinInvalidateRect(hDataWnd,NULL,FALSE); } } }