home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1990 / 02 / grdlagen / hello.c next >
Encoding:
C/C++ Source or Header  |  1989-11-16  |  5.7 KB  |  197 lines

  1. /*  Hello.c
  2.     Hello Application
  3.     Windows Toolkit Version 2.03
  4.     Copyright (c) Microsoft 1985,1986,1987,1988 */
  5.  
  6. #include "windows.h"
  7. #include "hello.h"
  8.  
  9. char szAppName[10];
  10. char szAbout[10];
  11. char szTitel[30];
  12. char szText[60];
  13. int MessageLength;
  14.  
  15. static HANDLE hInst;
  16. FARPROC lpprocAbout;
  17.  
  18. long FAR PASCAL HelloWndProc(HWND, unsigned, WORD, LONG);
  19.  
  20. BOOL FAR PASCAL About( hDlg, message, wParam, lParam )
  21. HWND hDlg;
  22. unsigned message;
  23. WORD wParam;
  24. LONG lParam;
  25. {
  26.     if (message == WM_COMMAND) {
  27.         EndDialog( hDlg, TRUE );
  28.         return TRUE;
  29.         }
  30.     else if (message == WM_INITDIALOG)
  31.         return TRUE;
  32.     else return FALSE;
  33. }
  34.  
  35.  
  36. void HelloPaint( hDC )
  37. HDC hDC;
  38. {
  39.     TextOut( hDC,
  40.              (short)10,
  41.              (short)10,
  42.              (LPSTR)szText,
  43.              (short)MessageLength );
  44. }
  45.  
  46.  
  47.    /* Procedure called when the application is loaded for */
  48.    /* the first time                                      */
  49. BOOL HelloInit( hInstance )
  50. HANDLE hInstance;
  51. {
  52.   PWNDCLASS   pHelloClass;
  53.  
  54.                             /* Load strings from resource */
  55.   LoadString( hInstance, IDSNAME, (LPSTR)szAppName, 10 );
  56.   LoadString( hInstance, IDSABOUT, (LPSTR)szAbout, 10 );
  57.   LoadString( hInstance, IDSTITLE, (LPSTR)szTitel, 30 );
  58.   MessageLength = LoadString( hInstance, IDSMYTEXT,
  59.                   (LPSTR)szText, 60 );
  60.  
  61.   pHelloClass = (PWNDCLASS)LocalAlloc( LPTR,
  62.                  sizeof(WNDCLASS) );
  63.  
  64.   pHelloClass->hCursor       = LoadCursor(NULL, IDC_ARROW);
  65.   pHelloClass->hIcon         = LoadIcon( hInstance,
  66.                                MAKEINTRESOURCE(HELLOICON) );
  67.   pHelloClass->lpszMenuName  = (LPSTR)NULL;
  68.   pHelloClass->lpszClassName = (LPSTR)szAppName;
  69.   pHelloClass->hbrBackground = (HBRUSH)GetStockObject
  70.                                ( WHITE_BRUSH );
  71.   pHelloClass->hInstance     = hInstance;
  72.   pHelloClass->style         = CS_HREDRAW | CS_VREDRAW;
  73.   pHelloClass->lpfnWndProc   = HelloWndProc;
  74.  
  75.   if (!RegisterClass( (LPWNDCLASS)pHelloClass ) )
  76.             /*                     Initialization failed. */
  77.             /*  Windows will automatically deallocate all */
  78.             /*                          allocated memory. */
  79.       return FALSE;
  80.  
  81.   LocalFree( (HANDLE)pHelloClass );
  82.   return TRUE;                /* Initialization succeeded */
  83. }
  84.  
  85.  
  86. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine,
  87.                     cmdShow )
  88. HANDLE hInstance, hPrevInstance;
  89. LPSTR lpszCmdLine;
  90. int cmdShow;
  91. {
  92.     MSG   msg;
  93.     HWND  hWnd;
  94.     HMENU hMenu;
  95.  
  96.     if (!hPrevInstance) {
  97.           /* Call initialization procedure if this is the */
  98.           /*                               first instance */
  99.  
  100.     if (!HelloInit( hInstance ))
  101.           return FALSE;
  102.         }
  103.     else {
  104.                       /* Copy data from previous instance */
  105.       GetInstanceData( hPrevInstance, (PSTR)szAppName, 10 );
  106.       GetInstanceData( hPrevInstance, (PSTR)szAbout, 10 );
  107.       GetInstanceData( hPrevInstance, (PSTR)szTitel, 30 );
  108.       GetInstanceData( hPrevInstance, (PSTR)szText, 60 );
  109.       GetInstanceData( hPrevInstance, (PSTR)&MessageLength,
  110.                        sizeof(int) );
  111.         }
  112.  
  113.     hWnd = CreateWindow((LPSTR)szAppName,
  114.            (LPSTR)szTitel,
  115.            WS_TILEDWINDOW,
  116.            0,           /*  x - ignored for tiled windows */
  117.            0,           /*  y - ignored for tiled windows */
  118.            0,           /* cx - ignored for tiled windows */
  119.            0,           /* cy - ignored for tiled windows */
  120.            (HWND)NULL,                       /* no parent */
  121.            (HMENU)NULL,                 /* use class menu */
  122.            (HANDLE)hInstance, /* handle to window instance*/
  123.            (LPSTR)NULL            /* no params to pass on */
  124.            );
  125.  
  126.                     /* Save instance handle for DialogBox */
  127.     hInst = hInstance;
  128.  
  129.            /* Bind callback function with module instance */
  130.     lpprocAbout = MakeProcInstance( (FARPROC)About,
  131.                                      hInstance );
  132.  
  133.                     /* Insert "About..." into system menu */
  134.     hMenu = GetSystemMenu(hWnd, FALSE);
  135.     ChangeMenu(hMenu, 0, NULL, 999,
  136.                MF_APPEND | MF_SEPARATOR);
  137.     ChangeMenu(hMenu, 0, (LPSTR)szAbout, IDSABOUT,
  138.                MF_APPEND | MF_STRING);
  139.  
  140.               /* Make window visible according to the way */
  141.                                   /* the app is activated */
  142.     ShowWindow( hWnd, cmdShow );
  143.     UpdateWindow( hWnd );
  144.  
  145.                      /* Polling messages from event queue */
  146.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  147.         TranslateMessage((LPMSG)&msg);
  148.         DispatchMessage((LPMSG)&msg);
  149.         }
  150.  
  151.     return (int)msg.wParam;
  152. }
  153.  
  154.  
  155.             /* Procedures which make up the window class. */
  156. long FAR PASCAL HelloWndProc( hWnd, message,
  157.                               wParam, lParam )
  158. HWND hWnd;
  159. unsigned message;
  160. WORD wParam;
  161. LONG lParam;
  162. {
  163.     PAINTSTRUCT ps;
  164.  
  165.     switch (message)
  166.     {
  167.     case WM_SYSCOMMAND:
  168.         switch (wParam)
  169.         {
  170.         case IDSABOUT:
  171.             DialogBox( hInst, MAKEINTRESOURCE(ABOUTBOX),
  172.                        hWnd, lpprocAbout );
  173.             break;
  174.         default:
  175.             return DefWindowProc( hWnd, message,
  176.                                   wParam, lParam );
  177.         }
  178.         break;
  179.  
  180.     case WM_DESTROY:
  181.         PostQuitMessage( 0 );
  182.         break;
  183.  
  184.     case WM_PAINT:
  185.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  186.         HelloPaint( ps.hdc );
  187.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  188.         break;
  189.  
  190.     default:
  191.         return DefWindowProc(hWnd, message, wParam, lParam);
  192.         break;
  193.     }
  194.     return(0L);
  195.                                           /* ENDE Hello.C */
  196. }
  197.