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

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