Source code of Windows XP (NT5)
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.

111 lines
3.3 KiB

  1. // hello.cpp : Defines the class behaviors for the application.
  2. // Hello is a simple program which consists of a main window
  3. // and an "About" dialog which can be invoked by a menu choice.
  4. // It is intended to serve as a starting-point for new
  5. // applications.
  6. //
  7. // This is a part of the Microsoft Foundation Classes C++ library.
  8. // Copyright (C) 1992-1998 Microsoft Corporation
  9. // All rights reserved.
  10. //
  11. // This source code is only intended as a supplement to the
  12. // Microsoft Foundation Classes Reference and related
  13. // electronic documentation provided with the library.
  14. // See these sources for detailed information regarding the
  15. // Microsoft Foundation Classes product.
  16. #include "stdafx.h"
  17. #include "resource.h"
  18. #include "hello.h"
  19. /////////////////////////////////////////////////////////////////////////////
  20. // theApp:
  21. // Just creating this application object runs the whole application.
  22. //
  23. CTheApp NEAR theApp;
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMainWindow constructor:
  26. // Create the window with the appropriate style, size, menu, etc.
  27. //
  28. CMainWindow::CMainWindow()
  29. {
  30. LoadFrame(IDR_MAINFRAME);
  31. }
  32. // OnPaint:
  33. // This routine draws the string "Hello, Windows!" in the center of the
  34. // client area. It is called whenever Windows sends a WM_PAINT message.
  35. // Note that creating a CPaintDC automatically does a BeginPaint and
  36. // an EndPaint call is done when it is destroyed at the end of this
  37. // function. CPaintDC's constructor needs the window (this).
  38. //
  39. void CMainWindow::OnPaint()
  40. {
  41. CRect rect;
  42. GetClientRect(rect);
  43. CPaintDC dc(this);
  44. dc.SetTextAlign(TA_BASELINE | TA_CENTER);
  45. dc.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
  46. dc.SetBkMode(TRANSPARENT);
  47. CString s;
  48. s.LoadString(IDS_HELLO);
  49. dc.TextOut((rect.right / 2), (rect.bottom / 2), s);
  50. }
  51. // OnAbout:
  52. // This member function is called when a WM_COMMAND message with an
  53. // ID_APP_ABOUT code is received by the CMainWindow class object. The
  54. // message map below is responsible for this routing.
  55. //
  56. // We create a ClDialog object using the "AboutBox" resource (see
  57. // hello.rc), and invoke it.
  58. //
  59. void CMainWindow::OnAbout()
  60. {
  61. CDialog about(IDD_ABOUTBOX);
  62. about.DoModal();
  63. }
  64. // CMainWindow message map:
  65. // Associate messages with member functions.
  66. //
  67. // It is implied that the ON_WM_PAINT macro expects a member function
  68. // "void OnPaint()".
  69. //
  70. // It is implied that members connected with the ON_COMMAND macro
  71. // receive no arguments and are void of return type, e.g., "void OnAbout()".
  72. //
  73. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  74. //{{AFX_MSG_MAP( CMainWindow )
  75. ON_WM_PAINT()
  76. ON_COMMAND(ID_APP_ABOUT, OnAbout)
  77. //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CTheApp
  81. // InitInstance:
  82. // When any CTheApp object is created, this member function is automatically
  83. // called. Any data may be set up at this point.
  84. //
  85. // Also, the main window of the application should be created and shown here.
  86. // Return TRUE if the initialization is successful.
  87. //
  88. BOOL CTheApp::InitInstance()
  89. {
  90. TRACE0("CTheApp::InitInstance\n");
  91. Enable3dControls(); // use 3d controls in dialogs
  92. m_pMainWnd = new CMainWindow;
  93. m_pMainWnd->ShowWindow(m_nCmdShow);
  94. m_pMainWnd->UpdateWindow();
  95. return TRUE;
  96. }