home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1991 / 05 / grdlagen / windemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-21  |  4.9 KB  |  163 lines

  1. /*----------------------------------------------------------
  2. -     WINDEMO.C - Ein kleines Übungsprogramm in MS C 6.0   -
  3. -                    (c) 1991 toolbox                      -
  4. ----------------------------------------------------------*/
  5.  
  6.  #include <windows.h>
  7.  #include "windemo.h"
  8.  
  9. /*---------------------------------------------------
  10.   Prototyp der Fensterfunktion
  11.  --------------------------------------------------*/
  12.  
  13.  long FAR PASCAL Fenster (HWND, WORD, WORD, LONG);
  14.  
  15.  static char szAppName[] = "Windows Demo";
  16.  HANDLE hInst;
  17.  
  18. /*---------------------------------------------------
  19.   Hier ist der Eintrittspunkt des Programms
  20.  --------------------------------------------------*/
  21.  
  22.  int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  23.                          LPSTR lpszCmdParam, int nCmdShow)
  24.  {
  25.    HWND         hwnd;
  26.    MSG          msg;
  27.    WNDCLASS     wndclass;
  28.  
  29.    if (!hPrevInstance)
  30.    {
  31.  
  32. /*---------------------------------------------------
  33.   Hier wird die Fensterklasse definiert
  34.  --------------------------------------------------*/
  35.   wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  36.   wndclass.lpfnWndProc   = Fenster;
  37.   wndclass.cbClsExtra    = 0;
  38.   wndclass.cbWndExtra    = 0;
  39.   wndclass.hInstance     = hInstance;
  40.   wndclass.hIcon         = LoadIcon(hInstance, szAppName );
  41.   wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  42.   wndclass.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  43.   wndclass.lpszMenuName  = "TestMenu";
  44.   wndclass.lpszClassName = szAppName ;
  45.  
  46. /*------------------------------------------------
  47.   Hier wird die Fensterklasse registriert
  48.  --------------------------------------------------*/
  49.  
  50.     RegisterClass (&wndclass);
  51.    }
  52.    hInst = hInstance;
  53.    hwnd = CreateWindow (szAppName,
  54.                     "toolbox Windows-Training",
  55.                     WS_OVERLAPPEDWINDOW,
  56.                     CW_USEDEFAULT,
  57.                     CW_USEDEFAULT,
  58.                     CW_USEDEFAULT,
  59.                     CW_USEDEFAULT,
  60.                     NULL,
  61.                     NULL,
  62.                     hInstance,
  63.                     NULL);
  64.  
  65. /*---------------------------------------------------
  66.   Darstellen des Fensters und des Client-Bereichs
  67.  --------------------------------------------------*/
  68.  
  69.    ShowWindow(hwnd, nCmdShow) ;
  70.    UpdateWindow (hwnd);
  71.  
  72. /*---------------------------------------------------
  73.   Warten auf eine Nachricht
  74.  --------------------------------------------------*/
  75.  
  76.    while (GetMessage (&msg, NULL, 0, 0))
  77.           {
  78.            TranslateMessage (&msg);
  79.            DispatchMessage (&msg);
  80.           }
  81.           return msg.wParam;
  82.    }
  83.  
  84. /*---------------------------------------------------
  85.   Definition der Fensterfunktion
  86.  --------------------------------------------------*/
  87.  
  88.  long FAR PASCAL Fenster (HWND hwnd, WORD message, 
  89.                           WORD wParam, LONG lParam)
  90.  {
  91.   static HICON hIcon;
  92.   HDC           hdc;
  93.   PAINTSTRUCT   ps;
  94.   RECT          rect;
  95.   FARPROC       lpProcAbout;
  96.  
  97. /*---------------------------------------------------
  98.   Hier werden eintreffende Nachrichten verarbeitet
  99.  --------------------------------------------------*/
  100.  
  101.   switch(message)
  102.   {
  103.    case WM_CREATE :
  104.           return 0;
  105.  
  106. /*-----------------------------------------------------
  107.   Hier wird geprüft, ob die Menüleiste ausgewählt wurde
  108.  ----------------------------------------------------*/
  109.    case WM_COMMAND :
  110.     if (wParam == IDM_ABOUT)
  111.     {
  112.           lpProcAbout = MakeProcInstance(Hilfe, hInst);
  113.           DialogBox(hInst,
  114.                     "InfoBox",
  115.                     hwnd,
  116.                     lpProcAbout);
  117.           FreeProcInstance(lpProcAbout);
  118.           break;
  119.     }
  120.     else
  121.        return DefWindowProc (hwnd, message, wParam, lParam);
  122.  
  123.  
  124.    case WM_PAINT :
  125.           hIcon = LoadIcon (hInst, szAppName);
  126.           hdc = BeginPaint (hwnd, &ps);
  127.           GetClientRect (hwnd, &rect) ;
  128.           DrawText (hdc,"Das erste Windows-Programm!",-1, 
  129.               &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  130.           EndPaint (hwnd, &ps);
  131.           return 0;
  132.  
  133.    case WM_DESTROY :
  134.           PostQuitMessage (0);
  135.           return 0;
  136.    }
  137.    return DefWindowProc (hwnd, message, wParam, lParam);
  138. }
  139.  
  140. /*---------------------------------------------------
  141.   Hier wird die About-Funktion definiert
  142.  --------------------------------------------------*/
  143.  
  144. BOOL FAR PASCAL Hilfe(HANDLE hDlg, WORD message,
  145.                               WORD wParam, LONG lParam)
  146. {
  147.           switch(message){
  148.            case WM_INITDIALOG:
  149.             return TRUE;
  150.  
  151.            case WM_COMMAND :
  152.             if ((wParam == IDOK) || (wParam == IDCANCEL))
  153.             {
  154.               EndDialog(hDlg, TRUE);
  155.               return (TRUE);
  156.             }
  157.             break;
  158.           }
  159.           return FALSE;
  160. }
  161. /*----------------------------------------------------------
  162. -                    Ende von WINDEMO.C                   */
  163.