source: trunk/MFCtooling/TestProg/TestProg.cpp @ 142

Last change on this file since 142 was 32, checked in by sherbold, 14 years ago
File size: 6.7 KB
Line 
1// TestProg.cpp : Defines the class behaviors for the application.
2//
3
4#include "stdafx.h"
5#include "TestProg.h"
6#include "MainFrm.h"
7
8#include "ChildFrm.h"
9#include "IpFrame.h"
10#include "TestProgDoc.h"
11#include "TestProgView.h"
12#include "afxwin.h"
13
14#ifdef _DEBUG
15#define new DEBUG_NEW
16#endif
17
18
19// CTestProgApp
20
21BEGIN_MESSAGE_MAP(CTestProgApp, CWinApp)
22        ON_COMMAND(ID_APP_ABOUT, &CTestProgApp::OnAppAbout)
23        // Standard file based document commands
24        ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
25        ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
26        // Standard print setup command
27        ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinApp::OnFilePrintSetup)
28END_MESSAGE_MAP()
29
30
31// CTestProgApp construction
32
33CTestProgApp::CTestProgApp()
34{
35        // TODO: add construction code here,
36        // Place all significant initialization in InitInstance
37}
38
39
40// The one and only CTestProgApp object
41
42CTestProgApp theApp;
43// This identifier was generated to be statistically unique for your app
44// You may change it if you prefer to choose a specific identifier
45
46// {81A5B9DA-E0DC-4E02-9097-38F90D423C7B}
47static const CLSID clsid =
48{ 0x81A5B9DA, 0xE0DC, 0x4E02, { 0x90, 0x97, 0x38, 0xF9, 0xD, 0x42, 0x3C, 0x7B } };
49
50
51// CTestProgApp initialization
52
53BOOL CTestProgApp::InitInstance()
54{
55        // InitCommonControlsEx() is required on Windows XP if an application
56        // manifest specifies use of ComCtl32.dll version 6 or later to enable
57        // visual styles.  Otherwise, any window creation will fail.
58        INITCOMMONCONTROLSEX InitCtrls;
59        InitCtrls.dwSize = sizeof(InitCtrls);
60        // Set this to include all the common control classes you want to use
61        // in your application.
62        InitCtrls.dwICC = ICC_WIN95_CLASSES;
63        InitCommonControlsEx(&InitCtrls);
64
65        CWinApp::InitInstance();
66
67        void (__cdecl *InitUsagelogPtr)(void) = NULL;
68       
69        hinstDll = LoadLibrary(L"userlog.dll");
70        if( hinstDll==NULL ) {
71                MessageBox(0, L"Loading of DLL failed", L"Failure", MB_OK);
72        }
73        InitUsagelogPtr = (void (*)(void)) GetProcAddress(hinstDll, "InitUsagelog");
74        if( InitUsagelogPtr==NULL ) {
75                MessageBox(0, L"Loading of InitFuncPtr failed", L"Failure", MB_OK);
76        }
77        if( InitUsagelogPtr!=NULL ) {
78                InitUsagelogPtr();
79        }
80
81
82        // Initialize OLE libraries
83        if (!AfxOleInit())
84        {
85                AfxMessageBox(IDP_OLE_INIT_FAILED);
86                return FALSE;
87        }
88        AfxEnableControlContainer();
89        // Standard initialization
90        // If you are not using these features and wish to reduce the size
91        // of your final executable, you should remove from the following
92        // the specific initialization routines you do not need
93        // Change the registry key under which our settings are stored
94        // TODO: You should modify this string to be something appropriate
95        // such as the name of your company or organization
96        SetRegistryKey(_T("Local AppWizard-Generated Applications"));
97        LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)
98        // Register the application's document templates.  Document templates
99        //  serve as the connection between documents, frame windows and views
100        CMultiDocTemplate* pDocTemplate;
101        pDocTemplate = new CMultiDocTemplate(IDR_TestProgTYPE,
102                RUNTIME_CLASS(CTestProgDoc),
103                RUNTIME_CLASS(CChildFrame), // custom MDI child frame
104                RUNTIME_CLASS(CTestProgView));
105        if (!pDocTemplate)
106                return FALSE;
107        pDocTemplate->SetContainerInfo(IDR_TestProgTYPE_CNTR_IP);
108        pDocTemplate->SetServerInfo(
109                IDR_TestProgTYPE_SRVR_EMB, IDR_TestProgTYPE_SRVR_IP,
110                RUNTIME_CLASS(CInPlaceFrame));
111        AddDocTemplate(pDocTemplate);
112        // Connect the COleTemplateServer to the document template
113        //  The COleTemplateServer creates new documents on behalf
114        //  of requesting OLE containers by using information
115        //  specified in the document template
116        m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
117        // Register all OLE server factories as running.  This enables the
118        //  OLE libraries to create objects from other applications
119        COleTemplateServer::RegisterAll();
120                // Note: MDI applications register all server objects without regard
121                //  to the /Embedding or /Automation on the command line
122
123        // create main MDI Frame window
124        CMainFrame* pMainFrame = new CMainFrame;
125        if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
126        {
127                delete pMainFrame;
128                return FALSE;
129        }
130        m_pMainWnd = pMainFrame;
131        // call DragAcceptFiles only if there's a suffix
132        //  In an MDI app, this should occur immediately after setting m_pMainWnd
133
134
135        // Parse command line for standard shell commands, DDE, file open
136        CCommandLineInfo cmdInfo;
137        ParseCommandLine(cmdInfo);
138
139        // App was launched with /Embedding or /Automation switch.
140        // Run app as automation server.
141        if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
142        {
143                // Don't show the main window
144                return TRUE;
145        }
146        // App was launched with /Unregserver or /Unregister switch.  Unregister
147        // typelibrary.  Other unregistration occurs in ProcessShellCommand().
148        else if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister)
149        {
150                m_server.UpdateRegistry(OAT_INPLACE_SERVER, NULL, NULL, FALSE);
151        }
152        // App was launched standalone or with other switches (e.g. /Register
153        // or /Regserver).  Update registry entries, including typelibrary.
154        else
155        {
156                m_server.UpdateRegistry(OAT_INPLACE_SERVER);
157        }
158
159        // Dispatch commands specified on the command line.  Will return FALSE if
160        // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
161        if (!ProcessShellCommand(cmdInfo))
162                return FALSE;
163        // The main window has been initialized, so show and update it
164        pMainFrame->ShowWindow(m_nCmdShow);
165        pMainFrame->UpdateWindow();
166
167        return TRUE;
168}
169
170
171int CTestProgApp::ExitInstance()
172{
173        //TODO: Zusätzliche Ressourcen behandeln, die Sie möglicherweise hinzugefügt haben
174        AfxOleTerm(FALSE);
175       
176        void (*ReleaseUsagelogPtr)(void) = NULL;
177               
178        ReleaseUsagelogPtr = (void (*)(void)) GetProcAddress(hinstDll, "ReleaseUsagelog");
179        if( ReleaseUsagelogPtr==NULL ) {
180                MessageBox(0, L"Loading of ReleaseFuncPtr failed", L"Failure", MB_OK);
181        }
182        if( ReleaseUsagelogPtr!=NULL ) {
183                ReleaseUsagelogPtr();
184        }
185
186        FreeLibrary(hinstDll);
187
188        return CWinApp::ExitInstance();
189}
190
191// CAboutDlg dialog used for App About
192
193class CAboutDlg : public CDialog
194{
195public:
196        CAboutDlg();
197
198// Dialog Data
199        enum { IDD = IDD_ABOUTBOX };
200
201protected:
202        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
203
204// Implementation
205protected:
206        DECLARE_MESSAGE_MAP()
207public:
208};
209
210CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
211{
212       
213}
214
215void CAboutDlg::DoDataExchange(CDataExchange* pDX)
216{
217        CDialog::DoDataExchange(pDX);
218}
219
220
221
222BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
223END_MESSAGE_MAP()
224
225// App command to run the dialog
226void CTestProgApp::OnAppAbout()
227{
228        CAboutDlg aboutDlg;
229        aboutDlg.DoModal();
230       
231}
232
233
234// CTestProgApp message handlers
235
Note: See TracBrowser for help on using the repository browser.