home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_03 / 3n03012b < prev    next >
Text File  |  1992-01-08  |  6KB  |  195 lines

  1. /*
  2.      File name:    TESTFAD.C
  3.      Description:  This source file demonstrates the use of
  4.      the Fader custom control in application programs.  The
  5.      base source code for this module was first generated
  6.      using the CASE:W code generator in verbose mode.
  7. */
  8.  
  9. #define EXTERN
  10. #include "TESTFAD.h" /* Generated by CASE:W */
  11. #include "fadbox.h" /* Generated by SDK Dialog Box Editor */
  12. #include "fader.h"  /* Needed for fader custom control */
  13.  
  14. BOOL NEAR PASCAL RegisterControlClass (HANDLE hInstance);
  15.  
  16. /* Windows 3.0 Main Program Body  */
  17.  
  18. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  19.                         LPSTR lpszCmdLine, int nCmdShow)
  20. {
  21.  MSG      msg;   /* MSG structure to store your messages */
  22.  int      nRc;   /* return value from Register Classes   */
  23.  HANDLE   hLibFader;
  24.  
  25.  strcpy(szarAppName, "TESTFAD");
  26.  hInst = hInstance;
  27.  if(!hPrevInstance)
  28.    {
  29.     if ((nRc = nCwRegisterClasses()) == -1)
  30.       {
  31.        /* registering one of the windows failed  */
  32.        LoadString(hInst, IDS_ERR_REGISTER_CLASS,
  33.                 szarString, sizeof(szarString));
  34.        MessageBox(NULL, szarString,
  35.                 NULL, MB_ICONEXCLAMATION);
  36.        return nRc;
  37.       }
  38.    }
  39.  
  40.  /* create application's Main window    */
  41.  hWndMain = CreateWindow(
  42.     szarAppName, NULL, WS_CAPTION | WS_SYSMENU
  43.     | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME
  44.     | WS_CLIPCHILDREN | WS_VISIBLE | WS_OVERLAPPED,
  45.     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
  46.     NULL, NULL, hInst, NULL);
  47.  
  48.  if(hWndMain == NULL)
  49.    {
  50.     LoadString(hInst, IDS_ERR_CREATE_WINDOW, szarString, sizeof(szarString));
  51.     MessageBox(NULL, szarString, NULL, MB_ICONEXCLAMATION);
  52.     return IDS_ERR_CREATE_WINDOW;
  53.    }
  54.  ShowWindow(hWndMain, nCmdShow);            /* display main window      */
  55.  hLibFader = LoadLibrary("FADER.DLL");
  56.  if (hLibFader < 32)
  57.    return(0);
  58.  
  59.  while(GetMessage(&msg, NULL, 0, 0))        /* Until WM_QUIT message    */
  60.    {
  61.     TranslateMessage(&msg);
  62.     DispatchMessage(&msg);
  63.    }
  64.  
  65.  /* Do cleanup before exiting from the application  */
  66.  UnregisterClass(szarAppName, hInst);
  67.  FreeLibrary(hLibFader);
  68.  return msg.wParam;
  69. } /*  End of WinMain  */
  70.  
  71.  
  72. /* Main Window Procedure  */
  73.  
  74. LONG FAR PASCAL WndProc(HWND hWnd, WORD Message, WORD wParam, LONG lParam)
  75. {
  76.  switch (Message)
  77.    {
  78.     case WM_COMMAND:
  79.          switch (wParam)
  80.            {
  81.             case IDM_D_FADERS:
  82.                  {
  83.                   FARPROC lpfnFADBOXMsgProc;
  84.  
  85.                   lpfnFADBOXMsgProc = MakeProcInstance(
  86.                             (FARPROC)FADBOXMsgProc, hInst);
  87.                   DialogBox(hInst, (LPSTR)"FADBOX",
  88.                             hWnd, lpfnFADBOXMsgProc);
  89.                   FreeProcInstance(lpfnFADBOXMsgProc);
  90.                  }
  91.                  break;
  92.             case IDM_D_EXIT:
  93.                  DestroyWindow(hWnd);
  94.                  if (hWnd == hWndMain)
  95.                    PostQuitMessage(0);
  96.                  hWndMain = 0;
  97.                  break;
  98.             default:
  99.                 return DefWindowProc(hWnd, Message,
  100.                                     wParam, lParam);
  101.            }
  102.          break;        /* End of WM_COMMAND */
  103.     case WM_CLOSE:  /* close the window  */
  104.          DestroyWindow(hWnd);
  105.          if (hWnd == hWndMain)
  106.            PostQuitMessage(0);
  107.          hWndMain = 0;
  108.          break;     /* End of WM_CLOSE       */
  109.     default:
  110.          return DefWindowProc(hWnd, Message, wParam, lParam);
  111.    }
  112.  return 0L;
  113. }     /* End of WndProc   */
  114.  
  115. /* Dialog Window Procedure  */
  116. BOOL FAR PASCAL FADBOXMsgProc(HWND hWndDlg, WORD Message,
  117.                                 WORD wParam, LONG lParam)
  118. {
  119.  char text_val[40];
  120.  int x;
  121.  BOOL lTranslated;
  122.  
  123.  switch(Message)
  124.    {
  125.     case WM_INITDIALOG:
  126.          SetDlgItemText(hWndDlg, FADER_EDIT,
  127.                 (LPSTR)"TESTING");
  128.          break; /* End of WM_INITDLG  */
  129.     case WM_CLOSE:
  130.          EndDialog(hWndDlg, TRUE);
  131.          break; /* End of WM_CLOSE */
  132.     case WM_COMMAND:
  133.          switch(wParam)
  134.            {
  135.             case FADER_OK:
  136.          /* Ignore data values entered into the controls  */
  137.          /* and dismiss the dialog window returning FALSE */
  138.                  EndDialog(hWndDlg, FALSE);
  139.                  break;
  140.             case FADER_1:
  141.                  switch (HIWORD(lParam)) {
  142.                     case FDRN_THUMBTRACK:
  143.                     case FDRN_ENDFADER:
  144.    /* User has changed the current value of the Fader */
  145.    /* Request the current value from the Fader */
  146.                        x = (int) SendMessage(LOWORD(lParam),
  147.                                     FDRM_GETLOGVALUE, 0, 0);
  148.                        wsprintf(text_val,"%d",x);
  149.                        SetDlgItemText(hWndDlg, FADER_EDIT,
  150.                                         (LPSTR)text_val);
  151.                        break;
  152.                      }
  153.                  break;
  154.             case FADER_EDIT:
  155.  /* If the value in the edit box changes, we will set the
  156.     fader to use this as the new logical position */
  157.                  if (HIWORD(lParam) == EN_CHANGE) {
  158.                      x = GetDlgItemInt(hWndDlg, FADER_EDIT,
  159.                           (BOOL FAR *)&lTranslated, FALSE);
  160.                      SendDlgItemMessage(hWndDlg, FADER_1,
  161.                                     FDRM_SETLOGVALUE, x, 0);
  162.                      }
  163.                  break;
  164.            }
  165.          break;    /* End of WM_COMMAND   */
  166.  
  167.     default:
  168.         return FALSE;
  169.    }
  170.  return TRUE;
  171. } /* End of FADBOXMsgProc  */
  172.  
  173.  
  174. /* nCwRegisterClasses Function   */
  175. int nCwRegisterClasses(void)
  176. {
  177.  WNDCLASS  wndclass; /* struct to define a window class */
  178.  
  179.  wndclass.style = CS_HREDRAW | CS_VREDRAW;
  180.  wndclass.lpfnWndProc = WndProc;
  181.  wndclass.cbClsExtra = 0;
  182.  wndclass.cbWndExtra = 0;
  183.  wndclass.hInstance = hInst;
  184.  wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  185.  wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  186.  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  187.  wndclass.lpszMenuName = szarAppName;
  188.  wndclass.lpszClassName = szarAppName;
  189.  
  190.  if(!RegisterClass(&wndclass))
  191.    return -1;
  192.  
  193.  return 0;
  194. }  /* End of nCwRegisterClasses */
  195.