|
|
1.1 ! root 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 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 Microsoft ! 13: // QuickHelp documentation provided with the library. ! 14: // See these sources for detailed information regarding the ! 15: // Microsoft Foundation Classes product. ! 16: ! 17: #include <afxwin.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 theApp; ! 28: ! 29: ///////////////////////////////////////////////////////////////////////////// ! 30: ! 31: // CMainWindow constructor: ! 32: // Create the window with the appropriate style, size, menu, etc. ! 33: // ! 34: CMainWindow::CMainWindow() ! 35: { ! 36: LoadAccelTable( "MainAccelTable" ); ! 37: Create( NULL, "Hello Foundation Application", ! 38: WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu" ); ! 39: } ! 40: ! 41: // OnPaint: ! 42: // This routine draws the string "Hello, Windows!" in the center of the ! 43: // client area. It is called whenever Windows sends a WM_PAINT message. ! 44: // Note that creating a CPaintDC automatically does a BeginPaint and ! 45: // an EndPaint call is done when it is destroyed at the end of this ! 46: // function. CPaintDC's constructor needs the window (this). ! 47: // ! 48: void CMainWindow::OnPaint() ! 49: { ! 50: CString s = "Hello, Windows!"; ! 51: CPaintDC dc( this ); ! 52: CRect rect; ! 53: ! 54: GetClientRect( rect ); ! 55: dc.SetTextAlign( TA_BASELINE | TA_CENTER ); ! 56: dc.SetTextColor( ::GetSysColor( COLOR_WINDOWTEXT ) ); ! 57: dc.SetBkMode(TRANSPARENT); ! 58: dc.TextOut( ( rect.right / 2 ), ( rect.bottom / 2 ), ! 59: s, s.GetLength() ); ! 60: } ! 61: ! 62: // OnAbout: ! 63: // This member function is called when a WM_COMMAND message with an ! 64: // IDM_ABOUT code is received by the CMainWindow class object. The ! 65: // message map below is responsible for this routing. ! 66: // ! 67: // We create a CModalDialog object using the "AboutBox" resource (see ! 68: // hello.rc), and invoke it. ! 69: // ! 70: void CMainWindow::OnAbout() ! 71: { ! 72: CModalDialog about( "AboutBox", this ); ! 73: about.DoModal(); ! 74: } ! 75: ! 76: // CMainWindow message map: ! 77: // Associate messages with member functions. ! 78: // ! 79: // It is implied that the ON_WM_PAINT macro expects a member function ! 80: // "void OnPaint()". ! 81: // ! 82: // It is implied that members connected with the ON_COMMAND macro ! 83: // receive no arguments and are void of return type, e.g., "void OnAbout()". ! 84: // ! 85: BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd ) ! 86: ON_WM_PAINT() ! 87: ON_COMMAND( IDM_ABOUT, OnAbout ) ! 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: TRACE( "HELLO WORLD\n" ); ! 103: ! 104: m_pMainWnd = new CMainWindow(); ! 105: m_pMainWnd->ShowWindow( m_nCmdShow ); ! 106: m_pMainWnd->UpdateWindow(); ! 107: ! 108: return TRUE; ! 109: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.