Annotation of mstools/mfc/samples/dlltrace/hello1.cpp, revision 1.1.1.1

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 version of hello also demonstrates communication with
                      8: //           a dynamic link library (DLL) implemented with the
                      9: //           Microsoft Foundation Classes.
                     10: //
                     11: // This is a part of the Microsoft Foundation Classes C++ library.
                     12: // Copyright (C) 1992 Microsoft Corporation
                     13: // All rights reserved.
                     14: //
                     15: // This source code is only intended as a supplement to the
                     16: // Microsoft Foundation Classes Reference and Microsoft
                     17: // QuickHelp documentation provided with the library.
                     18: // See these sources for detailed information regarding the
                     19: // Microsoft Foundation Classes product.
                     20: 
                     21: 
                     22: #include <afxwin.h>
                     23: #include "resource.h"
                     24: 
                     25: #include "traceapi.h"
                     26: 
                     27: #ifndef _DEBUG
                     28: #error This source file must be compiled with _DEBUG defined
                     29: #endif
                     30: 
                     31: /////////////////////////////////////////////////////////////////////////////
                     32: // CMainWindow
                     33: 
                     34: class CMainWindow : public CFrameWnd
                     35: {
                     36: public:
                     37:        CMainWindow();
                     38: 
                     39:        afx_msg void OnPaint();
                     40:        afx_msg void OnAbout();
                     41:        afx_msg void OnTraceFlags();
                     42: 
                     43:        DECLARE_MESSAGE_MAP()
                     44: };
                     45: 
                     46: BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
                     47:        ON_WM_PAINT()
                     48:        ON_COMMAND(IDM_ABOUT, OnAbout)
                     49:        ON_COMMAND(IDM_TRACE_FLAGS, OnTraceFlags)
                     50: END_MESSAGE_MAP()
                     51: 
                     52: /////////////////////////////////////////////////////////////////////////////
                     53: 
                     54: CMainWindow::CMainWindow()
                     55: {
                     56:        VERIFY(Create(NULL, "Hello Foundation Application",
                     57:                WS_OVERLAPPEDWINDOW, rectDefault, NULL, "MainMenu"));
                     58: }
                     59: 
                     60: void CMainWindow::OnPaint()
                     61: {
                     62:        CString s = "Hello, Windows! (with DLL support)";
                     63:        CPaintDC dc(this);
                     64:        CRect rect;
                     65: 
                     66:        GetClientRect(rect);
                     67:        dc.SetTextAlign(TA_BASELINE | TA_CENTER);
                     68:        dc.SetBkMode(TRANSPARENT);
                     69:        dc.TextOut(rect.right / 2, rect.bottom / 2, s);
                     70: }
                     71: 
                     72: void CMainWindow::OnAbout()
                     73: {
                     74:        CModalDialog about("AboutBox", this);
                     75:        about.DoModal();
                     76: }
                     77: 
                     78: void CMainWindow::OnTraceFlags()
                     79: {
                     80:        struct TracerData data;
                     81:        data.bEnabled = afxTraceEnabled;
                     82:        data.flags = afxTraceFlags;
                     83: 
                     84:        TRACE("Calling Tracer DLL\n");
                     85:        if (PromptTraceFlags(&data))
                     86:        {
                     87:                TRACE("Changing trace flags\n");
                     88:                afxTraceEnabled = data.bEnabled;
                     89:                afxTraceFlags = data.flags;
                     90:                TRACE("Changed trace flags\n");
                     91:        }
                     92: }
                     93: 
                     94: /////////////////////////////////////////////////////////////////////////////
                     95: // CTheApp
                     96: 
                     97: class CTheApp : public CWinApp
                     98: {
                     99: public:
                    100:        virtual BOOL InitInstance();
                    101:        virtual BOOL PreTranslateMessage(MSG* pMsg);
                    102: };
                    103: 
                    104: BOOL CTheApp::InitInstance()
                    105: {
                    106:        // standard initialization of a main window
                    107: 
                    108:        m_pMainWnd = new CMainWindow;
                    109:        m_pMainWnd->ShowWindow(m_nCmdShow);
                    110:        m_pMainWnd->UpdateWindow();
                    111:        return TRUE;
                    112: }
                    113: 
                    114: BOOL CTheApp::PreTranslateMessage(MSG* pMsg)
                    115: {
                    116:        // special filter for DLL
                    117:        return (CWinApp::PreTranslateMessage(pMsg) ||
                    118:                        FilterDllMsg(pMsg));
                    119: }
                    120: 
                    121: CTheApp theApp; // application object
                    122: 
                    123: /////////////////////////////////////////////////////////////////////////////

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.