Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: winmain.cxx
  7. //
  8. // Contents: main entry point
  9. //
  10. // Classes:
  11. //
  12. // Functions: WinMain
  13. //
  14. // History: 9-30-94 stevebl Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "test.h"
  18. #include "mwclass.h"
  19. #include <ole2ver.h>
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Function: InitApplication
  23. //
  24. // Synopsis: initializes the application and registers its window class
  25. // (called once for all instances)
  26. //
  27. // Arguments: [hInstance] - handle to the first instance
  28. //
  29. // Returns: TRUE on success
  30. //
  31. // History: 4-11-94 stevebl Created for MFract
  32. // 9-30-94 stevebl Stolen from MFract
  33. //
  34. //----------------------------------------------------------------------------
  35. BOOL InitApplication(HINSTANCE hInstance)
  36. {
  37. WNDCLASS wc;
  38. wc.style = 0;
  39. wc.lpfnWndProc = &WindowProc;
  40. wc.cbClsExtra = 0;
  41. wc.cbWndExtra = 0;
  42. wc.hInstance = hInstance;
  43. wc.hCursor = (HCURSOR) LoadCursor(NULL, IDC_ARROW);
  44. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  45. wc.hIcon = LoadIcon(hInstance, TEXT("AppIcon"));
  46. wc.lpszMenuName = TEXT(MAIN_WINDOW_CLASS_MENU_STR);
  47. wc.lpszClassName = TEXT(MAIN_WINDOW_CLASS_NAME);
  48. return(RegisterClass(&wc));
  49. }
  50. //+---------------------------------------------------------------------------
  51. //
  52. // Function: WinMain
  53. //
  54. // Synopsis: main window proceedure
  55. //
  56. // Arguments: [hInstance] - instance handle
  57. // [hPrevInstance] - handle of the previous instance (if any)
  58. // [lpCmdLine] - pointer to the command line
  59. // [nCmdShow] - show state
  60. //
  61. // History: 4-11-94 stevebl Created for MFract
  62. // 9-30-94 stevebl Stolen from MFract
  63. //
  64. // Notes: initializes application and starts message loop
  65. //
  66. //----------------------------------------------------------------------------
  67. extern "C" int PASCAL WinMain(HINSTANCE hInstance,
  68. HINSTANCE hPrevInstance,
  69. LPSTR lpCmdLine,
  70. int nCmdShow)
  71. {
  72. DWORD dwBuildVersion = OleBuildVersion();
  73. if (HIWORD(dwBuildVersion) != rmm || LOWORD(dwBuildVersion) < rup)
  74. {
  75. // alert the caller that the OLE version is incompatible
  76. // with this build.
  77. MessageBoxFromStringIds(
  78. NULL,
  79. hInstance,
  80. IDS_BADOLEVERSION,
  81. IDS_ERROR,
  82. MB_OK);
  83. return(FALSE);
  84. }
  85. if (FAILED(OleInitialize(NULL)))
  86. {
  87. // alert the caller that OLE couldn't be initialized
  88. MessageBoxFromStringIds(
  89. NULL,
  90. hInstance,
  91. IDS_OLEINITFAILED,
  92. IDS_ERROR,
  93. MB_OK);
  94. return(FALSE);
  95. }
  96. if (!hPrevInstance)
  97. {
  98. if (!InitApplication(hInstance))
  99. {
  100. return(FALSE);
  101. }
  102. }
  103. CMainWindow * pw = new CMainWindow;
  104. if (pw == NULL)
  105. {
  106. return(FALSE);
  107. }
  108. if (!pw->InitInstance(hInstance, nCmdShow))
  109. {
  110. // Note, if InitInstance has failed then it would have
  111. // already deleted pw for me so I don't delete it here.
  112. // This is because when WM_CREATE returns -1 (failure)
  113. // Windows sends the WM_DESTROY message to the window
  114. // and the the CHlprWindow class destroys itself whenever
  115. // it receives this message.
  116. return(FALSE);
  117. }
  118. MSG msg;
  119. HACCEL haccel = LoadAccelerators(hInstance, TEXT("AppAccel"));
  120. if (haccel == NULL)
  121. {
  122. return(FALSE);
  123. }
  124. while (GetMessage(&msg, NULL, 0, 0))
  125. {
  126. if (!TranslateAccelerator(
  127. pw->GetHwnd(),
  128. haccel,
  129. &msg))
  130. {
  131. TranslateMessage(&msg);
  132. DispatchMessage(&msg);
  133. }
  134. }
  135. OleUninitialize();
  136. return(msg.wParam);
  137. }