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