home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / SETOPT.ZIP / SETOPT.C < prev    next >
Text File  |  1991-06-04  |  53KB  |  1,031 lines

  1. /*
  2.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3.  *   Author: Larry B. Finkelstein                              *
  4.  *   (C) Copyright 1991.                                       *
  5.  *   Creative Systems Programming Corporation.                 *
  6.  *   All Rights Reserved.                                      *
  7.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  8.  *                                                             *
  9.  * This program provides an example of how to set the color    *
  10.  * and font for a Multi-Line Entry (MLE) control.              *
  11.  *                                                             *
  12.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  13. */
  14. #define EXTERN
  15. #include "SETOPT.h"
  16.  
  17. #define DOSASSERT(x) x;
  18.  
  19. SHORT cdecl main(argc, argv)
  20. int argc;
  21. char *argv[];
  22. {
  23.  QMSG qmsg;  /* MSG structure to store your messages                       */
  24.  PID  pid;   /* Process identifier for adding name to switch list          */
  25.  TID  tid;   /* Thread identifier                                          */
  26.  
  27.  /* The WinInitialize routine initializes the Presentation Manager         */
  28.  /* facilities for use by this application and returns a handle to the     */
  29.  /* anchor block assigned to the application by PM.                        */
  30.  
  31.  if((hAB = WinInitialize(0)) == 0)
  32.     return(FALSE);
  33.  
  34.  /* The WinCreateMsgQueue call creates a message queue for this application*/
  35.  
  36.  if((hMQ = WinCreateMsgQueue(hAB, 0)) == 0)
  37.     return(FALSE);
  38.  
  39.  /* The following function registers the classes of all application windows*/
  40.  if(!cwRegisterClass())
  41.     return(FALSE);
  42.  
  43.  /* The CreateWindow function creates a frame window for this application's*/
  44.  /* top window, and set the window's size and location as appropriate.     */
  45.  
  46.  hWndFrame = cwCreateWindow((HWND)HWND_DESKTOP,
  47.           FCF_TITLEBAR     |
  48.           FCF_SYSMENU      |
  49.           FCF_MINBUTTON    |
  50.           FCF_MAXBUTTON    |
  51.           FCF_SIZEBORDER   |
  52.           FCF_MENU         |
  53.           FCF_SHELLPOSITION,
  54.           szAppName,
  55.           "",
  56.           ID_SETOPT,
  57.           0, 0,
  58.           0, 0,
  59.           &hWndClient,
  60.           0L, SWP_SHOW);
  61.  
  62.  if(hWndFrame == 0)
  63.     return(FALSE);
  64.  
  65.  /* The following inline routine fills out the application's switch control*/
  66.  /* structure with the appropriate information to add the application's    */
  67.  /* name to the OS/2 Task Manager List, a list of the jobs currently       */
  68.  /* running on the computer.                                               */
  69.  
  70.  WinQueryWindowProcess(hWndFrame, &pid, &tid);
  71.  Swctl.hwnd = hWndFrame;                         /* Frame window handle    */
  72.  Swctl.idProcess = pid;                          /* Process identifier     */
  73.  Swctl.uchVisibility = SWL_VISIBLE;              /* visibility             */
  74.  Swctl.fbJump = SWL_JUMPABLE;                    /* Jump indicator         */
  75.  strcpy(Swctl.szSwtitle, "SETOPT.EXE");          /* Program name           */
  76.  hSwitch = WinAddSwitchEntry(&Swctl);
  77.  
  78.  /* The following is the message loop for the application.                 */
  79.  
  80.  while(WinGetMsg(hAB, (PQMSG)&qmsg, 0, 0, 0))
  81.        WinDispatchMsg(hAB,(PQMSG)&qmsg);
  82.  
  83.  /* Perform clean up before exiting application.                           */
  84.  /* The following routine destroys the application's frame window (which   */
  85.  /* also destroys its child windows), destroys its message queue, and      */
  86.  /* disassociates the application from the Presentation Manager system.    */
  87.  
  88.  WinDestroyWindow(hWndFrame); /* Destroy the frame window                  */
  89.  WinDestroyMsgQueue(hMQ);     /* Destroy this application's message queue  */
  90.  WinTerminate(hAB);           /* Terminate this application's use of the   */
  91.                               /* Presentation Manager resources            */
  92. } /* end of main */
  93.  
  94. /***************************************************************************/
  95. /*                                                                         */
  96. /* Main Window Procedure                                                   */
  97. /*                                                                         */
  98. /* This procedure provides service routines for the general PM events      */
  99. /* (messages) that PM sends to the window, as well as the user             */
  100. /* initiated events (messages) that are generated when the user selects    */
  101. /* the action bar and pulldown menu controls or the corresponding          */
  102. /* keyboard accelerators.                                                  */
  103. /*                                                                         */
  104. /***************************************************************************/
  105.  
  106. MRESULT EXPENTRY WndProc(hWnd, message, mp1, mp2)
  107. HWND hWnd;
  108. USHORT message;
  109. MPARAM mp1;
  110. MPARAM mp2;
  111. {                        /* Beginning of message processor                 */
  112.    HPS hPS;              /* Handle for the Presentation Space              */
  113.    RECTL rClient;        /* Handle to rectangle formed by client area      */
  114.    USHORT rc;            /* common return code value                       */
  115.  
  116.    switch(message)
  117.      {
  118.       case WM_COMMAND:
  119.         /* The PM messages for action bar and pulldown menu items are      */
  120.         /* processed in this routine.                                      */
  121.  
  122.            switch(SHORT1FROMMP(mp1))
  123.             {
  124.              case IDM_O_SETFONT:
  125.                   /* This makes a call to the dialog box named             */
  126.                   /* "SETFONT" rc will receive the return code             */
  127.                   /* sent when the dialog box is closed                    */
  128.                   rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)SETFONTMsgProc,
  129.                                  0, IDLG_SETFONT, (PBYTE)hWnd);
  130.                   break;
  131.  
  132.              case IDM_O_SETCOLOR:
  133.                   /* This makes a call to the dialog box named             */
  134.                   /* "SETCOLOR" rc will receive the return code            */
  135.                   /* sent when the dialog box is closed                    */
  136.                   rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)SETCOLORMsgProc,
  137.                                  0, IDLG_SETCOLOR, (PBYTE)hWnd);
  138.                   break;
  139.  
  140.  
  141.  
  142.              default:
  143.                   break; /* End of default case for switch(mp1) */
  144.             }
  145.            break; /* End of WM_COMMAND */
  146.  
  147.  
  148.       case WM_CREATE:
  149.            break; /* End of WM_CREATE */
  150.  
  151.       case WM_MOUSEMOVE:
  152.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  153.            break;
  154.  
  155.       case WM_SIZE:     /* code for sizing client area                     */
  156.            break;       /* End of WM_SIZE                                  */
  157.  
  158.       case WM_PAINT:    /* code for the window's client area               */
  159.            /* Obtain a handle to a cache presentation space                */
  160.            hPS = WinBeginPaint(hWnd, 0, 0);
  161.  
  162.            /* Determine the size of the client area                        */
  163.            WinQueryWindowRect(hWnd, &rClient);
  164.  
  165.            /* Fill the background with the default background color        */
  166.            WinFillRect(hPS, &rClient, CLR_BACKGROUND);
  167.  
  168.            /* return presentation space to state before WinBeginPaint      */
  169.            WinEndPaint(hPS);
  170.            break; /* End of WM_PAINT */
  171.  
  172.  
  173.       case WM_CLOSE:  /* close the window                                  */
  174. //           if(hWnd != hWndClient)
  175. //             break;
  176.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  177.            break; /* End of WM_CLOSE */
  178.  
  179.       default:
  180.            /* For any message for which you don't specifically provide a   */
  181.            /* service routine, you should return the message to PM using   */
  182.            /* the WinDefWindowProc function.                               */
  183.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  184.            break;  /* End of default */
  185.      }
  186.    return(0L);
  187. } /* End of WndProc */
  188.  
  189. /***************************************************************************/
  190. /*                                                                         */
  191. /* Dialog Window Procedure                                                 */
  192. /*                                                                         */
  193. /* This procedure is associated with the dialog box that is included in    */
  194. /* the function name of the procedure. It provides the service routines    */
  195. /* for the events (messages) that occur because the end user operates      */
  196. /* one of the dialog box's buttons, entry fields, or controls.             */
  197. /*                                                                         */
  198. /***************************************************************************/
  199.  
  200. MRESULT EXPENTRY SETFONTMsgProc(hWndDlg, message, mp1, mp2)
  201. HWND hWndDlg;
  202. USHORT message;
  203. MPARAM mp1;
  204. MPARAM mp2;
  205. {
  206.  static SHORT sfValidate = TRUE;
  207.  SHORT  i, j ;
  208.  static HWND  hWndParent;
  209.  
  210.    typedef struct _SETFONTS {
  211.       LONG         lNumberFonts ;
  212.       SHORT        sDfltSize ;
  213.       SHORT        sDfltPoints ;
  214.       SHORT        sDfltHeight ;
  215.       FATTRS       fatDefault;
  216.       PFONTMETRICS pFontMetrics ;
  217.    } SETFONTS;
  218.    typedef SETFONTS FAR *PSETFONTS ;
  219.  
  220.    HPS          hPS ;
  221.    LONG         lNumberFonts, lNoFontsReq = 0L ;
  222.    USHORT       usAllocSize, usMaxLB ;
  223.    SHORT        sLBPos ;
  224.    SEL          selFonts ;
  225.    CHAR         szFont[257];
  226.    HWND         hWnd ;
  227.    CHAR         szDfltFont[FACESIZE];
  228.    PFONTMETRICS pFontMetrics ;
  229.    PSETFONTS    pSetFonts ;
  230.    MRESULT      rc ;
  231.    static SHORT sOutlineFonts[10] = { 6,8,10,12,14,18,24,30,36,48 } ;
  232.    SHORT        sPointSize ;
  233.    BOOL         fScanning ;
  234.    BOOL         fSeries ;
  235.  
  236.    hWnd = hWndDlg ;
  237.    pSetFonts = (PSETFONTS)WinQueryWindowULong( hWndDlg, QWL_USER ) ;
  238.  switch(message)
  239.    {
  240.     case WM_INITDLG:
  241.          hWndParent = (HWND)mp2;
  242.          hPS = WinGetPS( hWndDlg ) ;
  243.          lNumberFonts = GpiQueryFonts( hPS, QF_PUBLIC | QF_PRIVATE, NULL,
  244.                                        &lNoFontsReq, 0L, (PFONTMETRICS)NULL ) ;
  245.          usAllocSize = ((USHORT)sizeof(FONTMETRICS) * (USHORT)lNumberFonts)+sizeof(SETFONTS) ;
  246.          DOSASSERT( DosAllocSeg( usAllocSize, &selFonts, 0 ) ) ;
  247.          pSetFonts = MAKEP( selFonts, 0 ) ;
  248.          WinSetWindowULong( hWndDlg, QWL_USER, (ULONG)pSetFonts ) ;
  249.  
  250.          pSetFonts->fatDefault.usRecordLength=sizeof(FATTRS) ;
  251.          WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_QUERYFONT, &(pSetFonts->fatDefault), 0L ) ;
  252. //         WinSendMsg( (HWND)0x1f677c20 , MLM_QUERYFONT, &(pSetFonts->fatDefault), 0L ) ;
  253.          pSetFonts->pFontMetrics = MAKEP( selFonts, sizeof(SETFONTS) ) ;
  254.          GpiQueryFonts( hPS, QF_PUBLIC | QF_PRIVATE, NULL, &lNumberFonts,
  255.                         (LONG)sizeof(FONTMETRICS), pSetFonts->pFontMetrics ) ;
  256.          pSetFonts->lNumberFonts = lNumberFonts ;
  257.          for ( i=0 ; i<(USHORT)lNumberFonts ; i++ )
  258.          {
  259.             pFontMetrics = MAKEP( selFonts, (i*sizeof(FONTMETRICS))+sizeof(SETFONTS) ) ;
  260.             strcpy( szFont, pFontMetrics->szFacename ) ;
  261.             if ( !(pFontMetrics->fsDefn & FM_DEFN_OUTLINE) )
  262.             {
  263.                if ( strcmp( szFont, "Courier" ) == 0 ||
  264.                     strcmp( szFont, "Helv"    ) == 0 ||
  265.                     strcmp( szFont, "Tms Rmn" ) == 0 )
  266.                {
  267.                   strcat( szFont, " Bitmap" ) ;
  268. //                  strcpy( pFontMetrics->szFacename, szFont ) ;
  269.                } /* endif */
  270.             } /* endif */
  271.             if ( i==0 )
  272.             {
  273.                strcpy( szDfltFont, szFont ) ;
  274.                pSetFonts->sDfltSize = pFontMetrics->sNominalPointSize ;
  275.                pSetFonts->sDfltPoints = pFontMetrics->sNominalPointSize/10 ;
  276.                pSetFonts->sDfltHeight = pFontMetrics->lMaxBaselineExt ;
  277.             }
  278.             else
  279.             {
  280.             } /* endif */
  281.             printf ( "Font: %s,%d Type=%x,Defn=%x,Sel=%x,Height=%ld,Width=%ld,ptr=%p\n",
  282.                       szFont,
  283.                       pFontMetrics->sNominalPointSize/10,
  284.                       pFontMetrics->fsType,
  285.                       pFontMetrics->fsDefn,
  286.                       pFontMetrics->fsSelection,
  287.                       pFontMetrics->lMaxBaselineExt,
  288.                       pFontMetrics->lAveCharWidth,
  289.                       pFontMetrics ) ;
  290.             sLBPos = SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg,
  291.                                                       LB_SETFONT_FONT,
  292.                                                       LM_SEARCHSTRING,
  293.                                                       MPFROM2SHORT( LSS_CASESENSITIVE, LIT_FIRST ),
  294.                                                       (PSZ)szFont ) ) ;
  295.             if ( sLBPos==LIT_NONE )
  296.             {
  297.                sLBPos=SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg,
  298.                                                        LB_SETFONT_FONT,
  299.                                                        LM_INSERTITEM,
  300.                                                        MPFROMSHORT( LIT_SORTASCENDING ),
  301.                                                        szFont ) ) ;
  302.                WinSendDlgItemMsg( hWndDlg,
  303.                                   LB_SETFONT_FONT,
  304.                                   LM_SETITEMHANDLE,
  305.                                   MPFROMSHORT( sLBPos ),
  306.                                   MPFROMP( pFontMetrics ) ) ;
  307.                if ( stricmp( szFont, szDfltFont )==0 )
  308.                {
  309.                   WinSendDlgItemMsg( hWndDlg, LB_SETFONT_SIZE, LM_DELETEALL, 0L, 0L ) ;
  310.                   WinSendDlgItemMsg( hWndDlg,
  311.                                      LB_SETFONT_FONT,
  312.                                      LM_SELECTITEM,
  313.                                      MPFROMSHORT( sLBPos ),
  314.                                      MPFROMSHORT( TRUE ) ) ;
  315.                } /* endif */
  316.             } /* endif */
  317.          } /* endfor */
  318.          sLBPos = SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg,
  319.                                                    LB_SETFONT_FONT,
  320.                                                    LM_SEARCHSTRING,
  321.                                                    MPFROM2SHORT( 0, LIT_FIRST ),
  322.                                                    MPFROMP( szDfltFont ) ) ) ;
  323.          if ( sLBPos != LIT_NONE )
  324.          {
  325.             WinSendDlgItemMsg( hWndDlg,
  326.                                LB_SETFONT_FONT,
  327.                                LM_SETTOPINDEX,
  328.                                MPFROMSHORT( sLBPos ), 0L ) ;
  329.          } /* endif */
  330.          WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_OK ), FALSE ) ;
  331.          WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_APPLY ), FALSE ) ;
  332.          break; /* End of WM_INITDLG */
  333.  
  334.     case WM_CONTROL:
  335.          switch(SHORT1FROMMP(mp1))
  336.            {
  337.             case CK_SETFONT_BOLD: /* Checkbox text: "~Bold"                */
  338.                  {
  339.                   USHORT checked;
  340.  
  341.                   /* Query check box control for current state             */
  342.                   checked = !WinSendDlgItemMsg(hWndDlg, CK_SETFONT_BOLD,
  343.                                                BM_QUERYCHECK, 0L, 0L );
  344.                   if ( !checked )
  345.                      pSetFonts->fatDefault.fsSelection |= FATTR_SEL_BOLD ;
  346.                   else
  347.                      pSetFonts->fatDefault.fsSelection &= 0xffff-FATTR_SEL_BOLD ;
  348.                   WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_SETFONT, &(pSetFonts->fatDefault), 0L ) ;
  349.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_OK ), TRUE ) ;
  350.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_APPLY ), TRUE ) ;
  351.                  }
  352.                  break;
  353.  
  354.             case CK_SETFONT_ITALIC: /* Checkbox text: "~Italic"            */
  355.                  {
  356.                   USHORT checked;
  357.  
  358.                   /* Query check box control for current state             */
  359.                   checked = !WinSendDlgItemMsg(hWndDlg, CK_SETFONT_ITALIC,
  360.                                                BM_QUERYCHECK, 0L, 0L );
  361.                   if ( !checked )
  362.                      pSetFonts->fatDefault.fsSelection |= FATTR_SEL_ITALIC ;
  363.                   else
  364.                      pSetFonts->fatDefault.fsSelection &= 0xffff-FATTR_SEL_ITALIC ;
  365.                   WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_SETFONT, &(pSetFonts->fatDefault), 0L ) ;
  366.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_OK ), TRUE ) ;
  367.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_APPLY ), TRUE ) ;
  368.                  }
  369.                  break;
  370.  
  371.             case CK_SETFONT_UNDERSCORE: /* Checkbox text: "~Underscore"    */
  372.                  {
  373.                   USHORT checked;
  374.  
  375.                   /* Query check box control for current state             */
  376.                   checked = !WinSendDlgItemMsg(hWndDlg, CK_SETFONT_UNDERSCORE,
  377.                                                BM_QUERYCHECK, 0L, 0L );
  378.                   if ( !checked )
  379.                      pSetFonts->fatDefault.fsSelection |= FATTR_SEL_UNDERSCORE ;
  380.                   else
  381.                      pSetFonts->fatDefault.fsSelection &= 0xffff-FATTR_SEL_UNDERSCORE ;
  382.                   WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_SETFONT, &(pSetFonts->fatDefault), 0L ) ;
  383.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_OK ), TRUE ) ;
  384.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_APPLY ), TRUE ) ;
  385.                  }
  386.                  break;
  387.  
  388.             case CK_SETFONT_STRIKEOUT: /* Checkbox text: "Strike~out"      */
  389.                  {
  390.                   USHORT checked;
  391.  
  392.                   /* Query check box control for current state             */
  393.                   checked = !WinSendDlgItemMsg(hWndDlg, CK_SETFONT_STRIKEOUT,
  394.                                                BM_QUERYCHECK, 0L, 0L );
  395.                   if ( !checked )
  396.                      pSetFonts->fatDefault.fsSelection |= FATTR_SEL_STRIKEOUT ;
  397.                   else
  398.                      pSetFonts->fatDefault.fsSelection &= 0xffff-FATTR_SEL_STRIKEOUT ;
  399.                   WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_SETFONT, &(pSetFonts->fatDefault), 0L ) ;
  400.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_OK ), TRUE ) ;
  401.                   WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_APPLY ), TRUE ) ;
  402.                  }
  403.                  break;
  404.  
  405.             case MLE_SETFONT: /* Entry field                               */
  406.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  407.                    {
  408.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  409.                          break;
  410.  
  411.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  412.                          break;
  413.  
  414.                     default: /* Default other messages                     */
  415.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  416.                          break;
  417.                    }
  418.                  break;
  419.  
  420.             case LB_SETFONT_FONT: /* List box                              */
  421.                  {
  422.                     if ( SHORT2FROMMP(mp1)==LN_SELECT )
  423.                     {
  424.                        if ( pSetFonts != NULL )
  425.                        {
  426.                           sLBPos=SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg,
  427.                                                                   LB_SETFONT_FONT,
  428.                                                                   LM_QUERYSELECTION,
  429.                                                                   MPFROMSHORT( LIT_FIRST ), 0L ) ) ;
  430.                           if ( sLBPos != LIT_NONE )
  431.                           {
  432.                              WinSendDlgItemMsg( hWndDlg,
  433.                                                 LB_SETFONT_FONT,
  434.                                                 LM_QUERYITEMTEXT,
  435.                                                 MPFROM2SHORT( sLBPos, sizeof(szDfltFont) ),
  436.                                                 szDfltFont ) ;
  437. //                             pFontMetrics = (PFONTMETRICS)
  438. //                                WinSendDlgItemMsg( hWndDlg,
  439. //                                                   LB_SETFONT_FONT,
  440. //                                                   LM_QUERYITEMHANDLE,
  441. //                                                   MPFROMSHORT( sLBPos ), 0L ) ;
  442.                              WinSendDlgItemMsg( hWndDlg,
  443.                                                 LB_SETFONT_SIZE,
  444.                                                 LM_DELETEALL,
  445.                                                 0L, 0L ) ;
  446.                              fScanning = fSeries = TRUE ;
  447.                              for ( i=0 ; i<(USHORT)pSetFonts->lNumberFonts ; i++ )
  448.                              {
  449.                                 pFontMetrics = MAKEP( SELECTOROF(pSetFonts), (i*sizeof(FONTMETRICS))+sizeof(SETFONTS) ) ;
  450.                                 strcpy( szFont, pFontMetrics->szFacename ) ;
  451.                                 if ( !(pFontMetrics->fsDefn & FM_DEFN_OUTLINE) )
  452.                                 {
  453.                                    if ( strcmp( szFont, "Courier" ) == 0 ||
  454.                                         strcmp( szFont, "Helv"    ) == 0 ||
  455.                                         strcmp( szFont, "Tms Rmn" ) == 0 )
  456.                                    {
  457.                                       strcat( szFont, " Bitmap" ) ;
  458.                                    } /* endif */
  459.                                 } /* endif */
  460.                                 if ( stricmp( szFont, szDfltFont )==0 )
  461.                                 {
  462.                                    for ( j= 0 ; j<10 ; j++ )
  463.                                    {
  464.                                       if ( pFontMetrics->fsDefn & FM_DEFN_OUTLINE )
  465.                                       {
  466.                                          sprintf ( szFont, "%d", sOutlineFonts[j] ) ;
  467.                                          sPointSize = sOutlineFonts[j]*10 ;
  468.                                       }
  469.                                       else
  470.                                       {
  471.                                          sprintf ( szFont, "%d", pFontMetrics->sNominalPointSize/10 ) ;
  472.                                          sPointSize = pFontMetrics->sNominalPointSize ;
  473.                                          j = 10 ;
  474.                                          if ( pSetFonts->sDfltPoints==(sPointSize/10) &&
  475.                                               pSetFonts->sDfltHeight==pFontMetrics->lMaxBaselineExt )
  476.                                          {
  477.                                             fScanning = FALSE ;
  478.                                          } /* endif */
  479.                                       } /* endif */
  480.                                       sLBPos = SHORT1FROMMR(
  481.                                          WinSendDlgItemMsg( hWndDlg,
  482.                                                              LB_SETFONT_SIZE,
  483.                                                              LM_SEARCHSTRING,
  484.                                                              MPFROM2SHORT( LSS_CASESENSITIVE, LIT_FIRST ),
  485.                                                              (PSZ)szFont ) ) ;
  486.                                       if ( sLBPos==LIT_NONE )
  487.                                       {
  488.                                          sLBPos=SHORT1FROMMR(
  489.                                                  WinSendDlgItemMsg( hWndDlg,
  490.                                                                     LB_SETFONT_SIZE,
  491.                                                                     LM_INSERTITEM,
  492.                                                                     MPFROMSHORT( LIT_END ),
  493.                                                                     szFont ) ) ;
  494.                                       } /* endif */
  495.                                       if ( !fScanning )
  496.                                       {
  497.                                          if ( (pSetFonts->sDfltPoints<(sPointSize/10)) && fSeries )
  498.                                          {
  499.                                             fSeries = FALSE ;
  500.                                          } /* endif */
  501.                                       } /* endif */
  502.                                       if ( fScanning || fSeries )
  503.                                       {
  504.                                          WinSendDlgItemMsg( hWndDlg,
  505.                                                             LB_SETFONT_SIZE,
  506.                                                             LM_SETITEMHANDLE,
  507.                                                             MPFROMSHORT( sLBPos ),
  508.                                                             MPFROMP( pFontMetrics ) ) ;
  509.                                          printf ( "Size: %s,%d Type=%x,Defn=%x,Sel=%x,Height=%ld,Width=%ld,ptr=%p,scan=%d\n",
  510.                                                    szDfltFont,
  511.                                                    pFontMetrics->sNominalPointSize/10,
  512.                                                    pFontMetrics->fsType,
  513.                                                    pFontMetrics->fsDefn,
  514.                                                    pFontMetrics->fsSelection,
  515.                                                    pFontMetrics->lMaxBaselineExt,
  516.                                                    pFontMetrics->lAveCharWidth,
  517.                                                    pFontMetrics, fScanning ) ;
  518.                                       }
  519.                                       else
  520.                                       {
  521.                                       } /* endif */
  522.                                    } /* endfor */
  523.                                 } /* endif */
  524.                              } /* endfor */
  525.                              sprintf ( szFont, "%d", pSetFonts->sDfltSize/10 ) ;
  526.                              sLBPos = SHORT1FROMMR(
  527.                                 WinSendDlgItemMsg( hWndDlg,
  528.                                                     LB_SETFONT_SIZE,
  529.                                                     LM_SEARCHSTRING,
  530.                                                     MPFROM2SHORT( LSS_CASESENSITIVE, LIT_FIRST ),
  531.                                                     (PSZ)szFont ) ) ;
  532.                              if ( sLBPos == LIT_NONE )
  533.                              {
  534.                                 WinSendDlgItemMsg( hWndDlg,
  535.                                                    LB_SETFONT_SIZE,
  536.                                                    LM_QUERYITEMTEXT,
  537.                                                    MPFROM2SHORT( 0 , sizeof(szFont) ),
  538.                                                    szFont ) ;
  539.                                 if (pSetFonts->sDfltSize/10 < atoi(szFont) )
  540.                                 {
  541.                                    sLBPos = 0 ;
  542.                                 }
  543.                                 else
  544.                                 {
  545.                                    usMaxLB = SHORT1FROMMR(
  546.                                       WinSendDlgItemMsg( hWndDlg,
  547.                                                           LB_SETFONT_SIZE,
  548.                                                           LM_QUERYITEMCOUNT,
  549.                                                           0L, 0L ) ) ;
  550.                                    WinSendDlgItemMsg( hWndDlg,
  551.                                                       LB_SETFONT_SIZE,
  552.                                                       LM_QUERYITEMTEXT,
  553.                                                       MPFROM2SHORT( usMaxLB, sizeof(szFont) ),
  554.                                                       szFont ) ;
  555.                                    if (pSetFonts->sDfltSize/10 < atoi(szFont) )
  556.                                    {
  557.                                       sLBPos = usMaxLB ;
  558.                                    } /* endif */
  559.                                 } /* endif */
  560.                              } /* endif */
  561.                              if ( sLBPos != LIT_NONE )
  562.                              {
  563.                                 WinSendDlgItemMsg( hWndDlg,
  564.                                                    LB_SETFONT_SIZE,
  565.                                                    LM_SELECTITEM,
  566.                                                    MPFROMSHORT( sLBPos ),
  567.                                                    MPFROMSHORT( TRUE ) ) ;
  568.                                 WinSendDlgItemMsg( hWndDlg,
  569.                                                    LB_SETFONT_SIZE,
  570.                                                    LM_SETTOPINDEX,
  571.                                                    MPFROMSHORT( sLBPos ), 0L ) ;
  572.                              } /* endif */
  573.                           } /* endif */
  574.                        } /* endif */
  575.                        WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_SETFONT, &(pSetFonts->fatDefault), 0L ) ;
  576.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_OK ), TRUE ) ;
  577.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_APPLY ), TRUE ) ;
  578.                     } /* endif */
  579.                  }
  580.                  break;
  581.  
  582.             case LB_SETFONT_SIZE: /* List box                              */
  583.                  {
  584.                     if ( SHORT2FROMMP(mp1)==LN_SELECT )
  585.                     {
  586.                        sLBPos=SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg,
  587.                                                                 LB_SETFONT_SIZE,
  588.                                                                 LM_QUERYSELECTION,
  589.                                                                 MPFROMSHORT( LIT_FIRST ), 0L ) ) ;
  590.                        if ( sLBPos != LIT_NONE )
  591.                        {
  592.                           WinSendDlgItemMsg( hWndDlg,
  593.                                              LB_SETFONT_SIZE,
  594.                                              LM_QUERYITEMTEXT,
  595.                                              MPFROM2SHORT( sLBPos, sizeof(szFont) ),
  596.                                              MPFROMP( szFont ) ) ;
  597.                           pFontMetrics=(PFONTMETRICS)
  598.                                        WinSendDlgItemMsg( hWndDlg,
  599.                                                           LB_SETFONT_SIZE,
  600.                                                           LM_QUERYITEMHANDLE,
  601.                                                           MPFROMSHORT( sLBPos ), 0L ) ;
  602.                           strcpy( pSetFonts->fatDefault.szFacename, pFontMetrics->szFacename ) ;
  603. //                          pSetFonts->fatDefault.fsSelection = pFontMetrics->fsSelection ;
  604. //                          pSetFonts->fatDefault.lMatch = pFontMetrics->lMatch ;
  605.                           pSetFonts->fatDefault.lMatch = 0L ;
  606.                           pSetFonts->fatDefault.idRegistry = pFontMetrics->idRegistry ;
  607.                           pSetFonts->fatDefault.usCodePage = pFontMetrics->usCodePage ;
  608.                           if ( pFontMetrics->fsDefn & FM_DEFN_OUTLINE )
  609.                           {
  610.                              pSetFonts->fatDefault.lMaxBaselineExt = (LONG)sOutlineFonts[sLBPos] *
  611.                                                                      pFontMetrics->lMaxBaselineExt /
  612.                                                                      ( pFontMetrics->sNominalPointSize/10 ) ;
  613.                              pSetFonts->fatDefault.lAveCharWidth = pFontMetrics->lAveCharWidth ;
  614.                              pSetFonts->sDfltSize = sOutlineFonts[sLBPos]*10 ;
  615.                              pSetFonts->fatDefault.fsFontUse = FATTR_FONTUSE_OUTLINE |
  616.                                                                FATTR_FONTUSE_TRANSFORMABLE ;
  617.                           }
  618.                           else
  619.                           {
  620.                              pSetFonts->fatDefault.lMaxBaselineExt = pFontMetrics->lMaxBaselineExt ;
  621.                              pSetFonts->fatDefault.lAveCharWidth = pFontMetrics->lAveCharWidth ;
  622.                              pSetFonts->sDfltSize = pFontMetrics->sNominalPointSize ;
  623.                              pSetFonts->fatDefault.fsFontUse = 0 ;
  624.                           } /* endif */
  625.                           pSetFonts->fatDefault.fsType = 0 /* pFontMetrics->fsType */ ;
  626. //                                                            FATTR_FONTUSE_NOMIX ;
  627.                        } /* endif */
  628.                        rc=WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_SETFONT, &(pSetFonts->fatDefault), 0L ) ;
  629.                        printf ( "SETF: %s,%s pFM=%p Baseline=%ld,%ld AveWidth=%ld,%ld,ptr=%p   RC=%lX\n",
  630.                                 pFontMetrics->szFacename,
  631.                                 szFont,
  632.                                 pFontMetrics,
  633.                                 pFontMetrics->lMaxBaselineExt,
  634.                                 pSetFonts->fatDefault.lMaxBaselineExt,
  635.                                 pFontMetrics->lAveCharWidth,
  636.                                 pSetFonts->fatDefault.lAveCharWidth, pFontMetrics, rc ) ;
  637.                        if ( pFontMetrics->fsDefn & FM_DEFN_OUTLINE )
  638.                        {
  639.                           rc=WinSendDlgItemMsg( hWndDlg, MLE_SETFONT, MLM_SETTABSTOP, MPFROMSHORT(8*sOutlineFonts[sLBPos]), 0L ) ;
  640. //                          printf( "Sett ... rc=%lX\n", rc ) ;
  641.                        } /* endif */
  642.                        if ( !rc )
  643.                        {
  644.                           WinAlarm( HWND_DESKTOP, WA_ERROR ) ;
  645.                           WinMessageBox( HWND_DESKTOP, hWndDlg, "Unable to set new font",
  646.                                          "ReadBBS - Set Font", 0, MB_OK | MB_ICONHAND ) ;
  647.                        } /* endif */
  648.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_OK ), TRUE ) ;
  649.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETFONT_APPLY ), TRUE ) ;
  650.                     } /* endif */
  651.                  }
  652.                  break;
  653.  
  654.            }
  655.          break; /* End of WM_CONTROL */
  656.  
  657.     case WM_COMMAND:
  658.          switch(SHORT1FROMMP(mp1))
  659.            {
  660.             case PB_SETFONT_OK:
  661.             case DID_OK: /* Button text: "OK"                              */
  662.                  DosFreeSeg( SELECTOROF(pSetFonts) ) ;
  663.                  WinDismissDlg(hWndDlg, TRUE);
  664.                  break;
  665.  
  666.             case PB_SETFONT_APPLY: /* Button text: "Apply"                 */
  667.                  break;
  668.  
  669.             case PB_SETFONT_CANCEL:
  670.             case DID_CANCEL: /* Button text: "Cancel"                      */
  671.                  /* Ignore data values entered into the dialog controls    */
  672.                  /* and dismiss the dialog window                          */
  673.                  DosFreeSeg( SELECTOROF(pSetFonts) ) ;
  674.                  WinDismissDlg(hWndDlg, FALSE);
  675.                  break;
  676.  
  677.             case PB_SETFONT_HELP: /* Button text: "Help"                   */
  678.                  break;
  679.  
  680.            }
  681.          break; /* End of WM_COMMAND */
  682.  
  683.     case WM_CLOSE:
  684.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  685.          break; /* End of WM_CLOSE */
  686.  
  687.     case WM_FAILEDVALIDATE:
  688.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  689.          sfValidate = FALSE;
  690.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  691.          sfValidate = TRUE;
  692.          return((MRESULT)TRUE);
  693.          break; /* End of WM_FAILEDVALIDATE */
  694.  
  695.     default:
  696.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  697.          break;
  698.    }
  699.  return FALSE;
  700. } /* End of SETFONTMsgProc */
  701.  
  702.  
  703. /***************************************************************************/
  704. /*                                                                         */
  705. /* Dialog Window Procedure                                                 */
  706. /*                                                                         */
  707. /* This procedure is associated with the dialog box that is included in    */
  708. /* the function name of the procedure. It provides the service routines    */
  709. /* for the events (messages) that occur because the end user operates      */
  710. /* one of the dialog box's buttons, entry fields, or controls.             */
  711. /*                                                                         */
  712. /***************************************************************************/
  713.  
  714. MRESULT EXPENTRY SETCOLORMsgProc(hWndDlg, message, mp1, mp2)
  715. HWND hWndDlg;
  716. USHORT message;
  717. MPARAM mp1;
  718. MPARAM mp2;
  719. {
  720.  static SHORT sfValidate = TRUE;
  721.  INT    i;
  722.  static HWND  hWndParent;
  723.    SHORT sLBPos ;
  724.    LONG lBackColor, lTextColor ;
  725.    IPT  iptStart, iptStop ;
  726.    ULONG ulImport ;
  727.    CHAR szText[] = "\tThis is an example of text.\r\nThis is an example of selected text." ;
  728.    CHAR szColor[16][16] = { "White","Blue ","Red ","Pink ","Green ","Cyan ",
  729.                             "Yellow ", "Black",
  730.                             "Dark Grey ","Dark Blue ","Dark Red ","Dark Pink ",
  731.                             "Dark Green ",
  732.                             "Dark Cyan ","Brown ","Pale Grey " } ;
  733.  
  734.  switch(message)
  735.    {
  736.     case WM_INITDLG:
  737.          hWndParent = (HWND)mp2;
  738.          lBackColor=WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_QUERYBACKCOLOR, 0L, 0L ) ;
  739.          lTextColor=WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_QUERYTEXTCOLOR, 0L, 0L ) ;
  740.          for ( i=CLR_BACKGROUND ; i<=CLR_PALEGRAY ; i++ )
  741.          {
  742.             sLBPos=SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg, LB_SETCOLOR_FOREGROUND,
  743.                                                     LM_INSERTITEM,
  744.                                                     MPFROMSHORT( LIT_SORTASCENDING ),
  745.                                                     szColor[i] ) ) ;
  746.             WinSendDlgItemMsg( hWndDlg, LB_SETCOLOR_FOREGROUND, LM_SETITEMHANDLE,
  747.                                MPFROMSHORT( sLBPos ), MPFROMSHORT( i ) ) ;
  748.             if (i==lTextColor)
  749.             {
  750.                WinSendDlgItemMsg( hWndDlg, LB_SETCOLOR_FOREGROUND,
  751.                                   LM_SELECTITEM, MPFROMSHORT( sLBPos ), MPFROMSHORT( TRUE ) ) ;
  752.             } /* endif */
  753.             sLBPos=SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg, LB_SETCOLOR_BACKGROUND,
  754.                                                     LM_INSERTITEM,
  755.                                                     MPFROMSHORT( LIT_SORTASCENDING ),
  756.                                                     szColor[i] ) ) ;
  757.             WinSendDlgItemMsg( hWndDlg, LB_SETCOLOR_BACKGROUND, LM_SETITEMHANDLE,
  758.                                MPFROMSHORT( sLBPos ), MPFROMSHORT( i ) ) ;
  759.             if (i==lBackColor)
  760.             {
  761.                WinSendDlgItemMsg( hWndDlg, LB_SETCOLOR_BACKGROUND,
  762.                                   LM_SELECTITEM, MPFROMSHORT( sLBPos ), MPFROMSHORT( TRUE ) ) ;
  763.             } /* endif */
  764.          } /* endfor */
  765.          WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_FORMAT, MLFIE_CFTEXT, 0L ) ;
  766.          ulImport = (ULONG)sizeof(szText) ;
  767.          WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_SETIMPORTEXPORT, MPFROMP(szText), &ulImport ) ;
  768.          iptStart = (IPT)-1L ;
  769.          WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_IMPORT, &iptStart, MPFROMSHORT(sizeof(szText)) ) ;
  770.          WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_SETSEL, (IPT)29L, (IPT)MPFROMSHORT(sizeof(szText)) ) ;
  771.          WinSetFocus( HWND_DESKTOP, WinWindowFromID( hWndDlg, MLE_SETCOLOR ) ) ;
  772.          WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETCOLOR_OK ), FALSE ) ;
  773.          WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETCOLOR_APPLY ), FALSE ) ;
  774.          break; /* End of WM_INITDLG */
  775.  
  776.     case WM_CONTROL:
  777.          switch(SHORT1FROMMP(mp1))
  778.            {
  779.             case MLE_SETCOLOR: /* Entry field                              */
  780.                  switch(SHORT2FROMMP(mp1)) /* switch on Notification Code  */
  781.                    {
  782.                     case EN_SETFOCUS:/* Entry field is receiving the focus */
  783.                          break;
  784.  
  785.                     case EN_KILLFOCUS: /* Entry field is losing the focus  */
  786.                          break;
  787.  
  788.                     default: /* Default other messages                     */
  789.                          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  790.                          break;
  791.                    }
  792.                  break;
  793.  
  794.             case LB_SETCOLOR_FOREGROUND: /* List box                       */
  795.                  {
  796.                     if ( SHORT2FROMMR(mp1)==LN_SELECT )
  797.                     {
  798.                        sLBPos=SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg,
  799.                                                                LB_SETCOLOR_FOREGROUND,
  800.                                                                LM_QUERYSELECTION,
  801.                                                                MPFROMSHORT( LIT_FIRST ), 0L ) ) ;
  802.                        if ( sLBPos != LIT_NONE )
  803.                        {
  804.                           lTextColor=LONGFROMMR( WinSendDlgItemMsg( hWndDlg,
  805.                                                                     LB_SETCOLOR_FOREGROUND,
  806.                                                                     LM_QUERYITEMHANDLE,
  807.                                                                     MPFROMSHORT( sLBPos ), 0L ) ) ;
  808.                           WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_SETTEXTCOLOR,
  809.                                              MPFROMLONG( lTextColor ), 0L ) ;
  810.                        } /* endif */
  811.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETCOLOR_OK ), TRUE ) ;
  812.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETCOLOR_APPLY ), TRUE ) ;
  813.                        WinSetFocus( HWND_DESKTOP, WinWindowFromID( hWndDlg, MLE_SETCOLOR ) ) ;
  814.                     } /* endif */
  815.                  }
  816.                  break;
  817.  
  818.             case LB_SETCOLOR_BACKGROUND: /* List box                      */
  819.                  {
  820.                     if ( SHORT2FROMMR(mp1)==LN_SELECT )
  821.                     {
  822.                        sLBPos=SHORT1FROMMR( WinSendDlgItemMsg( hWndDlg,
  823.                                                                LB_SETCOLOR_BACKGROUND,
  824.                                                                LM_QUERYSELECTION,
  825.                                                                MPFROMSHORT( LIT_FIRST ), 0L ) ) ;
  826.                        if ( sLBPos != LIT_NONE )
  827.                        {
  828.                           lBackColor=LONGFROMMR( WinSendDlgItemMsg( hWndDlg,
  829.                                                                     LB_SETCOLOR_BACKGROUND,
  830.                                                                     LM_QUERYITEMHANDLE,
  831.                                                                     MPFROMSHORT( sLBPos ), 0L ) ) ;
  832.                           WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_SETBACKCOLOR,
  833.                                              MPFROMLONG( lBackColor ), 0L ) ;
  834.                        } /* endif */
  835.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETCOLOR_OK ), TRUE ) ;
  836.                        WinEnableWindow( WinWindowFromID( hWndDlg, PB_SETCOLOR_APPLY ), TRUE ) ;
  837.                        WinSetFocus( HWND_DESKTOP, WinWindowFromID( hWndDlg, MLE_SETCOLOR ) ) ;
  838.                     } /* endif */
  839.                  }
  840.                  break;
  841.  
  842.            }
  843.          break; /* End of WM_CONTROL */
  844.  
  845.     case WM_COMMAND:
  846.          switch(SHORT1FROMMP(mp1))
  847.            {
  848.             case PB_SETCOLOR_OK:
  849.             case DID_OK: /* Button text: "OK"                              */
  850.                  lBackColor=WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_QUERYBACKCOLOR, 0L, 0L ) ;
  851.                  lTextColor=WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_QUERYTEXTCOLOR, 0L, 0L ) ;
  852. //                 WinSendMsg( pMleData->hWndReadMLE, MLM_SETTEXTCOLOR, MPFROMLONG( lTextColor ), 0L ) ;
  853. //                 WinSendMsg( pMleData->hWndReadMLE, MLM_SETBACKCOLOR, MPFROMLONG( lBackColor ), 0L ) ;
  854.                  WinDismissDlg(hWndDlg, TRUE);
  855.                  break;
  856.  
  857.             case PB_SETCOLOR_APPLY: /* Button text: "Apply"                */
  858.                  lBackColor=WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_QUERYBACKCOLOR, 0L, 0L ) ;
  859.                  lTextColor=WinSendDlgItemMsg( hWndDlg, MLE_SETCOLOR, MLM_QUERYTEXTCOLOR, 0L, 0L ) ;
  860. //                 WinSendMsg( pMleData->hWndReadMLE, MLM_SETTEXTCOLOR, MPFROMLONG( lTextColor ), 0L ) ;
  861. //                 WinSendMsg( pMleData->hWndReadMLE, MLM_SETBACKCOLOR, MPFROMLONG( lBackColor ), 0L ) ;
  862.                  WinSetFocus( HWND_DESKTOP, WinWindowFromID( hWndDlg, MLE_SETCOLOR ) ) ;
  863.                  break;
  864.  
  865.             case PB_SETCOLOR_CANCEL:
  866.             case DID_CANCEL: /* Button text: "Cancel"                      */
  867.                  /* Ignore data values entered into the dialog controls    */
  868.                  /* and dismiss the dialog window                          */
  869.                  WinDismissDlg(hWndDlg, FALSE);
  870.                  break;
  871.  
  872.             case PB_SETCOLOR_HELP: /* Button text: "Help"                  */
  873.                  WinSetFocus( HWND_DESKTOP, WinWindowFromID( hWndDlg, MLE_SETCOLOR ) ) ;
  874.                  break;
  875.  
  876.            }
  877.          break; /* End of WM_COMMAND */
  878.  
  879.     case WM_CLOSE:
  880.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  881.          break; /* End of WM_CLOSE */
  882.  
  883.     case WM_FAILEDVALIDATE:
  884.          WinAlarm(HWND_DESKTOP, WA_ERROR);
  885.          sfValidate = FALSE;
  886.          WinSetFocus(HWND_DESKTOP, WinWindowFromID(hWndDlg, SHORT1FROMMP(mp1)));
  887.          sfValidate = TRUE;
  888.          return((MRESULT)TRUE);
  889.          break; /* End of WM_FAILEDVALIDATE */
  890.  
  891.     default:
  892.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  893.          break;
  894.    }
  895.  return FALSE;
  896. } /* End of SETCOLORMsgProc */
  897.  
  898.  
  899.  
  900.  
  901. /***************************************************************************/
  902. /*                                                                         */
  903. /* cwRegisterClass Function                                                */
  904. /*                                                                         */
  905. /* The following function registers all the classes of all the windows     */
  906. /* associated with this application. The function returns TRUE if it is    */
  907. /* successful, otherwise it returns FALSE.                                 */
  908. /*                                                                         */
  909. /***************************************************************************/
  910.  
  911. INT cwRegisterClass()
  912. {
  913.  INT rc;
  914.  
  915.  strcpy(szAppName, "SETOPT");
  916.  rc = WinRegisterClass(hAB,             /* Anchor block handle             */
  917.                       (PCH)szAppName,   /* Name of class being registered  */
  918.                       (PFNWP)WndProc,   /* Window procedure for class      */
  919.                       CS_SIZEREDRAW ,
  920.                       0);            /* Extra bytes to reserve             */
  921.  if (rc == FALSE)
  922.    return(FALSE);
  923.  
  924.  return(TRUE);
  925. } /* End of cwRegisterClass */
  926.  
  927.  
  928.  
  929. /***************************************************************************/
  930. /*                                                                         */
  931. /* cwCreateWindow Function                                                 */
  932. /*                                                                         */
  933. /* The following function is used to create a window (the main window,     */
  934. /* a child window, an icon window, etc.) and set it's initial size and     */
  935. /* position. It returns the handle to the frame window.                    */
  936. /*                                                                         */
  937. /***************************************************************************/
  938.  
  939. HWND cwCreateWindow(
  940.    HWND   hWndParent,  /* Handle to the parent of the window to be created */
  941.    ULONG  ctldata,     /* Frame control flags for the window               */
  942.    PCH    appname,     /* Class name of the window                         */
  943.    PCH    title,       /* Title of the window                              */
  944.    USHORT ResID,       /* Resource id value                                */
  945.    INT    x,           /* Initial horizontal and vertical location         */
  946.    INT    y,
  947.    INT    cx,          /* Initial width and height of the window           */
  948.    INT    cy,
  949.    PHWND  hWndClient,  /* Handle to the client area of the window          */
  950.    ULONG  lfStyle,     /* Frame window style                               */
  951.    USHORT uSizeStyle)  /* User defined size and location flags             */
  952. {
  953.    USHORT rc;            /* accepts return codes from function calls       */
  954.    HWND   hWndFrame;     /* local handle to created window frame           */
  955.    USHORT SizeStyle;     /* local window positioning options               */
  956.    CHAR   MsgBuffer[80]; /* buffer for error messages                      */
  957.    HPS    hPS;           /* handle to a presentation space                 */
  958.    int    xmod, ymod;    /* modifiers for sizing                           */
  959.    #define DLGXMOD  4    /* Dialog units X modulo */
  960.    #define DLGYMOD  8    /* Dialog units Y modulo */
  961.    FONTMETRICS fm;       /* structure for determing modifiers              */
  962.    /* Create the frame window                                              */
  963.    hWndFrame = WinCreateStdWindow(hWndParent,  /* parent of window         */
  964.                                   lfStyle,     /* frame window style       */
  965.                                   &ctldata,    /* frame flags              */
  966.                                   appname,     /* class name               */
  967.                                   title,       /* window title             */
  968.                                   0L,          /* client window style      */
  969.                                   0,           /* module for resources     */
  970.                                   ResID,       /* resource id              */
  971.                                   (HWND FAR *)hWndClient); /* client handle*/
  972.  
  973.    /* if hWndFrame is NULL, an error occured when opening the window,      */
  974.    /*     notify the user and exit this function                           */
  975.    if(hWndFrame == 0)
  976.      {
  977.       WinLoadString(hAB, 0, IDS_ERR_WINDOW_CREATE, 80, MsgBuffer);
  978.       WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  979.                     0, 0, MB_OK|MB_ICONEXCLAMATION);
  980.       return((HWND)0);
  981.      }
  982.  
  983.    /* set up size options                                                  */
  984.    SizeStyle = SWP_ACTIVATE | SWP_ZORDER | uSizeStyle;
  985.  
  986.    /* if the height, width, intial x or initial y values are non-zero,     */
  987.    /*     then we will need to set up the modifiers for size and location  */
  988.    if((cx > 0) || (cy > 0) ||
  989.       (x > 0)  || (y > 0))
  990.      {
  991.       hPS = WinGetPS(HWND_DESKTOP);
  992.       GpiQueryFontMetrics(hPS, (LONG)sizeof(FONTMETRICS), &fm);
  993.       xmod = (INT)fm.lAveCharWidth;
  994.       ymod = (INT)fm.lMaxBaselineExt;
  995.       WinReleasePS(hPS);
  996.      }
  997.    /* if either the width or the height are non-zero, then the size of the */
  998.    /*     created window will be changed, set SizeStyle accordingly        */
  999.    if((cx > 0) || (cy > 0))
  1000.      SizeStyle |= SWP_SIZE;
  1001.    /* set the size and position of the window and activate it              */
  1002.    rc = WinSetWindowPos(hWndFrame, HWND_TOP, 0, 0,
  1003.                         (USHORT)(cx * xmod)/DLGXMOD,
  1004.                         (USHORT)(cy * ymod)/DLGYMOD, SizeStyle);
  1005.  
  1006.    /* if the either the intial x or y position of the window is non-zero,  */
  1007.    /*    set the window to its new position                                */
  1008.    if((x > 0) || (y > 0))
  1009.      rc = WinSetWindowPos(hWndFrame, HWND_TOP,
  1010.                           (USHORT)(x * xmod)/DLGXMOD,
  1011.                           (USHORT)(y * ymod)/DLGYMOD, 0, 0, SWP_MOVE);
  1012.  
  1013.    /* if rc is not set to TRUE then WinSetWindowPos failed, notify the user*/
  1014.    /*     and exit this function                                           */
  1015.    if(!rc)
  1016.      {
  1017.       WinLoadString(hAB, 0, IDS_ERR_WINDOW_POS, 80, MsgBuffer);
  1018.       WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  1019.                     0, 0, MB_OK|MB_ICONEXCLAMATION);
  1020.       return((HWND)0);
  1021.      }
  1022.  
  1023.    /* return the handle to the frame window                                */
  1024.    return(hWndFrame);
  1025. }  /* End of cwCreateWindow */
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.