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

unix.superglobalmegacorp.com

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