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