Annotation of os232sdk/toolkt20/c/samples/iniedit/iniedit.c, revision 1.1

1.1     ! root        1: /******************************* Module Header ******************************\
        !             2: * Module Name: IniEdit.c
        !             3: *
        !             4: *
        !             5: * PM OS2.ini Editor
        !             6: *
        !             7: * Allows adding, deleting and modifying of os2.ini entries through PM
        !             8: * interface
        !             9: *
        !            10: * Created by Microsoft, IBM Corporation 1990
        !            11: *
        !            12: *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is 
        !            13: *      sample code created by Microsoft Corporation and/or IBM 
        !            14: *      Corporation. This sample code is not part of any standard 
        !            15: *      Microsoft or IBM product and is provided to you solely for 
        !            16: *      the purpose of assisting you in the development of your 
        !            17: *      applications.  The code is provided "AS IS", without 
        !            18: *      warranty of any kind.  Neither Microsoft nor IBM shall be 
        !            19: *      liable for any damages arising out of your use of the sample 
        !            20: *      code, even if they have been advised of the possibility of 
        !            21: *      such damages.
        !            22: *
        !            23: \***************************************************************************/
        !            24: 
        !            25: 
        !            26: #define LINT_ARGS                           // Include needed parts of PM
        !            27: #define INCL_WININPUT                       //    definitions
        !            28: #define INCL_WINSYS
        !            29: #define INCL_WINMESSAGEMGR
        !            30: #define INCL_WINBUTTONS
        !            31: #define INCL_WINPOINTERS
        !            32: #define INCL_WINHEAP
        !            33: #define INCL_WINSHELLDATA
        !            34: #define INCL_WINMENUS
        !            35: #define INCL_WINFRAMEMGR
        !            36: #define INCL_WINDIALOGS
        !            37: #define INCL_WINLISTBOXES
        !            38: #define INCL_WINENTRYFIELDS
        !            39: #define INCL_DOSMEMMGR
        !            40: #define INCL_WINSWITCHLIST
        !            41: #define INCL_DOSPROCESS
        !            42: #define INCL_GPIBITMAPS
        !            43: #define INCL_GPIREGIONS
        !            44: #define INCL_GPILCIDS
        !            45: #define INCL_GPIPRIMITIVES
        !            46: #define INCL_DEV
        !            47: 
        !            48: #include <string.h>
        !            49: #include <stdio.h>
        !            50: 
        !            51: #include <os2.h>
        !            52: 
        !            53: #include "IniEdit.h"
        !            54: 
        !            55: 
        !            56: /******************************* Constants **********************************/
        !            57: 
        !            58: #define STACK_SIZE            0x2000        // Stack size for second thread
        !            59: #define UPPER_SEGMENT_LIMIT   0xFD00        // Amount of Segment used
        !            60: 
        !            61: /******************************** Globals **********************************/
        !            62: 
        !            63: char szIniEdit[] = "IniEdit";               // App String Name
        !            64: 
        !            65: HAB       habIniEdit;                       // Handle Anchor Block
        !            66: HMQ       hmqIniEdit;                       // Handle Message Queue
        !            67: HWND      hwndIniEdit;                      // Main Client Window
        !            68: HWND      hwndIniEditFrame;                 // Frame Window
        !            69: HDC       hdcScreen;                        // DC for Client Window
        !            70: HPS       hpsScreen;                        // PS for Client Window
        !            71: 
        !            72: 
        !            73: USHORT    cAppNames = 0;                    // Count of App names in os2.ini
        !            74: HWND      FocusWindow = (HWND)NULL;         // Focus of Dialog Box
        !            75: USHORT    cxBorder;                         // System border width
        !            76: USHORT    cyBorder;                         // System border height
        !            77: 
        !            78: USHORT    usFormat = APP_FORM;              // Current Display format
        !            79: USHORT    usPrintFormat = APP_FORM;         // Format for Printing
        !            80: USHORT    usLineHeight = 12;                // Current font Height
        !            81: HWND      hwndList = (HWND)NULL;            // Handle of Main ListBox
        !            82: HWND      hwndMenu = (HWND)NULL;            // Handle of Main Menu
        !            83: 
        !            84: PGROUPSTRUCT  pGroups;                      // Pointer to String Groups
        !            85: PPAIRSTRUCT   pPairsBase;                   // Pointer to Key-Value Pairs
        !            86: PPAIRSTRUCT   pPairsAlloc;                  // Pointer to next Avail Memory
        !            87: 
        !            88: #define HOLD_LEN 4096
        !            89: CHAR          achNames[HOLD_LEN];           // Array of Character from Query
        !            90: CHAR          szBuf[2 * MAX_STRING_LEN];        // Character buffer for Pairs
        !            91: 
        !            92: /***************************** Function Decls ******************************/
        !            93: 
        !            94: VOID    ProcessMenuItem( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 );
        !            95: VOID    cdecl main( VOID );
        !            96: VOID    IniEditPaint( VOID );
        !            97: VOID    ReadIni( VOID );
        !            98: VOID    OldProfilePrint( VOID );
        !            99: VOID    UpdateListBox( BOOL fRead, USHORT usForm );
        !           100: 
        !           101: MRESULT EXPENTRY IniEditWndProc(HWND, USHORT, MPARAM, MPARAM);
        !           102: 
        !           103: 
        !           104: /***************************** Function Header *****************************\
        !           105: *
        !           106: * main
        !           107: *
        !           108: *
        !           109: * Do initialization then do a message loop
        !           110: *
        !           111: \***************************************************************************/
        !           112: 
        !           113: VOID cdecl main()
        !           114: {
        !           115: 
        !           116:     QMSG         qmsg;                      // Current Queue Message
        !           117:     ULONG        fcf;                       // Frame Control Flags
        !           118:     SIZEL        sizel;                     // Size of PS
        !           119:     RECTL        rclWindow;                 // Size Rect for ListBox Window
        !           120:     SWCNTRL      swcntrl;                   // Switch Control Block
        !           121:     FONTMETRICS  fmetrics;                  // FontMetrics of current font
        !           122: 
        !           123: 
        !           124:     /*** Set up and Initialization ***/
        !           125: 
        !           126:     /* Initialize the anchor block handle */
        !           127:     habIniEdit = WinInitialize(NULL);
        !           128: 
        !           129:     /* Create the message queue */
        !           130:     hmqIniEdit = WinCreateMsgQueue(habIniEdit, 0);
        !           131: 
        !           132:     /* Register the window class for the IniEdit window */
        !           133:     WinRegisterClass(habIniEdit, (PCH)szIniEdit, IniEditWndProc,
        !           134:             CS_SIZEREDRAW, 0);
        !           135: 
        !           136:     /* Create the window for IniEdit */
        !           137:     fcf = FCF_TITLEBAR | FCF_MINMAX | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MENU
        !           138:         | FCF_SHELLPOSITION | FCF_ACCELTABLE | FCF_ICON;
        !           139: 
        !           140:     hwndIniEditFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE,
        !           141:         (PVOID)&fcf, (PSZ)szIniEdit, (PSZ)szIniEdit, WS_VISIBLE,
        !           142:         (HMODULE)NULL, IDI_INIEDIT, (PHWND)&hwndIniEdit);
        !           143: 
        !           144:     /* Create a DC for the IniEdit window */
        !           145:     hdcScreen = WinOpenWindowDC(hwndIniEdit);
        !           146: 
        !           147:     /* also create a screen PS */
        !           148: 
        !           149:     sizel.cx= 0L;   // To use the default screen page size.
        !           150:     sizel.cy= 0L;
        !           151: 
        !           152:     if( (hpsScreen = GpiCreatePS( habIniEdit, hdcScreen, &sizel,
        !           153:             (PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC ))) == (HPS)NULL )
        !           154:         {
        !           155:                 ;
        !           156:         }
        !           157: 
        !           158: 
        !           159:     /* Initially set the keyboard focus to us */
        !           160:     WinSetFocus(HWND_DESKTOP, hwndIniEdit);
        !           161: 
        !           162:     /* get the font size */
        !           163:     GpiQueryFontMetrics( hpsScreen, (LONG)sizeof( FONTMETRICS ), &fmetrics );
        !           164:     usLineHeight = (USHORT)(fmetrics.lMaxDescender + fmetrics.lMaxBaselineExt);
        !           165: 
        !           166:     /* get the system widths of a border */
        !           167:     cxBorder = (USHORT) WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
        !           168:     cyBorder = (USHORT) WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
        !           169: 
        !           170:     /* this menu handle is often used */
        !           171:     hwndMenu = WinWindowFromID( hwndIniEditFrame, FID_MENU );
        !           172: 
        !           173:     /* add program to switch list */
        !           174:     swcntrl.hwnd             = hwndIniEditFrame;
        !           175:     swcntrl.hwndIcon         = NULL;
        !           176:     swcntrl.hprog            = NULL;
        !           177:     swcntrl.idProcess        = NULL;
        !           178:     swcntrl.idSession        = NULL;
        !           179:     swcntrl.uchVisibility    = NULL;
        !           180:     swcntrl.fbJump           = NULL;
        !           181:     strcpy( swcntrl.szSwtitle, szIniEdit);
        !           182:     swcntrl.bProgType       = NULL;
        !           183: 
        !           184:     WinAddSwitchEntry( &swcntrl );
        !           185: 
        !           186:     /* Create main list box in main window */
        !           187:     WinQueryWindowRect( hwndIniEdit, &rclWindow);
        !           188:     rclWindow.yTop -= usLineHeight;
        !           189:     rclWindow.yTop += cyBorder;
        !           190:     rclWindow.xRight += 2*cxBorder;
        !           191:     hwndList = WinCreateWindow( hwndIniEdit,            // parent
        !           192:                                 WC_LISTBOX,             // class
        !           193:                                 (PSZ)"Scroll",          // name
        !           194:                                 LS_NOADJUSTPOS,         // style
        !           195:                                 -cxBorder, -cyBorder,   // position
        !           196:                                 (USHORT)rclWindow.xRight,
        !           197:                                 (USHORT)rclWindow.yTop,
        !           198:                                 hwndIniEditFrame,       // Owner
        !           199:                                 HWND_TOP,               // InsertBehind
        !           200:                                 IDI_LIST,               // ID
        !           201:                                 (PVOID)NULL,            // pCtlData,
        !           202:                                 (PVOID)NULL);
        !           203: 
        !           204: 
        !           205:     /*** Memory Allocation ***/
        !           206: 
        !           207:     /* Alloc the needed space for the groups */
        !           208:     if( DosAllocMem( &pGroups, 32000L, fPERM | PAG_COMMIT) )
        !           209:         ErrMessage( "main: DosAlloc for pGroup failed" );
        !           210: 
        !           211:     if( DosAllocMem( &pPairsBase, 4*64000, fPERM | PAG_COMMIT) )
        !           212:         ErrMessage( "main: DosAlloc for pPairs failed" );
        !           213:     pPairsAlloc = pPairsBase;
        !           214: 
        !           215:     /* read in os2.ini and fill in list box */
        !           216:     UpdateListBox( TRUE, APP_FORM );
        !           217: 
        !           218:     WinShowWindow( hwndList, TRUE );
        !           219: 
        !           220:     /* Process messages for the window */
        !           221:     while ( WinGetMsg(habIniEdit, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
        !           222:         {
        !           223: 
        !           224:         /* Dispatch the message */
        !           225:         WinDispatchMsg(habIniEdit, (PQMSG)&qmsg);
        !           226:         }
        !           227: 
        !           228: 
        !           229:     /*** CleanUp ***/
        !           230: 
        !           231:     /* Destroy the IniEdit window and message queue */
        !           232:     GpiDestroyPS( hpsScreen );
        !           233:     WinDestroyWindow(hwndIniEditFrame);
        !           234:     WinDestroyMsgQueue(hmqIniEdit);
        !           235: 
        !           236:     /* Exit PM */
        !           237:     WinTerminate( habIniEdit );
        !           238:     DosExit( EXIT_PROCESS, 0 );
        !           239: 
        !           240: }  /* main */
        !           241: 
        !           242: 
        !           243: /****************************** Function Header ****************************\
        !           244: *
        !           245: * ReadIni
        !           246: *
        !           247: *
        !           248: * Reads in OS2.ini
        !           249: *
        !           250: \***************************************************************************/
        !           251: 
        !           252: VOID ReadIni()
        !           253: {
        !           254:     ULONG     cchNames;                    // Count of Character from Query
        !           255:     USHORT    Index[MAX_APP_NAMES];         // Index of Names into achNames
        !           256:     USHORT    cPairs;                       // Count of pairs in current AppName
        !           257:     ULONG     ul;
        !           258:     INT       i,j;                          // Loop Counters
        !           259: 
        !           260: 
        !           261:     /* Reset Count of App Names */
        !           262:     cAppNames = 0;
        !           263: 
        !           264:     /* Reset memory available pointer to Base */
        !           265:     pPairsAlloc = pPairsBase;
        !           266: 
        !           267:     /* Determine number of characters in app Names Strings */
        !           268:     PrfQueryProfileSize( HINI_PROFILE, NULL, NULL, &cchNames );
        !           269: 
        !           270:     /* Read in the App Name strings */
        !           271:     PrfQueryProfileString( HINI_PROFILE, NULL, NULL, " ", achNames, cchNames );
        !           272: 
        !           273:     /*** Find the starting index of each App ***/
        !           274: 
        !           275:     /* step through each string in set of app characters
        !           276:      * adding length of current string to find beginning of next string
        !           277:      * also store each App Name into szAppName element of Group
        !           278:      */
        !           279:     for( i=0; i<cchNames; i += (strlen(pGroups[cAppNames-1].szAppName)+1) )
        !           280:         {
        !           281:         if( achNames[i] != (char)0 )
        !           282:             {
        !           283:             strcpy( pGroups[cAppNames++].szAppName, &achNames[i]);
        !           284:             }  /* if */
        !           285:         else
        !           286:             if( achNames[i+1] == (char)0 )
        !           287:                 break;
        !           288:         }  /* for */
        !           289: 
        !           290: 
        !           291:     /*** Read elements of each App Name ***/
        !           292:     for( i=0; i<cAppNames; i++ )
        !           293:         {
        !           294:         /* Get number of Character Associated with App Name */
        !           295:        PrfQueryProfileSize( HINI_PROFILE, pGroups[i].szAppName, NULL, &cchNames );
        !           296: 
        !           297:         /* Enumerate all KeyNames for this app name */
        !           298:        PrfQueryProfileString( HINI_PROFILE, pGroups[i].szAppName, NULL, " ", achNames, HOLD_LEN );
        !           299: 
        !           300:         /* Count the number of key Names */
        !           301:         cPairs = 0;
        !           302:         for( j=0; j<cchNames; j++)
        !           303:             if( achNames[j] != (CHAR)0 )
        !           304:                 {
        !           305:                 Index[cPairs++] = j;
        !           306:                 j += strlen( &achNames[j] );
        !           307:                 }
        !           308: 
        !           309:         pGroups[i].cKeys = cPairs;
        !           310: 
        !           311:         /*
        !           312:          * Make sure we can fit the entire structure into our current
        !           313:          * segment, if not, lets jump to the next segment
        !           314:          */
        !           315:         ul =  sizeof(PAIRSTRUCT) * cPairs;
        !           316: 
        !           317:         /* Allocate the number of pair structures for the current group */
        !           318:         pGroups[i].pPairs = pPairsAlloc;
        !           319: 
        !           320:         // pPairsAlloc += sizeof(PAIRSTRUCT)*cPairs;
        !           321:         // Remember that incrementing a pointer automatically mult by size of item
        !           322:         pPairsAlloc += cPairs;
        !           323: 
        !           324: 
        !           325:         /* Store the KeyName into the pair structure */
        !           326:         for( j=0; j<cPairs; j++ )
        !           327:            {
        !           328:             strcpy( pGroups[i].pPairs[j].szKey, &achNames[Index[j]] );
        !           329: 
        !           330:             /* store the key value */
        !           331:            PrfQueryProfileString( HINI_PROFILE, pGroups[i].szAppName,
        !           332:                      pGroups[i].pPairs[j].szKey, " ",
        !           333:                      pGroups[i].pPairs[j].szValue, MAX_STRING_LEN );
        !           334: 
        !           335:             }
        !           336:         }  /* each App Name */
        !           337: 
        !           338: }  /* ReadIni */
        !           339: 
        !           340: 
        !           341: /****************************** Function Header ****************************\
        !           342: *
        !           343: * ProcessMenuItem
        !           344: *
        !           345: *
        !           346: * Act on the corresponding Menu Item Choosen
        !           347: *
        !           348: \***************************************************************************/
        !           349: 
        !           350: VOID ProcessMenuItem( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
        !           351: {
        !           352:     TID  Tid;                               // ID of new thread; Not used
        !           353: 
        !           354: 
        !           355:     /* Switch on the Menu Item choosen */
        !           356:     switch( LOUSHORT( mp1 ) )
        !           357:         {
        !           358:         case IDMI_SHOW_ALL:
        !           359:         case IDMI_SHOW_APPNAMES:
        !           360:             usFormat = (LOUSHORT(mp1) == IDMI_SHOW_ALL);
        !           361:             UpdateListBox( FALSE, usFormat ? ALL_FORM : APP_FORM );
        !           362:             break;
        !           363: 
        !           364:         case IDM_SEARCH:
        !           365:             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)SearchWndProc,
        !           366:                             (HMODULE)NULL, IDD_SEARCH, (PVOID)NULL);
        !           367:             break;
        !           368: 
        !           369:         case IDMI_EDIT_DELETE_KEY:
        !           370:             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)DelKeyWndProc,
        !           371:                             (HMODULE)NULL, IDD_DEL_KEY, (PVOID)NULL);
        !           372:             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
        !           373:             break;
        !           374: 
        !           375:         case IDMI_EDIT_DELETE_APP:
        !           376:             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)DelAppWndProc,
        !           377:                             (HMODULE)NULL, IDD_DEL_APP, (PVOID)NULL);
        !           378:             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
        !           379:             break;
        !           380: 
        !           381:         case IDMI_EDIT_ADD_KEY:
        !           382:             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)AddKeyWndProc,
        !           383:                             (HMODULE)NULL, IDD_ADD_KEY, (PVOID)NULL);
        !           384:             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
        !           385:             break;
        !           386: 
        !           387:         case IDMI_EDIT_CHANGE:
        !           388:             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)ChangeKeyWndProc,
        !           389:                             (HMODULE)NULL, IDD_CHANGE_KEY, (PVOID)NULL);
        !           390:             UpdateListBox( TRUE, usFormat ? ALL_FORM : APP_FORM );
        !           391:             break;
        !           392: 
        !           393:         case IDMI_PRINT_ALL:
        !           394:         case IDMI_PRINT_APP:
        !           395:             usPrintFormat = LOUSHORT(mp1) == IDMI_PRINT_ALL ? ALL_FORM : APP_FORM;
        !           396:            if( DosCreateThread( &Tid, PrintThread, 0L, 0L, STACK_SIZE) )
        !           397:                 ErrMessage("StartThread2: DosCreateThread Failed");
        !           398:             break;
        !           399: 
        !           400:         case IDMI_REFRESH:
        !           401:             UpdateListBox( TRUE, usFormat );
        !           402:             break;
        !           403: 
        !           404:         case IDMI_ABOUT:
        !           405:             WinDlgBox(HWND_DESKTOP, hwndIniEditFrame, (PFNWP)DelAppWndProc,
        !           406:                             (HMODULE)NULL, IDD_ABOUT, (PVOID)NULL);
        !           407:             break;
        !           408: 
        !           409:         default:
        !           410:             WinDefWindowProc(hwnd, msg, mp1, mp2);
        !           411: 
        !           412:             break;
        !           413: 
        !           414:         }  /* switch */
        !           415: 
        !           416: }  /* ProcessMenuItem */
        !           417: 
        !           418: 
        !           419: /****************************** Function Header ****************************\
        !           420: *
        !           421: * UpdateListBox
        !           422: *
        !           423: *
        !           424: * Update Main List Box to correct state
        !           425: *    May Also:
        !           426: *    - Check correct menu item
        !           427: *    - Repaint title of List Box
        !           428: *    - ReRead os2.ini file
        !           429: *
        !           430: \***************************************************************************/
        !           431: 
        !           432: VOID UpdateListBox( BOOL fReadIni, USHORT usNewFormat )
        !           433: {
        !           434:     INT       i,j;                          // Loop Counters
        !           435:     USHORT    Index;                        // Index into ListBox
        !           436:     static    USHORT    usLastFormat = -1;  // Last displayed format
        !           437: 
        !           438: 
        !           439:     /* Check the correct item if format changed */
        !           440:     if( usLastFormat != usNewFormat )
        !           441:         {
        !           442:         WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDMI_SHOW_ALL, TRUE),
        !           443:                 MPFROM2SHORT(MIA_CHECKED, usFormat ? MIA_CHECKED:FALSE));
        !           444: 
        !           445:         WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDMI_SHOW_APPNAMES, TRUE),
        !           446:                 MPFROM2SHORT(MIA_CHECKED, (!usFormat) ? MIA_CHECKED:FALSE));
        !           447:         usLastFormat = usNewFormat;
        !           448: 
        !           449:         WinSendMsg( hwndIniEdit, WM_PAINT, (MPARAM)NULL, (MPARAM)NULL );
        !           450:         }
        !           451: 
        !           452: 
        !           453:     /* Turn off list box updates */
        !           454:     WinEnableWindowUpdate( hwndList, FALSE );
        !           455: 
        !           456:     /* Remove all items from list box */
        !           457:     WinSendMsg( hwndList, LM_DELETEALL, (MPARAM)0, (MPARAM)0 );
        !           458: 
        !           459:     /* ReRead os2.ini if needed */
        !           460:     if( fReadIni )
        !           461:         ReadIni();
        !           462: 
        !           463:     /* Add elements to listbox */
        !           464:     if( usNewFormat == ALL_FORM )
        !           465:         {
        !           466: 
        !           467:         /* Insert all app Names */
        !           468:         for( i=0; i<cAppNames; i++ )
        !           469:             {
        !           470:             Index = (USHORT)WinSendMsg( hwndList, LM_INSERTITEM,
        !           471:                     MPFROM2SHORT(LIT_END, NULL),
        !           472:                     MPFROMP(pGroups[i].szAppName) );
        !           473: 
        !           474:             WinSendMsg( hwndList, LM_SETITEMHANDLE,
        !           475:                     MPFROMSHORT(Index),
        !           476:                     MPFROMSHORT(i) );
        !           477: 
        !           478:             /* Insert Key Value Pairs for App Name */
        !           479:             for( j=0; j<pGroups[i].cKeys; j++ )
        !           480:                 {
        !           481:                 sprintf( szBuf, "     %s: %s", pGroups[i].pPairs[j].szKey,
        !           482:                         pGroups[i].pPairs[j].szValue );
        !           483:                 Index = (USHORT)WinSendMsg( hwndList, LM_INSERTITEM,
        !           484:                         MPFROM2SHORT(LIT_END, NULL),
        !           485:                         MPFROMP(szBuf) );
        !           486: 
        !           487:                 WinSendMsg( hwndList, LM_SETITEMHANDLE,
        !           488:                         MPFROMSHORT(Index),
        !           489:                         MPFROM2SHORT(i,j) );
        !           490: 
        !           491:                 }
        !           492:             }
        !           493:         }  /* if */
        !           494:     else
        !           495:         {
        !           496:         /* Insert all app Names */
        !           497:         for( i=0; i<cAppNames; i++ )
        !           498:             {
        !           499:             WinSendMsg( hwndList, LM_INSERTITEM,
        !           500:                     MPFROM2SHORT(LIT_SORTASCENDING, NULL),
        !           501:                     MPFROMP(pGroups[i].szAppName) );
        !           502:             }
        !           503:         }  /* else */
        !           504: 
        !           505:     /* Do All repainting of ListBox */
        !           506:     WinEnableWindowUpdate( hwndList, TRUE );
        !           507: 
        !           508: }  /* UpdateListBox */
        !           509: 
        !           510: 
        !           511: /****************************** Function Header ****************************\
        !           512: *
        !           513: * IniEditPaint
        !           514: *
        !           515: *
        !           516: * Window Paint Routine
        !           517: *
        !           518: \***************************************************************************/
        !           519: 
        !           520: VOID IniEditPaint()
        !           521: {
        !           522:     RECTL     rclWindow;                    // Current size of Main Window
        !           523:     RECTL     rclBlit;                      // Size of Area to Blank for Title
        !           524:     CHAR      szShowMode[MAX_STRING_LEN];   // String Description of mode
        !           525: 
        !           526: 
        !           527:     /* Get the size of the whole window */
        !           528:     WinQueryWindowRect( hwndIniEdit, &rclWindow );
        !           529: 
        !           530:     /* Paint the window Title Area */
        !           531:     rclBlit = rclWindow;
        !           532:     rclBlit.yBottom = rclBlit.yTop - usLineHeight;
        !           533: 
        !           534:     GpiBitBlt( hpsScreen, (HPS)NULL, 2L, (PPOINTL)&rclBlit, ROP_ONE, (LONG)NULL);
        !           535: 
        !           536:     /* Write the Title */
        !           537:     strcpy( szShowMode, usFormat == APP_FORM ? SZAPP : SZALL );
        !           538:     WinDrawText( hpsScreen, strlen(szShowMode), szShowMode, &rclWindow,
        !           539:             CLR_BLUE, CLR_WHITE, DT_CENTER|DT_TOP);
        !           540: 
        !           541: }  /* IniEditPaint */
        !           542: 
        !           543: 
        !           544: /****************************** Function Header ****************************\
        !           545: *
        !           546: * IniEditWndProc
        !           547: *
        !           548: *
        !           549: * Window Proc for IniEdit
        !           550: *
        !           551: \***************************************************************************/
        !           552: 
        !           553: MRESULT EXPENTRY IniEditWndProc(HWND hwnd, USHORT msg,
        !           554:         MPARAM mp1, MPARAM mp2)
        !           555: {
        !           556: 
        !           557:     CHAR      szBuf[MAX_STRING_LEN];        // Input character Buffer
        !           558:     CHAR      szBuf2[MAX_STRING_LEN];       // Second Input Character Buffer
        !           559:     USHORT    Index;                        // Index of Current ListBox Item
        !           560:     USHORT    TopIndex;                     // Current Top Item in ListBox
        !           561:     ULONG     Handle;                       // ListBox Item Handle Info
        !           562:     HWND      hwndDialog;                   // Window handle of Dailog Box
        !           563:     HWND      hwndText;                     // Handle of current text window
        !           564:     HPS       hpsPaint;                     // PS to Paint
        !           565:     RECTL     rclPaint;                     // Rect in hpsPaint to Paint
        !           566:     BOOL      fScroll = FALSE;              // Scroll List Box Flag
        !           567: 
        !           568: 
        !           569:     /* Switch on message being processed */
        !           570:     switch( msg )
        !           571:         {
        !           572:         case WM_PAINT:
        !           573:             /* Paint the IniEdit window portion not covered by List Box */
        !           574:             hpsPaint = WinBeginPaint(hwnd, (HPS)NULL, &rclPaint);
        !           575:             IniEditPaint();
        !           576:             WinEndPaint(hpsPaint);
        !           577:             break;
        !           578: 
        !           579:         case WM_COMMAND:
        !           580:             /* If menu item call Processing Routine */
        !           581:             if( LOUSHORT( mp2 ) == CMDSRC_MENU )
        !           582:                 ProcessMenuItem( hwnd, msg, mp1, mp2 );
        !           583: 
        !           584:             /* If accelorator call appropriate routine */
        !           585:             if( LOUSHORT( mp2 ) == CMDSRC_ACCELERATOR )
        !           586:                 {
        !           587:                 switch( LOUSHORT( mp1 ) )
        !           588:                     {
        !           589:                     case IDDI_SEARCH_NEXT:
        !           590:                         FindNext();
        !           591:                         break;
        !           592:                     }
        !           593:                 }
        !           594:             break;
        !           595: 
        !           596:         case WM_SIZE:
        !           597:             /* Put the list box in the correct location of the window */
        !           598:             if( hwndList != (HWND)NULL )
        !           599:                 /* The position is set to fill the client, except for the */
        !           600:                 /* area at the top for some text.  In addition, the       */
        !           601:                 /* rectangle is outset by a border width on all dimensions*/
        !           602:                 /* except for the top so that the list box border is      */
        !           603:                 /* "tucked" under the clients border and doesn't cause    */
        !           604:                 /* there to be a double thick border around it.           */
        !           605:                 WinSetWindowPos( hwndList, HWND_TOP, -cxBorder, -cyBorder,
        !           606:                         SHORT1FROMMP(mp2)+(2*cxBorder),
        !           607:                         SHORT2FROMMP(mp2)-usLineHeight + cyBorder,
        !           608:                         SWP_SIZE | SWP_MOVE );
        !           609:             break;
        !           610: 
        !           611:         case WM_CONTROL:
        !           612:             /* Switch on Control activated */
        !           613:             switch( SHORT1FROMMP(mp1) )
        !           614:                 {
        !           615: 
        !           616:                 /*** Process List Box Activity ***/
        !           617:                 case IDI_LIST:
        !           618:                     /* was it a double click? */
        !           619:                     if( SHORT2FROMMP(mp1) == LN_ENTER )
        !           620:                         {
        !           621:                         /* get the item clicked on */
        !           622:                         Index = (USHORT)WinSendMsg( hwndList, LM_QUERYSELECTION,
        !           623:                                 (MPARAM)0, (MPARAM)0 );
        !           624: 
        !           625:                         /* grab its text */
        !           626:                         WinSendMsg( hwndList, LM_QUERYITEMTEXT,
        !           627:                                 MPFROM2SHORT(Index, MAX_STRING_LEN), MPFROMP(szBuf) );
        !           628: 
        !           629:                         /* if in APP form toggle to ALL form */
        !           630:                         if( usFormat == APP_FORM )
        !           631:                             {
        !           632:                             usFormat = ALL_FORM;
        !           633:                             fScroll = TRUE;
        !           634:                             }
        !           635:                         else
        !           636:                             {
        !           637:                             /* if an App name was choosen then go to APP form */
        !           638:                             if( szBuf[0] != ' ')
        !           639:                                 {
        !           640:                                 usFormat = APP_FORM;
        !           641:                                 fScroll = TRUE;
        !           642:                                 }
        !           643:                             else
        !           644:                                 /* A Key Value Pair was double clicked
        !           645:                                  * allow editing of key Value
        !           646:                                  */
        !           647:                                 {
        !           648: 
        !           649:                                 FocusWindow = (HWND)1;
        !           650: 
        !           651:                                 hwndDialog = WinLoadDlg( HWND_DESKTOP,
        !           652:                                     hwndIniEditFrame, ChangeKeyWndProc,
        !           653:                                     (HMODULE)NULL, IDD_CHANGE_KEY, NULL);
        !           654: 
        !           655:                                 Handle = (ULONG)WinSendMsg( hwndList, LM_QUERYITEMHANDLE,
        !           656:                                     MPFROMSHORT(Index), (MPARAM)NULL );
        !           657: 
        !           658:                                 hwndText = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_APP );
        !           659:                                 WinSendMsg(hwndText, EM_SETTEXTLIMIT,
        !           660:                                         MPFROMSHORT(MAX_STRING_LEN), 0L);
        !           661:                                 WinSetWindowText( hwndText, pGroups[LOUSHORT(Handle)].szAppName);
        !           662: 
        !           663:                                 /* note bug in PMWin GPs if full segment */
        !           664:                                 hwndText = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_KEY );
        !           665:                                 WinSendMsg(hwndText, EM_SETTEXTLIMIT,
        !           666:                                         MPFROMSHORT(MAX_STRING_LEN), 0L);
        !           667:                                 strcpy( szBuf2, pGroups[LOUSHORT(Handle)].pPairs[HIUSHORT(Handle)].szKey );
        !           668:                                 WinSetWindowText( hwndText, szBuf2 );
        !           669: 
        !           670:                                 hwndText = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL );
        !           671:                                 WinSendMsg(hwndText, EM_SETTEXTLIMIT,
        !           672:                                         MPFROMSHORT(MAX_STRING_LEN), 0L);
        !           673:                                 strcpy( szBuf2, pGroups[LOUSHORT(Handle)].pPairs[HIUSHORT(Handle)].szValue );
        !           674:                                 WinSetWindowText( hwndText, szBuf2 );
        !           675: 
        !           676:                                 WinPostMsg( hwndText, EM_SETSEL,
        !           677:                                         MPFROM2SHORT(0, strlen(szBuf2)), (MPARAM)0 );
        !           678: 
        !           679:                                 if( WinProcessDlg( hwndDialog ) == IDDI_CHANGE_KEY_OK )
        !           680:                                     {
        !           681:                                     TopIndex = (USHORT)WinSendMsg( hwndList, LM_QUERYTOPINDEX,
        !           682:                                          (MPARAM)NULL, (MPARAM)NULL );
        !           683: 
        !           684:                                     UpdateListBox( TRUE, usFormat );
        !           685: 
        !           686:                                     /* scroll to top */
        !           687:                                     WinSendMsg( hwndList, LM_SETTOPINDEX,
        !           688:                                          MPFROMSHORT(TopIndex), (MPARAM)NULL );
        !           689: 
        !           690:                                     /* make the item selected */
        !           691:                                     WinSendMsg( hwndList, LM_SELECTITEM,
        !           692:                                             MPFROMSHORT(Index), MPFROMSHORT(TRUE) );
        !           693: 
        !           694:                                     /* make selected */
        !           695:                                     }
        !           696: 
        !           697:                                 WinDestroyWindow( hwndDialog );
        !           698:                                 }
        !           699:                             }
        !           700: 
        !           701:                         /* Make the double clicked item selected in new form */
        !           702:                         if( fScroll )
        !           703:                             {
        !           704:                             /* put in correct form */
        !           705:                             UpdateListBox( FALSE, usFormat );
        !           706: 
        !           707:                             /* get the index of the item clicked on */
        !           708:                             Index = (USHORT)WinSendMsg( hwndList, LM_SEARCHSTRING,
        !           709:                                     MPFROM2SHORT(LSS_SUBSTRING, LIT_FIRST),
        !           710:                                     MPFROMP(szBuf) );
        !           711: 
        !           712:                             /* scroll that item to the top */
        !           713:                             WinSendMsg( hwndList, LM_SETTOPINDEX,
        !           714:                                     MPFROMSHORT(Index), (MPARAM)NULL );
        !           715: 
        !           716:                             /* make the item selected */
        !           717:                             WinSendMsg( hwndList, LM_SELECTITEM,
        !           718:                                     MPFROMSHORT(Index), MPFROMSHORT(TRUE) );
        !           719:                             }
        !           720:                         }  /* if ENTER */
        !           721:                 }
        !           722:             break;
        !           723: 
        !           724:         default:
        !           725:             return WinDefWindowProc(hwnd, msg, mp1, mp2);
        !           726:             break;
        !           727:         }
        !           728: 
        !           729:     return 0L;
        !           730: 
        !           731: }  /* IniEditWndProc */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.