home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / REGM151 / DEMOWIN.C_ / DEMOWIN.C
Text File  |  1995-03-03  |  6KB  |  151 lines

  1.  
  2. #include <windows.h>    /* Window's header file - always included */
  3. #include "demowin.h"    /* Demo's header file */
  4. /*
  5. ******************************************************************
  6.  This is a demo program which checks the Keywords
  7. ******************************************************************
  8. */
  9.  
  10. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine,
  11.                     int nCmdShow)
  12. {
  13.         HWND    hWnd;
  14.         MSG             msg;
  15.         WNDCLASS        wndclass;       /* window class structure */
  16.                                         /* fill in class data for new class */
  17.         char    Keyword [40];
  18.         int     i;
  19.  
  20.         if (!hPrevInstance)
  21.             {
  22.             wndclass.style              = CS_HREDRAW | CS_VREDRAW;
  23.             wndclass.lpfnWndProc        = WndProc;
  24.             wndclass.cbClsExtra         = 0;
  25.             wndclass.cbWndExtra         = 0;
  26.             wndclass.hInstance          = hInstance;
  27.             wndclass.hIcon              = LoadIcon (hInstance, "ICON_BRITE");
  28.             wndclass.hCursor            = LoadCursor (NULL,IDC_ARROW);
  29.             wndclass.hbrBackground      = GetStockObject (LTGRAY_BRUSH);
  30.             wndclass.lpszMenuName       = "MyMenu";
  31.             wndclass.lpszClassName      = "MyClass";
  32.                                         /* register the new window class */
  33.             if (!RegisterClass (&wndclass))
  34.                  return (0);            /* quit if can't register class */
  35.             }
  36.  
  37.         /* Create main windows */
  38.         hWnd = CreateWindow ("MyClass",
  39.                              "Demo of Remote Control Validation",
  40.                              WS_OVERLAPPEDWINDOW,
  41.                              CW_USEDEFAULT,    // Default horizontal pozition.
  42.                              CW_USEDEFAULT,    // Default vertical pozition.
  43.                              CW_USEDEFAULT,    // Default wigth.
  44.                              CW_USEDEFAULT,    // Default height.
  45.                              NULL,             // Overlapped windows have no parents.
  46.                              NULL,             // Use the window class menu.
  47.                              hInstance,        // This unstance owns this window.
  48.                              NULL);            // Pointer not needed.
  49.  
  50.         ShowWindow (hWnd, nCmdShow);           // display the window
  51.  
  52.         /* Get the Keyword */
  53.         lstrcpy (Keyword, lpszCmdLine);
  54.         for (i = 0; i < strlen (Keyword) && Keyword [i] != ' '; i++);
  55.         Keyword [i] = 0x00;
  56.         if (strcmp (Keyword, "DemoUser") == 0)
  57.             MessageBox (hWnd,
  58.                         "This program is running successfully!!!",
  59.                         "Program OK",
  60.                         MB_OK | MB_ICONEXCLAMATION);
  61.         else
  62.             {
  63.             MessageBeep (0);
  64.             MessageBox (hWnd,
  65.                         "This program needs validation.\n See the documentation.",
  66.                          "Warning",
  67.                         MB_OK | MB_ICONSTOP);
  68.             return (msg.wParam);    /* quit */
  69.             }
  70.         while (GetMessage (&msg, NULL, NULL, NULL))     /* message loop */
  71.                {
  72.                TranslateMessage (&msg); /* translate keyboard message */
  73.                DispatchMessage (&msg);  /* send message to WndProc () */
  74.                }
  75.  
  76.         return (msg.wParam);    /* quit */
  77. }
  78.  
  79. /* WndProc () is a custom function for processing messages from Windows */
  80. long FAR PASCAL _export WndProc (HWND hWnd, unsigned int wMessage,
  81.                                  unsigned int wParam, LONG lParam)
  82. {
  83.         FARPROC lpfnDlgProc;    /* far pointer to a function */
  84.         HINSTANCE hInstance;
  85.  
  86.         switch (wMessage)                       /* process windows messages */
  87.             {
  88.             case WM_COMMAND:
  89.                  switch (wParam)
  90.                  {
  91.                  case IDM_QUIT:                 /* quit menu item */
  92.                         DestroyWindow (hWnd);   /* destroy window, */
  93.                         break;                  /* terminate application */
  94.                  case IDM_ABOUT:                /* about menu item */
  95.  
  96.                         hInstance = GetWindowWord (hWnd, GWW_HINSTANCE);
  97.                         lpfnDlgProc = MakeProcInstance ((FARPROC) About,
  98.                                                         hInstance);
  99.                         DialogBox (hInstance, "DIALOG_1", hWnd, lpfnDlgProc);
  100.                         FreeProcInstance (lpfnDlgProc);
  101.  
  102.                         break;                  /* continue application */
  103.                  }
  104.                  break;
  105.  
  106.             case WM_DESTROY:                    /* stop application */
  107.                  PostQuitMessage (0);       /* this will exit message loop */
  108.                  break;
  109.  
  110.             default:                            /* default windows message processing */
  111.                  return DefWindowProc (hWnd, wMessage, wParam, lParam);
  112.             }
  113.  
  114.         return (0L);
  115. }
  116.  
  117. /* */
  118. /*
  119. ********************************************
  120.    Dialog box ABOUT
  121. ********************************************
  122. */
  123.  
  124. BOOL FAR PASCAL About (HWND hDlg, unsigned int wMessage,
  125.                        unsigned int wParam, LONG lParam)
  126. {
  127.         HINSTANCE hInstance;
  128.         FARPROC lpfnDlgProc;    /* far pointer to a function */
  129.         char    str [3];
  130.  
  131.         switch (wMessage)
  132.             {
  133.             case WM_INITDIALOG:
  134.                  return (TRUE);
  135.  
  136.             case WM_COMMAND:    /* controls in dialog box activated */
  137.  
  138.                  switch (wParam)
  139.                      {
  140.                      case ABOUT_OK:             /* OK button */
  141.                        EndDialog (hDlg, 0);  /* exit the dialog box */
  142.                        return (TRUE);
  143.                      }
  144.             case WM_DESTROY:                    /* stop application */
  145.                  EndDialog (hDlg, 0);  /* exit the dialog box */
  146.                  break;
  147.             }
  148.         return (FALSE); /* return FALSE to signify message not processed */
  149. }
  150.  
  151.