home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12732.ZIP / DLGPROC.C next >
Text File  |  1990-08-17  |  15KB  |  476 lines

  1. /******************************* Module Header ******************************\
  2. * Module Name: DlgProc.c
  3. *
  4. * Created by Microsoft Corporation, 1989
  5. *
  6. *
  7. * System Test Application
  8. *
  9. *
  10. \***************************************************************************/
  11.  
  12.  
  13. #define INCL_PM
  14. #define INCL_BASE
  15.  
  16. #include <string.h>
  17. #include <stdio.h>
  18.  
  19. #include <os2.h>
  20.  
  21. #include "IniEdit.h"
  22.  
  23.  
  24. /******************************* Constants *********************************/
  25.  
  26. #define BUF_SIZE 132
  27.  
  28.  
  29. /******************************** Globals **********************************/
  30.  
  31. static CHAR   szSearch[BUF_SIZE] = { 0 };           // Current search string
  32. static USHORT usLastIndex = 0;                      // Last Searched Item
  33.  
  34. /******************************* Externals *********************************/
  35.  
  36. extern USHORT        cAppNames;                     // see iniedit.c
  37. extern HWND          hwndList;
  38. extern PGROUPSTRUCT  pGroups;
  39. extern HAB           habIniEdit;
  40. extern HWND          FocusWindow;
  41. extern HINI          hIniFile;
  42.  
  43.  
  44. /****************************** Function Header ****************************\
  45. *
  46. * SearchWndProc
  47. *
  48. *
  49. * Handles the Search Dialog Box messages
  50. *
  51. \***************************************************************************/
  52.  
  53. MRESULT _loadds EXPENTRY SearchWndProc(HWND hwndDialog, USHORT msg,
  54.         MPARAM mp1, MPARAM mp2)
  55. {
  56.     HWND   hwndText;                            // Current Text Window
  57.  
  58.  
  59.     switch (msg)
  60.         {
  61.  
  62.         case WM_INITDLG:
  63.             hwndText = WinWindowFromID( hwndDialog, IDDI_SEARCH_TEXT );
  64.             WinSetWindowText(hwndText, szSearch);
  65.             WinSendMsg( hwndText, EM_SETSEL,
  66.                     MPFROM2SHORT(0, strlen(szSearch)), (MPARAM)0 );
  67.  
  68.             break;
  69.  
  70.         case WM_COMMAND:
  71.             switch( LOUSHORT( mp1 ) )
  72.                 {
  73.  
  74.                 case IDDI_SEARCH_OK:
  75.                     hwndText = WinWindowFromID( hwndDialog, IDDI_SEARCH_TEXT );
  76.                     WinQueryWindowText( hwndText, BUF_SIZE, szSearch );
  77.                     WinDismissDlg( hwndDialog, 0 );
  78.  
  79.                     if( (usLastIndex = (USHORT) (ULONG) WinSendMsg( hwndList, LM_SEARCHSTRING,
  80.                             MPFROM2SHORT( LSS_SUBSTRING, LIT_FIRST),
  81.                             MPFROMP( szSearch )) ) != LIT_NONE )
  82.                         {
  83.                         WinSendMsg( hwndList, LM_SELECTITEM,
  84.                                 MPFROM2SHORT( (usLastIndex), NULL),
  85.                                 MPFROM2SHORT( TRUE, NULL ) );
  86.                         }
  87.                     else  /* not found */
  88.                         {
  89.                         usLastIndex = LIT_FIRST;
  90.                         WinAlarm( HWND_DESKTOP, 0);
  91.                         }
  92.                     break;
  93.  
  94.                 case IDDI_SEARCH_NEXT:
  95.                     FindNext();
  96.                     break;
  97.  
  98.                 default:
  99.                     return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  100.                     break;
  101.                 }
  102.  
  103.         default:
  104.             return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  105.             break;
  106.         }
  107.  
  108.     return 0L;
  109.  
  110. }  /* SearchWndProc */
  111.  
  112.  
  113. /****************************** Function Header ****************************\
  114. *
  115. * FindNext
  116. *
  117. *
  118. * Finds the next instance of the current search string starting from the
  119. * Last searched position
  120. *
  121. \***************************************************************************/
  122.  
  123. VOID FindNext()
  124. {
  125.    if( (usLastIndex = (USHORT) (ULONG)WinSendMsg( hwndList, LM_SEARCHSTRING,
  126.            MPFROM2SHORT( LSS_SUBSTRING, usLastIndex),
  127.            MPFROMP( szSearch )) ) != LIT_NONE )
  128.        {
  129.        WinSendMsg( hwndList, LM_SELECTITEM,
  130.                MPFROM2SHORT( (usLastIndex), NULL),
  131.                MPFROM2SHORT( TRUE, NULL ) );
  132.        }
  133.    else   /* alarm if not found */
  134.        WinAlarm( HWND_DESKTOP, 0);
  135.  
  136. }  /* FindNext */
  137.  
  138.  
  139. /****************************** Function Header ****************************\
  140. *
  141. * AddKeyWndProc
  142. *
  143. *
  144. * Handles the AddKey Dialog Box messages
  145. * Will facilitate adding new keys for a given App Name
  146. *
  147. \***************************************************************************/
  148.  
  149. MRESULT _loadds EXPENTRY AddKeyWndProc(HWND hwndDialog, USHORT msg,
  150.         MPARAM mp1, MPARAM mp2)
  151. {
  152.     HWND   hwndTextApp;                         // Handle for App Text Window
  153.     HWND   hwndTextKey;
  154.     HWND   hwndTextValue;
  155.     CHAR   szApp[BUF_SIZE];                     // String Contents
  156.     CHAR   szKey[BUF_SIZE];
  157.     CHAR   szValue[BUF_SIZE];
  158.  
  159.  
  160.     switch (msg)
  161.         {
  162.         case WM_INITDLG:
  163.             WinSendDlgItemMsg(hwndDialog, IDDI_ADD_KEY_TEXT_APP, EM_SETTEXTLIMIT,
  164.                     MPFROMSHORT(MAX_STRING_LEN), 0L);
  165.             WinSendDlgItemMsg(hwndDialog, IDDI_ADD_KEY_TEXT_KEY, EM_SETTEXTLIMIT,
  166.                     MPFROMSHORT(MAX_STRING_LEN), 0L);
  167.             WinSendDlgItemMsg(hwndDialog, IDDI_ADD_KEY_TEXT_VAL, EM_SETTEXTLIMIT,
  168.                     MPFROMSHORT(MAX_STRING_LEN), 0L);
  169.             break;
  170.         case WM_COMMAND:
  171.             switch( LOUSHORT( mp1 ) )
  172.                 {
  173.  
  174.                 case IDDI_ADD_KEY_OK:
  175.                     hwndTextApp = WinWindowFromID( hwndDialog, IDDI_ADD_KEY_TEXT_APP );
  176.                     WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );
  177.  
  178.                     hwndTextKey = WinWindowFromID( hwndDialog, IDDI_ADD_KEY_TEXT_KEY );
  179.                     WinQueryWindowText( hwndTextKey, BUF_SIZE, szKey );
  180.  
  181.                     hwndTextValue = WinWindowFromID( hwndDialog, IDDI_ADD_KEY_TEXT_VAL );
  182.                     WinQueryWindowText( hwndTextValue, BUF_SIZE, szValue );
  183.  
  184.                     WinDismissDlg( hwndDialog, 0 );
  185.  
  186.                     /* if the App is NULL forget it */
  187.                     if( *szApp == (CHAR)0 )
  188.                         {
  189.                         break;
  190.                         }
  191.  
  192.                     /* if the Key is NULL forget it */
  193.                     if( *szKey == (CHAR)0 )
  194.                         {
  195.                         break;
  196.                         }
  197.  
  198.                     /* if the Value is NULL forget it */
  199.                     if( *szValue == (CHAR)0 )
  200.                         {
  201.                         break;
  202.                         }
  203.  
  204. #ifdef INI11
  205.                     if( !WinWriteProfileString( habIniEdit, szApp, szKey, szValue ) )
  206.                         ;
  207.  
  208. #else
  209.                     if( !PrfWriteProfileString( hIniFile, szApp, szKey, szValue ) )
  210.                         ;
  211. #endif
  212.  
  213.  
  214.                     break;
  215.  
  216.                 default:
  217.                     return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  218.                     break;
  219.                 }
  220.  
  221.         default:
  222.             return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  223.             break;
  224.         }
  225.  
  226.     return 0L;
  227.  
  228. }  /* AddKeyWndProc */
  229.  
  230.  
  231. /****************************** Function Header ****************************\
  232. *
  233. * ChangeKeyWndProc
  234. *
  235. *
  236. * Handles the ChangeKey Dialog Box messages
  237. * Will facilitate changing a key's value given an app, key and new value
  238. *
  239. \***************************************************************************/
  240.  
  241. MRESULT _loadds EXPENTRY ChangeKeyWndProc(HWND hwndDialog, USHORT msg,
  242.         MPARAM mp1, MPARAM mp2)
  243. {
  244.     HWND     hwndTextApp;                       // Handle for App Text Window
  245.     HWND     hwndTextKey;
  246.     HWND     hwndTextVal;
  247.     CHAR     szApp[BUF_SIZE];                   // String Contents
  248.     CHAR     szKey[BUF_SIZE];
  249.     CHAR     szVal[BUF_SIZE];
  250.  
  251.  
  252.     switch (msg)
  253.         {
  254.         case WM_INITDLG:
  255.             if( FocusWindow )
  256.                 {
  257.  
  258.                 FocusWindow = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL );
  259.                 WinSetFocus( HWND_DESKTOP, FocusWindow);
  260.                 WinQueryWindowText( FocusWindow, BUF_SIZE, szVal );
  261.  
  262.                 FocusWindow = (HWND)NULL;
  263.  
  264.                 return( (MRESULT) TRUE );
  265.                 } else {
  266.                 WinSendDlgItemMsg(hwndDialog, IDDI_CHANGE_KEY_TEXT_APP, EM_SETTEXTLIMIT,
  267.                         MPFROMSHORT(MAX_STRING_LEN), 0L);
  268.                 WinSendDlgItemMsg(hwndDialog, IDDI_CHANGE_KEY_TEXT_KEY, EM_SETTEXTLIMIT,
  269.                         MPFROMSHORT(MAX_STRING_LEN), 0L);
  270.                 WinSendDlgItemMsg(hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL, EM_SETTEXTLIMIT,
  271.                         MPFROMSHORT(MAX_STRING_LEN), 0L);
  272.                 }
  273.             break;
  274.  
  275.         case WM_COMMAND:
  276.             switch( LOUSHORT( mp1 ) )
  277.                 {
  278.  
  279.                 case IDDI_CHANGE_KEY_OK:
  280.                     hwndTextApp = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_APP );
  281.                     WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );
  282.  
  283.                     hwndTextKey = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_KEY );
  284.                     WinQueryWindowText( hwndTextKey, BUF_SIZE, szKey );
  285.  
  286.                     hwndTextVal = WinWindowFromID( hwndDialog, IDDI_CHANGE_KEY_TEXT_VAL );
  287.                     WinQueryWindowText( hwndTextVal, BUF_SIZE, szVal );
  288.  
  289.  
  290.                     WinDismissDlg( hwndDialog, IDDI_CHANGE_KEY_OK );
  291.  
  292.                     /* if the App is NULL forget it */
  293.                     if( *szApp == (CHAR)0 )
  294.                         {
  295.                         break;
  296.                         }
  297.  
  298.                     /* if the Key is NULL forget it */
  299.                     if( *szKey == (CHAR)0 )
  300.                         {
  301.                         break;
  302.                         }
  303.  
  304.                     /* if the Value is NULL forget it */
  305.                     if( *szVal == (CHAR)0 )
  306.                         {
  307.                         break;
  308.                         }
  309.  
  310.  
  311. #ifdef INI11
  312.                     if( !WinWriteProfileString( habIniEdit, szApp, szKey, szVal ) )
  313. #else
  314.                     if( !PrfWriteProfileString( hIniFile, szApp, szKey, szVal ) )
  315.  
  316. #endif
  317.                     break;
  318.  
  319.                 default:
  320.                     return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  321.                     break;
  322.                 }
  323.  
  324.         default:
  325.             return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  326.             break;
  327.         }
  328.  
  329.     return 0L;
  330.  
  331. }  /* ChangeKeyWndProc */
  332.  
  333.  
  334. /****************************** Function Header ****************************\
  335. *
  336. * DelKeyWndProc
  337. *
  338. *
  339. * Handles the DelKey Dialog Box messages
  340. * Will facilitate deleting a key value given an app and the key
  341. *
  342. \***************************************************************************/
  343.  
  344. MRESULT _loadds EXPENTRY DelKeyWndProc(HWND hwndDialog, USHORT msg,
  345.         MPARAM mp1, MPARAM mp2)
  346. {
  347.     HWND   hwndTextApp;                         // Handle for App Text Window
  348.     HWND   hwndTextKey;
  349.     CHAR   szApp[BUF_SIZE];                     // String Contents
  350.     CHAR   szKey[BUF_SIZE];
  351.  
  352.  
  353.     switch (msg)
  354.         {
  355.         case WM_INITDLG:
  356.             WinSendDlgItemMsg(hwndDialog, IDDI_DEL_KEY_TEXT_APP, EM_SETTEXTLIMIT,
  357.                     MPFROMSHORT(MAX_STRING_LEN), 0L);
  358.             WinSendDlgItemMsg(hwndDialog, IDDI_DEL_KEY_TEXT_KEY, EM_SETTEXTLIMIT,
  359.                     MPFROMSHORT(MAX_STRING_LEN), 0L);
  360.             break;
  361.         case WM_COMMAND:
  362.             switch( LOUSHORT( mp1 ) )
  363.                 {
  364.  
  365.                 case IDDI_DEL_KEY_OK:
  366.                     hwndTextApp = WinWindowFromID( hwndDialog, IDDI_DEL_KEY_TEXT_APP );
  367.                     WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );
  368.  
  369.                     hwndTextKey = WinWindowFromID( hwndDialog, IDDI_DEL_KEY_TEXT_KEY );
  370.                     WinQueryWindowText( hwndTextKey, BUF_SIZE, szKey );
  371.  
  372.  
  373.                     WinDismissDlg( hwndDialog, 0 );
  374.  
  375.                     /* if the App is NULL forget it */
  376.                     if( *szApp == (CHAR)0 )
  377.                         {
  378.                         break;
  379.                         }
  380.  
  381.                     /* if the Key is NULL forget it */
  382.                     if( *szKey == (CHAR)0 )
  383.                         {
  384.                         break;
  385.                         }
  386.  
  387. #ifdef INI11
  388.                     if( !WinWriteProfileString( habIniEdit, szApp, szKey, (PCHAR)NULL ) )
  389.                         ;
  390. #else
  391.                     if( !PrfWriteProfileString( hIniFile, szApp, szKey, (PCHAR)NULL ) )
  392.                         ;
  393. #endif
  394.  
  395.                     break;
  396.  
  397.                 default:
  398.                     return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  399.                     break;
  400.                 }
  401.  
  402.         default:
  403.             return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  404.             break;
  405.         }
  406.  
  407.     return 0L;
  408.  
  409. }  /* DelKeyProc */
  410.  
  411.  
  412. /****************************** Function Header ****************************\
  413. *
  414. * DelAppWndProc
  415. *
  416. *
  417. * Handles the DelApp Dialog Box messages
  418. * Will facilitate deleting all keys from a given app name
  419. *
  420. \***************************************************************************/
  421.  
  422. MRESULT _loadds EXPENTRY DelAppWndProc(HWND hwndDialog, USHORT msg,
  423.         MPARAM mp1, MPARAM mp2)
  424. {
  425.     HWND   hwndTextApp;                         // App Name Window
  426.     CHAR   szApp[BUF_SIZE];                     // String Contents of Window
  427.  
  428.  
  429.     switch (msg)
  430.         {
  431.         case WM_INITDLG:
  432.             WinSendDlgItemMsg(hwndDialog, IDDI_DEL_APP_TEXT_APP, EM_SETTEXTLIMIT,
  433.                     MPFROMSHORT(MAX_STRING_LEN), 0L);
  434.             break;
  435.  
  436.         case WM_COMMAND:
  437.             switch( LOUSHORT( mp1 ) )
  438.                 {
  439.  
  440.                 case IDDI_DEL_APP_OK:
  441.                     hwndTextApp = WinWindowFromID( hwndDialog, IDDI_DEL_APP_TEXT_APP );
  442.                     WinQueryWindowText( hwndTextApp, BUF_SIZE, szApp );
  443.  
  444.                     WinDismissDlg( hwndDialog, 0 );
  445.  
  446.                     /* if the App is NULL forget it */
  447.                     if( *szApp == (CHAR)0 )
  448.                         {
  449.                         break;
  450.                         }
  451.  
  452. #ifdef INI11
  453.                     if( !WinWriteProfileString( habIniEdit, szApp, (PCHAR)NULL, (PCHAR)NULL ) )
  454.                         ;
  455. #else
  456.                     if( !PrfWriteProfileString( hIniFile, szApp, (PCHAR)NULL, (PCHAR)NULL ) )
  457.                         ;
  458. #endif
  459.  
  460.                     break;
  461.  
  462.                 default:
  463.                     return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  464.                     break;
  465.                 }
  466.  
  467.         default:
  468.             return WinDefDlgProc(hwndDialog, msg, mp1, mp2);
  469.             break;
  470.         }
  471.  
  472.     return 0L;
  473.  
  474. }  /* DelAppWndProc */
  475. 
  476.