home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / w3_prog / 3d.arj / DEMODLG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  5.1 KB  |  178 lines

  1. #include <windows.h>
  2. #include <string.h>
  3. #include "ids.h"
  4. #include "demo.h"
  5. #include "three_d.h"
  6.  
  7. BOOL FAR PASCAL DemoDlgProc(HWND,WORD,WORD,LONG);
  8. BOOL FAR PASCAL AboutDlgProc(HWND,WORD,WORD,LONG);
  9. static void AdjustPosition(HWND);
  10.  
  11. extern HANDLE hInst;
  12.  
  13. /*
  14.    ****************************************************************************
  15.    DemoDlgProc()
  16.    Handles all messages for the 3-D demo dialog box.
  17.    ****************************************************************************
  18. */
  19.  
  20. BOOL FAR PASCAL DemoDlgProc(HWND hDlg, WORD msg, WORD wParam, LONG lParam)
  21. {
  22.    FARPROC lpprocAboutDlg;
  23.  
  24.    switch (msg)
  25.    {
  26.       case WM_INITDIALOG:
  27.          AdjustPosition(hDlg);
  28.          /* Fill listboxes and combo boxes with current directory listing */
  29.          DlgDirList(hDlg,"*.*",IDD_9,NULL,0x0000);
  30.          DlgDirListComboBox(hDlg,"*.*",IDD_12,NULL,0x0000);
  31.          DlgDirListComboBox(hDlg,"*.*",IDD_13,NULL,0x0000);
  32.          DlgDirListComboBox(hDlg,"*.*",IDD_14,NULL,0x0000);
  33.          break;
  34.  
  35.       case WM_CTLCOLOR:                      /* Allow DLL to handle this one */
  36.          return(Control3dColor(hDlg,wParam));
  37.  
  38.       case WM_PAINT:
  39.          /* This posts a message to the DLL defined message WM_3DPAINT */
  40.          /* It is very important to return FALSE here, to allow the dialog */
  41.          /* handler to process the WM_PAINT message first */
  42.          PostMessage(hDlg,WM_3DPAINT,0,0L);
  43.          return (FALSE);
  44.  
  45.       case WM_3DPAINT:
  46.          /* This code calls functions in the DLL to make the controls in the */
  47.          /* dialog box 3-D */
  48.  
  49.          Draw3dFrame(hDlg,INSIDE_FRAME);
  50.          Draw3dBorder(hDlg,IDD_1,RECESSED,1);
  51.          Draw3dBorder(hDlg,IDD_2,RAISED,1);
  52.  
  53.          Draw3dBorder(hDlg,IDD_3,RECESSED,2);
  54.          Draw3dBorder(hDlg,IDD_4,RAISED,2);
  55.          Draw3dShadow(hDlg,IDD_5);
  56.  
  57.          Draw3dBorder(hDlg,IDD_6,RECESSED,3);
  58.          Draw3dBorder(hDlg,IDD_7,RAISED,3);
  59.          Draw3dShadow(hDlg,IDD_8);
  60.  
  61.          Draw3dBorder(hDlg,IDD_9,RECESSED,1);
  62.          Draw3dBorder(hDlg,IDD_10,RAISED,1);
  63.          Draw3dShadow(hDlg,IDD_11);
  64.  
  65.          Draw3dBorder(hDlg,IDD_12,RECESSED,2);
  66.          Draw3dBorder(hDlg,IDD_13,RAISED,2);
  67.          Draw3dShadow(hDlg,IDD_14);
  68.  
  69.          Draw3dBorder(hDlg,IDD_15,RECESSED,3);
  70.          Draw3dBorder(hDlg,IDD_16,RAISED,3);
  71.          Draw3dShadow(hDlg,IDD_17);
  72.  
  73.          Draw3dBorder(hDlg,IDOK,RECESSED,2);
  74.          Draw3dBorder(hDlg,IDCANCEL,RAISED,2);
  75.          Draw3dShadow(hDlg,IDD_ABOUT);
  76.  
  77.          break;
  78.  
  79.       case WM_COMMAND:
  80.          switch(wParam)
  81.          {
  82.             case IDOK:
  83.             case IDCANCEL:
  84.                EndDialog(hDlg,TRUE);
  85.                break;
  86.  
  87.             case IDD_ABOUT:
  88.                lpprocAboutDlg = MakeProcInstance(AboutDlgProc,hInst);
  89.                DialogBox(hInst,"AboutBox",hDlg,lpprocAboutDlg);
  90.                FreeProcInstance(lpprocAboutDlg);
  91.                break;
  92.  
  93.             default:
  94.                return (FALSE);
  95.          }
  96.          break;
  97.  
  98.       default:
  99.          return(FALSE);
  100.    }
  101.    return (TRUE);
  102. }
  103.  
  104. BOOL FAR PASCAL AboutDlgProc(HWND hDlg, WORD msg, WORD wParam, LONG lParam)
  105. {
  106.    PAINTSTRUCT ps;
  107.  
  108.    switch (msg)
  109.    {
  110.       case WM_INITDIALOG:
  111.          AdjustPosition(hDlg);
  112.          break;
  113.  
  114.       case WM_CTLCOLOR:
  115.          return(Control3dColor(hDlg,wParam));
  116.  
  117.       case WM_PAINT:
  118.          PostMessage(hDlg,WM_3DPAINT,0,0L);
  119.          return (FALSE);
  120.  
  121.       case WM_3DPAINT:
  122.          Draw3dFrame(hDlg,OUTSIDE_FRAME);
  123.          Draw3dBorder(hDlg,IDD_ICON1,RAISED,2);
  124.          Draw3dBorder(hDlg,IDD_HEADER,RECESSED,2);
  125.          Draw3dBorder(hDlg,IDD_ICON2,RAISED,2);
  126.          Draw3dShadow(hDlg,IDD_RECT);
  127.          break;
  128.  
  129.       case WM_COMMAND:
  130.          switch(wParam)
  131.          {
  132.             case IDOK:
  133.                EndDialog(hDlg,TRUE);
  134.                break;
  135.  
  136.             default:
  137.                return (FALSE);
  138.          }
  139.          break;
  140.  
  141.       default:
  142.          return(FALSE);
  143.    }
  144.    return (TRUE);
  145. }
  146.  
  147. /*
  148.    ****************************************************************************
  149.    AdjustPosition()
  150.    Adjusts the position of the passed window so that it is centered both
  151.    horizontally and vertically in the client of the main window.
  152.    ****************************************************************************
  153. */
  154.  
  155. void AdjustPosition(hWindow)
  156. HWND hWindow;
  157. {
  158.    RECT hRect;
  159.    short xSize,ySize,xPos,yPos;
  160.    short xScreen,yScreen;
  161.  
  162.    xScreen = GetSystemMetrics(SM_CXSCREEN);  /* Width of screen */
  163.    yScreen = GetSystemMetrics(SM_CYSCREEN);  /* Height of screen */
  164.  
  165.    GetWindowRect(hWindow,&hRect);            /* Get dialog screen coordinates */
  166.  
  167.    xSize = hRect.right - hRect.left;         /* x size of dialog box */
  168.    ySize = hRect.bottom - hRect.top;         /* y size of dialog box */
  169.    xPos  = (xScreen - xSize) / 2;            /* Calculate x position */
  170.    yPos  = (yScreen - ySize) / 2;            /* Calculate y position */
  171.  
  172.    /* Center the window based on the screen dimensions */
  173.    MoveWindow(hWindow,xPos,yPos,xSize,ySize,FALSE);
  174.  
  175.    return;
  176. }
  177.  
  178.