FRACTAL.CXX
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:

Windows编程

开发平台:

Visual C++

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright 1992 - 1997 Microsoft Corporation.
  5. //
  6. //  File:       fractal.cxx
  7. //
  8. //  Contents:   main windows engine
  9. //
  10. //  Classes:
  11. //
  12. //  Functions:  InitApplication
  13. //              WinMain
  14. //              Exists
  15. //
  16. //  History:    4-11-94   stevebl   Created
  17. //
  18. //----------------------------------------------------------------------------
  19. #include <windows.h>
  20. #include <ole2.h>
  21. #include <ole2ver.h>
  22. #include "fractal.h"
  23. #include "fclass.h"
  24. //+---------------------------------------------------------------------------
  25. //
  26. //  Function:   InitApplication
  27. //
  28. //  Synopsis:   initializes the application and registers its window class
  29. //              (called once for all instances)
  30. //
  31. //  Arguments:  [hInstance] - handle to the first instance
  32. //
  33. //  Returns:    TRUE on success
  34. //
  35. //  History:    4-11-94   stevebl   Created
  36. //
  37. //----------------------------------------------------------------------------
  38. BOOL InitApplication(HINSTANCE hInstance)
  39. {
  40.     WNDCLASS wc;
  41.     wc.style = CS_DBLCLKS;
  42.     wc.lpfnWndProc = &WindowProc;
  43.     wc.cbClsExtra = 0;
  44.     wc.cbWndExtra = 0;
  45.     wc.hInstance = hInstance;
  46.     wc.hIcon = LoadIcon(hInstance, TEXT("AppIcon"));
  47.     wc.hCursor = (HCURSOR) LoadCursor(NULL, IDC_ARROW);
  48.     wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  49.     wc.lpszMenuName = TEXT("CFractalWindowMenu");
  50.     wc.lpszClassName = TEXT("CFractalWindow");
  51.     return(RegisterClass(&wc));
  52. }
  53. //+---------------------------------------------------------------------------
  54. //
  55. //  Function:   WinMain
  56. //
  57. //  Synopsis:   main window proceedure
  58. //
  59. //  Arguments:  [hInstance]     - instance handle
  60. //              [hPrevInstance] - handle of the previous instance (if any)
  61. //              [lpCmdLine]     - pointer to the command line
  62. //              [nCmdShow]      - show state
  63. //
  64. //  History:    4-11-94   stevebl   Created
  65. //
  66. //  Notes:      initializes application and starts message loop
  67. //
  68. //----------------------------------------------------------------------------
  69. extern "C" int PASCAL WinMain(HINSTANCE hInstance,
  70.             HINSTANCE hPrevInstance,
  71.             LPSTR lpCmdLine,
  72.             int nCmdShow)
  73. {
  74.     DWORD dwBuildVersion = OleBuildVersion();
  75.     if (HIWORD(dwBuildVersion) != rmm || LOWORD(dwBuildVersion) < rup)
  76.     {
  77.         // alert the caller that the OLE version is incompatible
  78.         // with this build.
  79.         TCHAR szTitle[MAX_STRING_LENGTH];
  80.         TCHAR szText[MAX_STRING_LENGTH];
  81.         if (LoadString(hInstance, IDS_ERROR, szTitle, MAX_STRING_LENGTH))
  82.         {
  83.             if (LoadString(hInstance, IDS_OLEINCOMPATIBLE, szText, MAX_STRING_LENGTH))
  84.             {
  85.                 MessageBox(
  86.                     NULL,
  87.                     szText,
  88.                     szTitle,
  89.                     MB_OK | MB_ICONEXCLAMATION);
  90.             }
  91.         }
  92.         return(FALSE);
  93.     }
  94.     if (FAILED(OleInitialize(NULL)))
  95.     {
  96.         // alert the caller that OLE couldn't be initialized
  97.         TCHAR szTitle[MAX_STRING_LENGTH];
  98.         TCHAR szText[MAX_STRING_LENGTH];
  99.         if (LoadString(hInstance, IDS_ERROR, szTitle, MAX_STRING_LENGTH))
  100.         {
  101.             if (LoadString(hInstance, IDS_OLEINITFAILED, szText, MAX_STRING_LENGTH))
  102.             {
  103.                 MessageBox(
  104.                     NULL,
  105.                     szText,
  106.                     szTitle,
  107.                     MB_OK | MB_ICONEXCLAMATION);
  108.             }
  109.         }
  110.         return(FALSE);
  111.     }
  112.     if (!hPrevInstance)
  113.     {
  114.         if (!InitApplication(hInstance))
  115.         {
  116.             OleUninitialize();
  117.             return(FALSE);
  118.         }
  119.     }
  120.     CFractalWindow * pw = new CFractalWindow;
  121.     if (pw == NULL)
  122.     {
  123.         return(FALSE);
  124.     }
  125.     if (!pw->InitInstance(hInstance, nCmdShow))
  126.     {
  127.         // Note, if InitInstance has failed then it would have
  128.         // already deleted pw for me so I don't delete it here.
  129.         // This is because when WM_CREATE returns -1 (failure)
  130.         // Windows sends the WM_DESTROY message to the window
  131.         // and the the CHlprWindow class destroys itself whenever
  132.         // it receives this message.
  133.         OleUninitialize();
  134.         return(FALSE);
  135.     }
  136.     MSG msg;
  137.     HACCEL haccel = LoadAccelerators(hInstance, TEXT("AppAccel"));
  138.     if (haccel == NULL)
  139.     {
  140.         OleUninitialize();
  141.         return(FALSE);
  142.     }
  143.     while (GetMessage(&msg, NULL, 0, 0))
  144.     {
  145.         if (!TranslateAccelerator(
  146.             pw->GetHwnd(),
  147.             haccel,
  148.             &msg))
  149.         {
  150.             TranslateMessage(&msg);
  151.             DispatchMessage(&msg);
  152.         }
  153.     }
  154.     OleUninitialize();
  155.     return(msg.wParam);
  156. }
  157. //+---------------------------------------------------------------------------
  158. //
  159. //  Function:   Exists
  160. //
  161. //  Synopsis:   simple function to test for the existance of a file
  162. //
  163. //  History:    6-16-93   stevebl   Created
  164. //
  165. //----------------------------------------------------------------------------
  166. int Exists(TCHAR *sz)
  167. {
  168.     HANDLE h;
  169.     h = CreateFile(sz,
  170.         GENERIC_READ,
  171.         FILE_SHARE_READ | FILE_SHARE_WRITE,
  172.         NULL,
  173.         OPEN_EXISTING,
  174.         0,
  175.         0);
  176.     if (h != INVALID_HANDLE_VALUE)
  177.     {
  178.         CloseHandle(h);
  179.         return(1);
  180.     }
  181.     return (0);
  182. }