home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / ADS / CPP / HELLOADS / MAINWND.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  4.5 KB  |  162 lines

  1. /* 
  2.     MAINWND.CPP -
  3.     
  4.     This file:
  5.  
  6.         Defines basic WINDOW object and MAINWDOW object.
  7.  
  8.     (C) Copyright 1988-1994 by Autodesk, Inc.
  9.  
  10.     This program is copyrighted by Autodesk, Inc. and is  licensed
  11.     to you under the following conditions.  You may not distribute
  12.     or  publish the source code of this program in any form.   You
  13.     may  incorporate this code in object form in derivative  works
  14.     provided  such  derivative  works  are  (i.) are  designed and
  15.     intended  to  work  solely  with  Autodesk, Inc. products, and
  16.     (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright
  17.     1988-1994 by Autodesk, Inc."
  18.  
  19.     AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  20.     AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  21.     CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  22.     DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  23.     UNINTERRUPTED OR ERROR FREE.
  24.  
  25. */
  26. #include "HELLOADS.h"
  27.  
  28. char MAINWINDOW::szClassName[] = APP_NAME;
  29.  
  30. //-----------------------------------------------------------------------------
  31. MAINWINDOW::MAINWINDOW()
  32. {
  33.     text = szClassName;
  34.     
  35.     if ( Register() )
  36.     {
  37.  
  38.         hWnd = CreateWindow( szClassName
  39.                             , szClassName
  40.                             , WS_OVERLAPPEDWINDOW
  41.                             , CW_USEDEFAULT
  42.                             , 0
  43.                             , CW_USEDEFAULT
  44.                             , 0
  45.                             , NULL
  46.                             , NULL
  47.                             , AppInstance()
  48.                             , (LPSTR) this ); 
  49.     }
  50.     assert( hWnd );
  51. }
  52.  
  53. //-----------------------------------------------------------------------------
  54. BOOL MAINWINDOW::Register( void )
  55. {
  56.     WNDCLASS wndclass;
  57.  
  58.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  59.     wndclass.lpfnWndProc   = ::WndProc;
  60.     wndclass.cbClsExtra    = 0;
  61.     wndclass.cbWndExtra    = sizeof( MAINWINDOW * );
  62.     wndclass.hInstance     = AppInstance();
  63.     wndclass.hIcon         = NULL;
  64.     wndclass.hCursor       = LoadCursor( NULL, IDC_ARROW );
  65.     wndclass.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
  66.     wndclass.lpszMenuName  = NULL;
  67.     wndclass.lpszClassName = szClassName;
  68.  
  69.     if ( ! RegisterClass( &wndclass ) )
  70.     {
  71.         return( FALSE );
  72.     }
  73.     return TRUE;
  74. }
  75.  
  76. //-----------------------------------------------------------------------------
  77. void MAINWINDOW::Paint( void )
  78. {
  79.     PAINTSTRUCT ps;
  80.     RECT        rect;
  81.     HDC hdc = BeginPaint( hWnd, &ps );
  82.     GetClientRect( hWnd, &rect) ;
  83.     DrawText( hdc
  84.             , text.CString()
  85.             , -1
  86.             , &rect
  87.             , DT_SINGLELINE | DT_CENTER | DT_VCENTER );
  88.     EndPaint( hWnd, &ps );
  89. }
  90.  
  91. //-----------------------------------------------------------------------------
  92. LRESULT MAINWINDOW::WndProc( UINT iMessage, WPARAM wParam, LPARAM lParam )
  93. {
  94.     switch (iMessage)
  95.     {
  96.         case WM_CREATE:
  97.         {
  98.         }
  99.         break;
  100.  
  101.         case WM_PAINT:
  102.         {
  103.             Paint();
  104.         }
  105.         break;
  106.  
  107.         case WM_DESTROY:
  108.         {
  109.             PostQuitMessage( 0 );
  110.         }
  111.         break;
  112.  
  113.         default:
  114.         {
  115.             return DefWindowProc( hWnd, iMessage, wParam, lParam );
  116.         }
  117.     }
  118.     return 0;
  119. }
  120.  
  121. //-----------------------------------------------------------------------------
  122. inline WINDOW *GetPointer( HWND hWnd )
  123. {
  124.     return (WINDOW *) GetWindowLong( hWnd, 0 );
  125. }
  126. //-----------------------------------------------------------------------------
  127. inline void SetPointer( HWND hWnd, WINDOW *pWindow )
  128. {
  129.     SetWindowLong( hWnd, 0, (LONG) pWindow );
  130. }
  131.  
  132. //-----------------------------------------------------------------------------
  133. LRESULT  CALLBACK WndProc( HWND hWnd
  134.                         , UINT iMessage
  135.                         , WPARAM wParam
  136.                         , LPARAM lParam )
  137. {
  138.     WINDOW *pWindow = GetPointer( hWnd );
  139.  
  140.     if ( pWindow == 0 )
  141.     {
  142.         if ( iMessage == WM_CREATE )
  143.         {
  144.             LPCREATESTRUCT lpcs;
  145.  
  146.             lpcs = (LPCREATESTRUCT) lParam;
  147.             pWindow = (WINDOW *) lpcs->lpCreateParams;
  148.  
  149.             SetPointer( hWnd, pWindow );
  150.             return pWindow->WndProc( iMessage, wParam, lParam );
  151.         }
  152.         else
  153.         {
  154.             return DefWindowProc( hWnd, iMessage, wParam, lParam );
  155.         }
  156.     }
  157.     else
  158.     {
  159.         return pWindow->WndProc( iMessage, wParam, lParam );
  160.     }
  161. }
  162.