home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12520.ZIP / PRESPARM.C < prev    next >
C/C++ Source or Header  |  1990-01-16  |  10KB  |  337 lines

  1. /*----------------------------------------------------------------------------------
  2.    PresParm.C -- A Program that Demonstrates Combo Boxes and Presentation Parameters
  3.   ---------------------------------------------------------------------------------*/
  4.  
  5. #define INCL_WIN
  6. #include <os2.h>
  7. #include "PresParm.h"
  8. #include <stdlib.h>
  9.  
  10. #define RGB(r,g,b) (((ULONG) ((ULONG)(r) << 8 | (ULONG)(g)) << 8) | (ULONG)(b))
  11.  
  12. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  13. MRESULT EXPENTRY GetPresParamsDlgProc (HWND, USHORT, MPARAM, MPARAM) ;
  14. MRESULT EXPENTRY AboutboxDlgProc (HWND, USHORT, MPARAM, MPARAM) ;
  15.  
  16. MRESULT EXPENTRY GetPresParamsDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  17.      {
  18.  
  19.      /* Handle to List Box which is being updated */
  20.      static HWND   hwndListBox ;
  21.  
  22.      /* used for indexing */
  23.         int i ;
  24.  
  25.      /* temporary storage variables  */
  26.  
  27.         USHORT  usTempRed, usTempGreen, usTempBlue, usTempListIndex;
  28.         char szTempTitle [25] ;
  29.  
  30.      /* Used for storing values between changes */
  31.  
  32.      static ULONG TempPresParam[3] ;
  33.  
  34.      /* static variables to save variable values  */
  35.  
  36.      static USHORT  usRed = 0, usGreen = 0, usBlue = 0, usListIndex = 0 ;
  37.      static char szTitle [25] = "Sample Title:";
  38.         LONG   clr;
  39.  
  40.      static ULONG idPresParam[3] = {PP_FOREGROUNDCOLOR,
  41.                     PP_BACKGROUNDCOLOR,
  42.                     PP_HILITEBACKGROUNDCOLOR} ;
  43.  
  44.      static ULONG PresParam[3] = {RGB(0,0,0),
  45.                   RGB(255,255,255),
  46.                   RGB(0,0,0)} ;
  47.  
  48.      switch (msg)
  49.       {
  50.  
  51.       case WM_INITDLG:
  52.  
  53.        /* Initialize static text string */
  54.  
  55.            WinSetDlgItemText (hwnd, DID_TITLE, szTitle) ;
  56.  
  57.       /* Initialize drop down combo box */
  58.  
  59.            WinSetDlgItemText (hwnd, DID_EDITLIST, szTitle) ;
  60.  
  61.            WinSendDlgItemMsg (hwnd, DID_EDITLIST, LM_INSERTITEM,
  62.                   MPFROMSHORT ((SHORT) LIT_END),
  63.                   MPFROMP ((PSZ) "Demo Strings:")) ;
  64.            WinSendDlgItemMsg (hwnd, DID_EDITLIST, LM_INSERTITEM,
  65.                   MPFROMSHORT ((SHORT) LIT_END),
  66.                   MPFROMP ((PSZ) "Test Strings:")) ;
  67.            WinSendDlgItemMsg (hwnd, DID_EDITLIST, LM_INSERTITEM,
  68.                   MPFROMSHORT ((SHORT) LIT_END),
  69.                   MPFROMP ((PSZ) "List Strings:")) ;
  70.  
  71.       /* Initialize drop down list box */
  72.  
  73.            WinSendDlgItemMsg (hwnd, DID_LISTCOMBO, LM_INSERTITEM,
  74.                   MPFROMSHORT ((SHORT) LIT_END),
  75.                   MPFROMP ((PSZ) "List Box Text")) ;
  76.            WinSendDlgItemMsg (hwnd, DID_LISTCOMBO, LM_INSERTITEM,
  77.                   MPFROMSHORT ((SHORT) LIT_END),
  78.                   MPFROMP ((PSZ) "Background")) ;
  79.            WinSendDlgItemMsg (hwnd, DID_LISTCOMBO, LM_INSERTITEM,
  80.                   MPFROMSHORT ((SHORT) LIT_END),
  81.                   MPFROMP ((PSZ) "Selection")) ;
  82.            WinSendDlgItemMsg (hwnd, DID_LISTCOMBO,
  83.                   LM_SELECTITEM,
  84.                   MPFROMSHORT ((SHORT) usListIndex),
  85.                   MPFROMSHORT ((SHORT) TRUE) ) ;
  86.  
  87.       /* Initialize Sample Strings */
  88.  
  89.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  90.                   MPFROMSHORT ((SHORT) LIT_END),
  91.                   MPFROMP ((PSZ) "String 1")) ;
  92.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  93.                   MPFROMSHORT ((SHORT) LIT_END),
  94.                   MPFROMP ((PSZ) "String 2")) ;
  95.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  96.                   MPFROMSHORT ((SHORT) LIT_END),
  97.                   MPFROMP ((PSZ) "String 3")) ;
  98.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  99.                   MPFROMSHORT ((SHORT) LIT_END),
  100.                   MPFROMP ((PSZ) "String 4")) ;
  101.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  102.                   MPFROMSHORT ((SHORT) LIT_END),
  103.                   MPFROMP ((PSZ) "String 5")) ;
  104.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  105.                   MPFROMSHORT ((SHORT) LIT_END),
  106.                   MPFROMP ((PSZ) "String 6")) ;
  107.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  108.                   MPFROMSHORT ((SHORT) LIT_END),
  109.                   MPFROMP ((PSZ) "String 7")) ;
  110.            WinSendDlgItemMsg (hwnd, DID_LIST, LM_INSERTITEM,
  111.                   MPFROMSHORT ((SHORT) LIT_END),
  112.                   MPFROMP ((PSZ) "String 8")) ;
  113.  
  114.      /* Initialize Edit Fields */
  115.  
  116.            WinSetDlgItemShort (hwnd, DID_RED, usRed, FALSE) ;
  117.            WinSetDlgItemShort (hwnd, DID_GREEN, usGreen, FALSE) ;
  118.            WinSetDlgItemShort (hwnd, DID_BLUE, usBlue, FALSE) ;
  119.  
  120.      /*    Set Presentation Parameters on list box with Id of DID_LIST   */
  121.  
  122.            hwndListBox = WinWindowFromID (hwnd, DID_LIST) ;
  123.  
  124.            for (i = 0 ; i <3 ; i++ )
  125.            WinSetPresParam (hwndListBox,
  126.                    idPresParam[i],
  127.                    (LONG) sizeof (LONG),
  128.                    (PVOID) &PresParam[i]) ;
  129.  
  130.       /* Update temporary storage */
  131.  
  132.            for (i = 0 ; i <3 ; i++ )
  133.            TempPresParam[i] = PresParam[i] ;
  134.  
  135.            return 0 ;
  136.  
  137.  
  138.       case WM_COMMAND:
  139.            switch (COMMANDMSG(&msg)->cmd)
  140.             {
  141.             case DID_UPDATE:
  142.  
  143.             /* Update Display Text */
  144.  
  145.              WinQueryDlgItemText (hwnd, DID_EDITLIST, 25, szTempTitle) ;
  146.              WinSetDlgItemText (hwnd, DID_TITLE, szTempTitle) ;
  147.  
  148.             /* Get new color value */
  149.  
  150.              WinQueryDlgItemShort (hwnd, DID_RED, &usTempRed, FALSE) ;
  151.              WinQueryDlgItemShort (hwnd, DID_GREEN, &usTempGreen, FALSE) ;
  152.              WinQueryDlgItemShort (hwnd, DID_BLUE, &usTempBlue, FALSE) ;
  153.  
  154.              clr = RGB (usTempRed, usTempGreen, usTempBlue) ;
  155.  
  156.             /* Query type of PresParam to change */
  157.  
  158.              usTempListIndex = (USHORT) WinSendDlgItemMsg (hwnd, DID_LISTCOMBO,
  159.                                LM_QUERYSELECTION,
  160.                                MPFROMSHORT ((SHORT) LIT_FIRST), 0L) ;
  161.  
  162.             /* Update PresParams */
  163.  
  164.              WinSetPresParam (hwndListBox,
  165.                        idPresParam[usTempListIndex],
  166.                        (LONG) sizeof (LONG),
  167.                        (PVOID) &clr ) ;
  168.  
  169.             /* Save value between Update messages */
  170.  
  171.              TempPresParam[usTempListIndex] = clr ;
  172.  
  173.             /* Return to the system */
  174.  
  175.              return 0 ;
  176.  
  177.             case DID_OK:
  178.  
  179.             /* Make final display and variable updates */
  180.  
  181.              WinQueryDlgItemText (hwnd, DID_EDITLIST, 25, szTitle) ;
  182.              WinSetDlgItemText (hwnd, DID_TITLE, szTitle) ;
  183.  
  184.  
  185.              WinQueryDlgItemShort (hwnd, DID_RED, &usRed, FALSE) ;
  186.              WinQueryDlgItemShort (hwnd, DID_GREEN, &usGreen, FALSE) ;
  187.              WinQueryDlgItemShort (hwnd, DID_BLUE, &usBlue, FALSE) ;
  188.  
  189.  
  190.              usListIndex = (USHORT) WinSendDlgItemMsg (hwnd, DID_LISTCOMBO,
  191.                               LM_QUERYSELECTION,
  192.                               MPFROMSHORT ((SHORT) LIT_FIRST), 0L) ;
  193.  
  194.              clr = RGB (usRed, usGreen, usBlue) ;
  195.  
  196.              WinSetPresParam (hwndListBox,
  197.                        idPresParam[usListIndex],
  198.                        (LONG) sizeof (LONG),
  199.                        (PVOID) &clr ) ;
  200.  
  201.              TempPresParam[usListIndex] = clr ;
  202.  
  203.              for (i = 0 ; i <3 ; i++ )
  204.                  PresParam[i] = TempPresParam[i] ;
  205.  
  206.              WinDismissDlg (hwnd, TRUE) ;
  207.              return 0 ;
  208.  
  209.             case DID_CANCEL:
  210.  
  211.              WinDismissDlg (hwnd, FALSE) ;
  212.              return 0 ;
  213.             }
  214.            break ;
  215.           }
  216.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  217.      }
  218.  
  219.  
  220.  
  221. MRESULT EXPENTRY AboutboxDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  222.      {
  223.  
  224.      switch (msg)
  225.       {
  226.  
  227.       case WM_INITDLG:
  228.  
  229.            return 0 ;
  230.  
  231.  
  232.       case WM_COMMAND:
  233.            switch (COMMANDMSG(&msg)->cmd)
  234.             {
  235.  
  236.             case DID_OK:
  237.  
  238.              WinDismissDlg (hwnd, FALSE) ;
  239.              return 0 ;
  240.             }
  241.            break ;
  242.           }
  243.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  244.      }
  245.  
  246.  
  247. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  248.      {
  249.      HPS hps ;
  250.      RECTL rcl ;
  251.  
  252.      switch (msg)
  253.       {
  254.  
  255.           case WM_COMMAND:
  256.                switch (COMMANDMSG(&msg)->cmd)
  257.                     {
  258.             case IDM_PLAY:
  259.              WinDlgBox (HWND_DESKTOP, hwnd, GetPresParamsDlgProc,
  260.                     NULL, ID_RESOURCE, NULL) ;
  261.              return 0 ;
  262.  
  263.             case IDM_ABOUT:
  264.              WinDlgBox (HWND_DESKTOP, hwnd, AboutboxDlgProc,
  265.                     NULL, ID_ABOUT, NULL) ;
  266.  
  267.              return 0 ;
  268.  
  269.  
  270.             case IDM_QUIT:
  271.              WinSendMsg (hwnd, WM_CLOSE, 0L, 0L) ;
  272.              return 0 ;
  273.  
  274.             }
  275.            break ;
  276.  
  277.       case WM_PAINT:
  278.            hps = WinBeginPaint (hwnd, NULL, &rcl) ;
  279.            WinFillRect (hps, &rcl , CLR_WHITE) ;
  280.            WinEndPaint (hps) ;
  281.            return 0 ;
  282.  
  283.           }
  284.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  285.      }
  286.  
  287.  
  288.  
  289.  
  290.  
  291. int main (void)
  292.      {
  293.      static CHAR  szClientClass [] = "PresParm" ;
  294.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  295.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  296.                  FCF_SHELLPOSITION | FCF_TASKLIST |
  297.                  FCF_MENU ;
  298.  
  299.        HAB        hab ;
  300.        HMQ        hmq ;
  301.        HWND        hwndClient, hwndFrame ;
  302.        QMSG        qmsg ;
  303.  
  304.      hab = WinInitialize (0) ;
  305.      hmq = WinCreateMsgQueue (hab, 0) ;
  306.  
  307.      WinRegisterClass (
  308.                     hab,                // Anchor block handle
  309.                     szClientClass,      // Name of class being registered
  310.                     ClientWndProc,      // Window procedure for class
  311.                     CS_SIZEREDRAW,      // Class style
  312.                     0) ;                // Extra bytes to reserve
  313.  
  314.      hwndFrame = WinCreateStdWindow (
  315.                     HWND_DESKTOP,       // Parent window handle
  316.                     WS_VISIBLE,         // Style of frame window
  317.                     &flFrameFlags,      // Pointer to control data
  318.                     szClientClass,      // Client window class name
  319.                     NULL,               // Title bar text
  320.                     0L,                 // Style of client window
  321.                     NULL,               // Module handle for resources
  322.             ID_RESOURCE,    // ID of resources
  323.                     &hwndClient) ;      // Pointer to client window handle
  324.  
  325.      WinSendMsg (hwndFrame, WM_SETICON,
  326.                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
  327.                  NULL) ;
  328.  
  329.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  330.           WinDispatchMsg (hab, &qmsg) ;
  331.  
  332.      WinDestroyWindow (hwndFrame) ;
  333.      WinDestroyMsgQueue (hmq) ;
  334.      WinTerminate (hab) ;
  335.      return 0 ;
  336.      }
  337.