home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / hello / hello.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  112 lines

  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.  
  17. #include "stdafx.h"
  18. #include "resource.h"
  19.  
  20. #include "hello.h"
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23.  
  24. // theApp:
  25. // Just creating this application object runs the whole application.
  26. //
  27. CTheApp NEAR theApp;
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30.  
  31. // CMainWindow constructor:
  32. // Create the window with the appropriate style, size, menu, etc.
  33. //
  34. CMainWindow::CMainWindow()
  35. {
  36.     LoadFrame(IDR_MAINFRAME);
  37. }
  38.  
  39. // OnPaint:
  40. // This routine draws the string "Hello, Windows!" in the center of the
  41. // client area.  It is called whenever Windows sends a WM_PAINT message.
  42. // Note that creating a CPaintDC automatically does a BeginPaint and
  43. // an EndPaint call is done when it is destroyed at the end of this
  44. // function.  CPaintDC's constructor needs the window (this).
  45. //
  46. void CMainWindow::OnPaint()
  47. {
  48.     CRect rect;
  49.     GetClientRect(rect);
  50.  
  51.     CPaintDC dc(this);
  52.     dc.SetTextAlign(TA_BASELINE | TA_CENTER);
  53.     dc.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
  54.     dc.SetBkMode(TRANSPARENT);
  55.     CString s;
  56.     s.LoadString(IDS_HELLO);
  57.     dc.TextOut((rect.right / 2), (rect.bottom / 2), s);
  58. }
  59.  
  60. // OnAbout:
  61. // This member function is called when a WM_COMMAND message with an
  62. // ID_APP_ABOUT code is received by the CMainWindow class object.   The
  63. // message map below is responsible for this routing.
  64. //
  65. // We create a ClDialog object using the "AboutBox" resource (see
  66. // hello.rc), and invoke it.
  67. //
  68. void CMainWindow::OnAbout()
  69. {
  70.     CDialog about(IDD_ABOUTBOX);
  71.     about.DoModal();
  72. }
  73.  
  74. // CMainWindow message map:
  75. // Associate messages with member functions.
  76. //
  77. // It is implied that the ON_WM_PAINT macro expects a member function
  78. // "void OnPaint()".
  79. //
  80. // It is implied that members connected with the ON_COMMAND macro
  81. // receive no arguments and are void of return type, e.g., "void OnAbout()".
  82. //
  83. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  84.     //{{AFX_MSG_MAP( CMainWindow )
  85.     ON_WM_PAINT()
  86.     ON_COMMAND(ID_APP_ABOUT, OnAbout)
  87.     //}}AFX_MSG_MAP
  88. END_MESSAGE_MAP()
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CTheApp
  92.  
  93. // InitInstance:
  94. // When any CTheApp object is created, this member function is automatically
  95. // called.  Any data may be set up at this point.
  96. //
  97. // Also, the main window of the application should be created and shown here.
  98. // Return TRUE if the initialization is successful.
  99. //
  100. BOOL CTheApp::InitInstance()
  101. {
  102.     TRACE0("CTheApp::InitInstance\n");
  103.  
  104.     Enable3dControls(); // use 3d controls in dialogs
  105.  
  106.     m_pMainWnd = new CMainWindow;
  107.     m_pMainWnd->ShowWindow(m_nCmdShow);
  108.     m_pMainWnd->UpdateWindow();
  109.  
  110.     return TRUE;
  111. }
  112.