source: trunk/XSUC/Modbucfg.cpp@ 28

Last change on this file since 28 was 11, checked in by marrucho, 12 years ago
File size: 6.4 KB
Line 
1// Modbucfg.cpp : Defines the class behaviors for the application.
2//
3
4#include "stdafx.h"
5#include "Modbucfg.h"
6#include "OleFuncs.h"
7
8#include "MainFrm.h"
9#include "ChildFrm.h"
10#include "ModbucfgDoc.h"
11#include "ModbucfgView.h"
12#include "AutoModbus.h"
13#include "Splash.h"
14
15#ifdef _DEBUG
16#define new DEBUG_NEW
17#undef THIS_FILE
18static char THIS_FILE[] = __FILE__;
19#endif
20
21CComModule _Module;
22
23/////////////////////////////////////////////////////////////////////////////
24// CModbucfgApp
25
26BEGIN_MESSAGE_MAP(CModbucfgApp, CWinApp)
27 //{{AFX_MSG_MAP(CModbucfgApp)
28 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
29 // NOTE - the ClassWizard will add and remove mapping macros here.
30 // DO NOT EDIT what you see in these blocks of generated code!
31 //}}AFX_MSG_MAP
32 // Standard file based document commands
33 ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
34 ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
35END_MESSAGE_MAP()
36
37/////////////////////////////////////////////////////////////////////////////
38// CModbucfgApp construction
39
40CModbucfgApp::CModbucfgApp()
41{
42 // TODO: add construction code here,
43 // Place all significant initialization in InitInstance
44}
45
46/////////////////////////////////////////////////////////////////////////////
47// The one and only CModbucfgApp object
48
49CModbucfgApp theApp;
50
51// This identifier was generated to be statistically unique for your app.
52// You may change it if you prefer to choose a specific identifier.
53
54// {A3BAD4A5-F5AE-11D1-8FE9-6CD504C1BC01}
55static const CLSID clsid =
56{ 0xa3bad4a5, 0xf5ae, 0x11d1, { 0x8f, 0xe9, 0x6c, 0xd5, 0x4, 0xc1, 0xbc, 0x1 } };
57
58/////////////////////////////////////////////////////////////////////////////
59// CModbucfgApp initialization
60
61BOOL CModbucfgApp::InitInstance()
62{
63
64 if (!DComOk()) {
65 AfxMessageBox(_T("DCOM OLE Not supported"),MB_SYSTEMMODAL+MB_OK);
66 return FALSE;
67 }
68
69 if (!AfxSocketInit())
70 {
71 AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
72 return FALSE;
73 }
74
75 // Initialize OLE libraries
76 if (!AfxOleInit2())
77 {
78 AfxMessageBox(IDP_OLE_INIT_FAILED);
79 return FALSE;
80 }
81
82 // Standard initialization
83 // If you are not using these features and wish to reduce the size
84 // of your final executable, you should remove from the following
85 // the specific initialization routines you do not need.
86
87#ifdef _AFXDLL
88 Enable3dControls(); // Call this when using MFC in a shared DLL
89#else
90 Enable3dControlsStatic(); // Call this when linking to MFC statically
91#endif
92
93 // Change the registry key under which our settings are stored.
94 // 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
98
99 // Register the application's document templates. Document templates
100 // serve as the connection between documents, frame windows and views.
101
102 CMultiDocTemplate* pDocTemplate;
103 pDocTemplate = new CMultiDocTemplate(
104 IDR_MODBUCTYPE,
105 RUNTIME_CLASS(CModbucfgDoc),
106 RUNTIME_CLASS(CChildFrame), // custom MDI child frame
107 RUNTIME_CLASS(CModbucfgView));
108 AddDocTemplate(pDocTemplate);
109
110 // Parse command line for standard shell commands, DDE, file open
111 CCommandLineInfo cmdInfo;
112 ParseCommandLine(cmdInfo);
113
114 CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
115
116 // create main MDI Frame window
117 CMainFrame* pMainFrame = new CMainFrame;
118 if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
119 return FALSE;
120 m_pMainWnd = pMainFrame;
121
122 // DON'T display a new MDI child window during startup!!!
123 cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
124
125 // Dispatch commands specified on the command line
126 if (!ProcessShellCommand(cmdInfo))
127 return FALSE;
128
129 // The main window has been initialized, so show and update it.
130 pMainFrame->ShowWindow(m_nCmdShow);
131 pMainFrame->UpdateWindow();
132
133 return TRUE;
134}
135
136/////////////////////////////////////////////////////////////////////////////
137// CAboutDlg dialog used for App About
138
139class CAboutDlg : public CDialog
140{
141public:
142 CAboutDlg();
143
144// Dialog Data
145 //{{AFX_DATA(CAboutDlg)
146 enum { IDD = IDD_ABOUTBOX };
147 //}}AFX_DATA
148
149 // ClassWizard generated virtual function overrides
150 //{{AFX_VIRTUAL(CAboutDlg)
151 protected:
152 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
153 //}}AFX_VIRTUAL
154
155// Implementation
156protected:
157 //{{AFX_MSG(CAboutDlg)
158 // No message handlers
159 //}}AFX_MSG
160 DECLARE_MESSAGE_MAP()
161public:
162 afx_msg void OnBnClickedOk();
163};
164
165CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
166{
167 //{{AFX_DATA_INIT(CAboutDlg)
168 //}}AFX_DATA_INIT
169}
170
171void CAboutDlg::DoDataExchange(CDataExchange* pDX)
172{
173 CDialog::DoDataExchange(pDX);
174 //{{AFX_DATA_MAP(CAboutDlg)
175 //}}AFX_DATA_MAP
176}
177
178BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
179 //{{AFX_MSG_MAP(CAboutDlg)
180 // No message handlers
181 //}}AFX_MSG_MAP
182 ON_BN_CLICKED(IDOK, OnBnClickedOk)
183END_MESSAGE_MAP()
184
185// App command to run the dialog
186void CModbucfgApp::OnAppAbout()
187{
188 CAboutDlg aboutDlg;
189 aboutDlg.DoModal();
190}
191
192/////////////////////////////////////////////////////////////////////////////
193// CModbucfgApp commands
194
195void CModbucfgApp::Test()
196{
197
198 CAutoModbus autoModbus;
199
200 autoModbus.CreateInstance("","com3");
201
202 autoModbus.ComPort(3);
203 autoModbus.BaudRate(1200);
204 autoModbus.Parity(mbNOPARITY);
205 autoModbus.Timeout(500);
206 autoModbus.TransmissionMode(mbMODE_RTU);
207
208
209
210 autoModbus.m_pIModbusSrv->put_RaiseError(VARIANT_TRUE);
211
212 if (!autoModbus.Connect()) {
213 return;
214
215 }
216
217 if (!autoModbus.LoopbackTest(1)){
218 }
219
220
221}
222
223
224BOOL CModbucfgApp::PreTranslateMessage(MSG* pMsg)
225{
226 // CG: The following lines were added by the Splash Screen component.
227 if (CSplashWnd::PreTranslateAppMessage(pMsg))
228 return TRUE;
229
230 return CWinApp::PreTranslateMessage(pMsg);
231}
232
233
234BOOL RegTypeLib(LPCSTR szTypeLibName) {
235
236 WCHAR* pwsz = new WCHAR[MAX_PATH];
237 BOOL bResp=FALSE;
238 HRESULT hRes;
239 ITypeLib* pITypeLib;
240
241 ::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTypeLibName , -1,
242 pwsz, MAX_PATH);
243
244 hRes= ::LoadTypeLib((OLECHAR FAR*)pwsz,&pITypeLib);
245
246 if FAILED(hRes){
247 bResp=FALSE;
248 }
249 else {
250 hRes = ::RegisterTypeLib((ITypeLib FAR*)pITypeLib,pwsz,NULL);
251 bResp=(S_OK==hRes);
252 pITypeLib->Release();
253 }
254
255 delete[]pwsz;
256
257 return bResp;
258}
259
260
261
262void CAboutDlg::OnBnClickedOk()
263{
264 // TODO : ajoutez ici le code de votre gestionnaire de notification de contrôle
265 OnOK();
266}
Note: See TracBrowser for help on using the repository browser.