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