home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 18.ddi / SAMPLES / DIBVIEW / OPTIONS.C_ / OPTIONS.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  12.2 KB  |  395 lines

  1. /*************************************************************************
  2.  
  3.       File:  OPTIONS.C
  4.  
  5.    Purpose:  Routines to implement the display/printing options dialog
  6.              box.
  7.  
  8.  Functions:  ShowOptions
  9.              StretchDlg
  10.              OptionsInit
  11.              EnableXYAxisWindows
  12.              SetHelpText
  13.              GetDlgItemIntOrDef
  14.  
  15.   Comments:
  16.  
  17.    History:   Date     Reason
  18.  
  19.              6/1/91    Created
  20.  
  21. *************************************************************************/
  22.  
  23. #include "master.h"
  24.  
  25. // Magic numbers used within this modules.
  26.  
  27. #define MAX_HELP_LINE   80
  28.  
  29.  
  30. // Locally used variables -- globals for this module only.
  31.  
  32. static char          szStretchDlgName[] = "OptionsStretch";
  33. static BOOL          bTmpStretch;         // New stretch value.
  34. static BOOL          bTmpUse31PrnAPIs;    // New 3.1 Print APIs value.
  35. static BOOL          bTmpUseBanding;      // New banding flag value.
  36. static LPOPTIONSINFO lpInfo;
  37. static int           idDispOption;        // Current display option.
  38. static int           idPrintOption;       // Current print option.
  39.  
  40.  
  41.  
  42. // Locally used function prototypes.
  43.  
  44. BOOL FAR PASCAL __export StretchDlg(HWND, unsigned, WORD, LONG);
  45. void EnableXYAxisWindows (HWND hDlg, BOOL bEnable);
  46. BOOL OptionsInit (HWND hDlg, LPOPTIONSINFO lpOptions);
  47. void SetHelpText (HWND hDlg, WORD wCtrlID);
  48. int  GetDlgItemIntOrDef (HWND hDlg, int nCtrlID, int nDefault);
  49.  
  50.  
  51.  
  52.  
  53. //---------------------------------------------------------------------
  54. //
  55. // Function:   ShowOptions
  56. //
  57. // Purpose:    Brings up options dialog box which modifies the OPTIONSINFO
  58. //             structure passed to this routine.
  59. //
  60. // Parms:      hWnd    == Handle to options dialog box's parent.
  61. //             lpInfo  == Far pointer to OPTIONSINFO structure the options
  62. //                         dialog box should edit.
  63. //
  64. // History:   Date      Reason
  65. //             6/01/91  Created
  66. //
  67. //---------------------------------------------------------------------
  68.  
  69. void ShowOptions (HWND hWnd, LPOPTIONSINFO lpInfo)
  70. {
  71.    FARPROC lpProcStretch;
  72.  
  73.    lpProcStretch = MakeProcInstance(StretchDlg, hInst);
  74.  
  75.    DialogBoxParam(hInst,
  76.                   szStretchDlgName,
  77.                   hWnd,
  78.                   lpProcStretch,
  79.                   (LONG) (LPOPTIONSINFO) lpInfo);
  80.  
  81.    FreeProcInstance(lpProcStretch);
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. //---------------------------------------------------------------------
  90. //
  91. // Function:   StretchDlg
  92. //
  93. // Purpose:    Window procedure for the options dialog box.
  94. //
  95. // Parms:      hWnd    == Handle to options dialog box's parent.
  96. //             message == Message being sent to dialog box.
  97. //             wParam  == Depends on message.
  98. //             lParam  == Depends on message.
  99. //
  100. //
  101. // History:   Date      Reason
  102. //             6/01/91  Created
  103. //             7/01/91  Major restructuring.
  104. //
  105. //---------------------------------------------------------------------
  106.  
  107. BOOL FAR PASCAL __export StretchDlg (HWND hDlg,
  108.                         unsigned message,
  109.                             WORD wParam,
  110.                             LONG lParam)
  111. {
  112.    switch (message)
  113.       {
  114.       case WM_INITDIALOG:
  115.          return OptionsInit (hDlg, (LPOPTIONSINFO) lParam);
  116.  
  117.  
  118.  
  119.       case WM_COMMAND:
  120.          if (wParam != IDRB_STRETCHWINDOW)
  121.             SetHelpText (hDlg, wParam);
  122.  
  123.          switch (wParam)
  124.             {
  125.                // If the stretch checkbox is hit, toggle the current
  126.                //  stretch mode, and update the help window.
  127.  
  128.             case IDRB_STRETCHWINDOW:
  129.                bTmpStretch = !bTmpStretch;
  130.                SetHelpText (hDlg, wParam + bTmpStretch);
  131.                return TRUE;
  132.  
  133.  
  134.                // If the banding checkbox is hit, toggle the current
  135.                //  banding mode, and update the help window.
  136.  
  137.             case IDRB_USEBANDING:
  138.                bTmpUseBanding = !bTmpUseBanding;
  139.                SetHelpText (hDlg, wParam + bTmpUseBanding);
  140.                return TRUE;
  141.  
  142.  
  143.                // If the "Use 3.1 APIs" checkbox is hit, toggle the current
  144.                //  mode, and update the help window.
  145.  
  146.             case IDRB_USE31APIS:
  147.                bTmpUse31PrnAPIs = !bTmpUse31PrnAPIs;
  148.                SetHelpText (hDlg, wParam + bTmpUse31PrnAPIs);
  149.                return TRUE;
  150.  
  151.  
  152.  
  153.                // If one of the printer option buttons is pressed,
  154.                //  we may want to enable or gray the X/Y Axis
  155.                //  edit controls.  We only perform this action if
  156.                //  it is necessary.  Also, remember which button
  157.                //  is selected.
  158.  
  159.             case IDRB_SCALE:
  160.             case IDRB_STRETCH:
  161.             case IDRB_BESTFIT:
  162.                if (wParam == IDRB_SCALE && idPrintOption != IDRB_SCALE)
  163.                   EnableXYAxisWindows (hDlg, TRUE);
  164.                else if (wParam != IDRB_SCALE && idPrintOption == IDRB_SCALE)
  165.                   EnableXYAxisWindows (hDlg, FALSE);
  166.  
  167.                idPrintOption = wParam;
  168.                return TRUE;
  169.  
  170.  
  171.                // If one of the display option buttons is pressed,
  172.                //  remember it.
  173.  
  174.             case IDRB_USEDIBS:
  175.             case IDRB_USEDDBS:
  176.             case IDRB_USESETDIBITS:
  177.                idDispOption = wParam;
  178.                return TRUE;
  179.  
  180.  
  181.  
  182. //            case IDEF_XAXIS:
  183. //               return TRUE;
  184. //
  185. //            case IDEF_YAXIS:
  186. //               return TRUE;
  187.  
  188.  
  189.             case IDOK:
  190.                lpInfo->bStretch        = bTmpStretch;
  191.                lpInfo->bPrinterBand    = bTmpUseBanding;
  192.                lpInfo->bUse31PrintAPIs = bTmpUse31PrnAPIs;
  193.                lpInfo->wDispOption     = idDispOption;
  194.                lpInfo->wPrintOption    = idPrintOption;
  195.                lpInfo->wXScale         = GetDlgItemIntOrDef (hDlg,
  196.                                                              IDEF_XAXIS,
  197.                                                              lpInfo->wXScale);
  198.                lpInfo->wYScale         = GetDlgItemIntOrDef (hDlg,
  199.                                                              IDEF_YAXIS,
  200.                                                              lpInfo->wYScale);
  201.  
  202.                // Fall through (end this dialog box).
  203.  
  204.             case IDCANCEL:
  205.                EndDialog(hDlg, TRUE);
  206.                return TRUE;
  207.  
  208.  
  209.             default:
  210.                return FALSE;
  211.             }
  212.       }
  213.    return FALSE;
  214. }
  215.  
  216.  
  217.  
  218.  
  219.  
  220. //---------------------------------------------------------------------
  221. //
  222. // Function:   OptionsInit
  223. //
  224. // Purpose:    Called by options dialog for WM_INITDIALOG.  Keeps a pointer
  225. //             to the OPTIONSINFO structure we're modifying.  Sets up
  226. //             globals for current state of certain buttons.  Sets correct
  227. //             buttons.  Grays controls that should be gray.  Initializes
  228. //             edit fields.
  229. //
  230. //             Sets focus to radio button who is "selected" in the
  231. //             first group of radio buttons (i.e. the display options
  232. //             radio button group).  Strange side-effects can happen
  233. //             if this isn't done (e.g. tabbing through the controls
  234. //             will stop on the first control in the dialog box -- even
  235. //             if it isn't checked).  This leads to some subtle bugs...
  236. //
  237. // Parms:      hDlg      == Handle to options dialog box's window.
  238. //             lpOptions == Far pointer to OPTIONSINFO structure passed
  239. //                          for our dialog box to change.  All starting
  240. //                          info is saved from this.
  241. //
  242. // History:   Date      Reason
  243. //             9/01/91  Cut out of dialog procedure.
  244. //            11/08/91  Added SetFocus, and return FALSE.
  245. //
  246. //---------------------------------------------------------------------
  247.  
  248. BOOL OptionsInit (HWND hDlg,
  249.          LPOPTIONSINFO lpOptions)
  250. {
  251.    lpInfo           = lpOptions;
  252.    bTmpStretch      = lpOptions->bStretch;
  253.    bTmpUseBanding   = lpOptions->bPrinterBand;
  254.    bTmpUse31PrnAPIs = lpOptions->bUse31PrintAPIs;
  255.  
  256.  
  257.       // Set up the correct buttons in the box.  Disable controls
  258.       //  which should be disabled.
  259.  
  260.    SendDlgItemMessage (hDlg,
  261.                        IDRB_STRETCHWINDOW,
  262.                        BM_SETCHECK,
  263.                        bTmpStretch,
  264.                        NULL);
  265.  
  266.    SendDlgItemMessage (hDlg,
  267.                        IDRB_USEBANDING,
  268.                        BM_SETCHECK,
  269.                        bTmpUseBanding,
  270.                        NULL);
  271.  
  272.    SendDlgItemMessage (hDlg,
  273.                        IDRB_USE31APIS,
  274.                        BM_SETCHECK,
  275.                        bTmpUse31PrnAPIs,
  276.                        NULL);
  277.  
  278.    idDispOption  = lpOptions->wDispOption;
  279.    idPrintOption = lpOptions->wPrintOption;
  280.  
  281.  
  282.       // Note the use of CheckRadioButton (as opposed to
  283.       //  SendDlgItemMessage (... BM_SETCHECK...) -- this is used so
  284.       //  that tabbing occurs between _groups_ correctly.  When
  285.       //  a radio button is pressed, tabbing to the group of
  286.       //  radio buttons should set the focus to *that* button.
  287.  
  288.    CheckRadioButton (hDlg, IDRB_USEDIBS, IDRB_USESETDIBITS, idDispOption);
  289.    CheckRadioButton (hDlg, IDRB_BESTFIT, IDRB_SCALE, idPrintOption);
  290.  
  291.    SetDlgItemInt (hDlg, IDEF_XAXIS, lpOptions->wXScale, FALSE);
  292.    SetDlgItemInt (hDlg, IDEF_YAXIS, lpOptions->wYScale, FALSE);
  293.  
  294.    EnableXYAxisWindows (hDlg, lpOptions->wPrintOption == PRINT_SCALE);
  295.  
  296.    return TRUE;
  297. }
  298.  
  299.  
  300.  
  301.  
  302. //---------------------------------------------------------------------
  303. //
  304. // Function:   EnableXYAxisWindows
  305. //
  306. // Purpose:    Enables or gray's the X/Y axis edit controls and their
  307. //             labes.
  308. //
  309. // Parms:      hDlg    == Handle to options dialog box's parent.
  310. //             bEnable == TRUE = Enable them, FALSE = Gray them.
  311. //
  312. // History:   Date      Reason
  313. //             7/01/91  Cut out of options dialog.
  314. //
  315. //---------------------------------------------------------------------
  316.  
  317. void EnableXYAxisWindows (HWND hDlg, BOOL bEnable)
  318. {
  319.    EnableWindow (GetDlgItem (hDlg, IDEF_XAXIS),  bEnable);
  320.    EnableWindow (GetDlgItem (hDlg, IDEF_YAXIS),  bEnable);
  321.    EnableWindow (GetDlgItem (hDlg, IDC_XLABEL),  bEnable);
  322.    EnableWindow (GetDlgItem (hDlg, IDC_YLABEL),  bEnable);
  323. }
  324.  
  325.  
  326.  
  327.  
  328. //---------------------------------------------------------------------
  329. //
  330. // Function:   SetHelpText
  331. //
  332. // Purpose:    Sets the help static edit control to the appropriate
  333. //             string.  Strings are kept in a string table in the
  334. //             resources (see DIBVIEW.RC).
  335. //
  336. // Parms:      hDlg    == Handle to options dialog box's parent.
  337. //             wCtrlID == ID of control we're setting help for.
  338. //
  339. // History:   Date      Reason
  340. //             7/01/91  Cut out of options dialog.
  341. //
  342. //---------------------------------------------------------------------
  343.  
  344. void SetHelpText (HWND hDlg, WORD wCtrlID)
  345. {
  346.    char  szHelpBuffer [MAX_HELP_LINE];
  347.  
  348.    LoadString (hInst, wCtrlID, szHelpBuffer, sizeof (szHelpBuffer));
  349.    SetDlgItemText (hDlg, IDEF_HELP, szHelpBuffer);
  350. }
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357. //---------------------------------------------------------------------
  358. //
  359. // Function:   GetDlgItemIntOrDef
  360. //
  361. // Purpose:    Returns an integer stored in an edit control of a
  362. //             dialog box.  If the edit control doesn't contain
  363. //             a valid integer value, returns a default value.
  364. //
  365. // Parms:      hDlg     == Handle to dialog box.
  366. //             wCtrlID  == ID of control we're getting the int from.
  367. //             nDefault == Value to return if edit control doesn't have
  368. //                          a valid integer in it.
  369. //
  370. // History:   Date      Reason
  371. //            11/13/91  Created
  372. //            11/14/91  Use string table for error string.
  373. //
  374. //---------------------------------------------------------------------
  375.  
  376. int GetDlgItemIntOrDef (HWND hDlg, int nCtrlID, int nDefault)
  377. {
  378.    int  nVal;
  379.    BOOL bTrans;
  380.    char szErr[MAX_HELP_LINE];
  381.  
  382.    nVal = GetDlgItemInt (hDlg, nCtrlID, &bTrans, FALSE);
  383.  
  384.    if (bTrans)
  385.       return nVal;
  386.    else
  387.       if (LoadString (hInst, IDS_ERRXYSCALE, szErr, MAX_HELP_LINE))
  388.          MessageBox (hDlg, szErr, NULL, MB_OK);
  389.       else
  390.          MessageBeep (0);
  391.  
  392.    return nDefault;
  393. }
  394.  
  395.