1 | // MainFrm.cpp : implementation of the CMainFrame class
|
---|
2 | //
|
---|
3 |
|
---|
4 | #include "stdafx.h"
|
---|
5 | #include "Modbucfg.h"
|
---|
6 |
|
---|
7 | #include "MainFrm.h"
|
---|
8 |
|
---|
9 | #include "Globals.h"
|
---|
10 |
|
---|
11 | #include "CommParameters.h"
|
---|
12 |
|
---|
13 | #include "DlgConnections.h"
|
---|
14 | #include "Splash.h"
|
---|
15 |
|
---|
16 | #ifdef _DEBUG
|
---|
17 | #define new DEBUG_NEW
|
---|
18 | #undef THIS_FILE
|
---|
19 | static char THIS_FILE[] = __FILE__;
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | /////////////////////////////////////////////////////////////////////////////
|
---|
23 | // CMainFrame
|
---|
24 |
|
---|
25 | // Message ID used for tray notifications
|
---|
26 | #define WM_MY_TRAY_NOTIFICATION WM_USER+0
|
---|
27 |
|
---|
28 |
|
---|
29 | IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
|
---|
30 |
|
---|
31 | BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
|
---|
32 | ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
|
---|
33 | //{{AFX_MSG_MAP(CMainFrame)
|
---|
34 | ON_WM_CREATE()
|
---|
35 | ON_COMMAND(ID_OPTIONS_CONNECTIONS, OnOptionsConnections)
|
---|
36 | ON_COMMAND(ID_TRAY_MAIN, OnTrayMain)
|
---|
37 | ON_COMMAND(ID_TRAY_CONNECTIONS, OnTrayConnections)
|
---|
38 | ON_WM_SHOWWINDOW()
|
---|
39 | ON_WM_CLOSE()
|
---|
40 | ON_COMMAND(ID_TRAY_EXIT, OnTrayExit)
|
---|
41 | ON_WM_SIZE()
|
---|
42 | ON_COMMAND(ID_OPTIONS_REGISTERTYPELIBRARY, OnOptionsRegistertypeLibrary)
|
---|
43 | //}}AFX_MSG_MAP
|
---|
44 | END_MESSAGE_MAP()
|
---|
45 |
|
---|
46 | static UINT indicators[] =
|
---|
47 | {
|
---|
48 | ID_SEPARATOR, // status line indicator
|
---|
49 | ID_INDICATOR_CAPS,
|
---|
50 | ID_INDICATOR_NUM,
|
---|
51 | ID_INDICATOR_SCRL,
|
---|
52 | };
|
---|
53 |
|
---|
54 | /////////////////////////////////////////////////////////////////////////////
|
---|
55 | // CMainFrame construction/destruction
|
---|
56 |
|
---|
57 | CMainFrame::CMainFrame(): m_trayIcon(IDR_TRAY_ICON)
|
---|
58 | {
|
---|
59 | m_bTeminate=FALSE;
|
---|
60 | m_bConfiguringConnections=FALSE;
|
---|
61 |
|
---|
62 | }
|
---|
63 |
|
---|
64 | CMainFrame::~CMainFrame()
|
---|
65 | {
|
---|
66 | }
|
---|
67 |
|
---|
68 | int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
---|
69 | {
|
---|
70 | if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
|
---|
71 | return -1;
|
---|
72 |
|
---|
73 | if (!m_wndToolBar.Create(this) ||
|
---|
74 | !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
|
---|
75 | {
|
---|
76 | TRACE0("Failed to create toolbar\n");
|
---|
77 | return -1; // fail to create
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (!m_wndStatusBar.Create(this) ||
|
---|
81 | !m_wndStatusBar.SetIndicators(indicators,
|
---|
82 | sizeof(indicators)/sizeof(UINT)))
|
---|
83 | {
|
---|
84 | TRACE0("Failed to create status bar\n");
|
---|
85 | return -1; // fail to create
|
---|
86 | }
|
---|
87 |
|
---|
88 | // TODO: Remove this if you don't want tool tips or a resizeable toolbar
|
---|
89 | m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
|
---|
90 | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
|
---|
91 |
|
---|
92 | // TODO: Delete these three lines if you don't want the toolbar to
|
---|
93 | // be dockable
|
---|
94 | m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
|
---|
95 | EnableDocking(CBRS_ALIGN_ANY);
|
---|
96 | DockControlBar(&m_wndToolBar);
|
---|
97 |
|
---|
98 | // CG: The following line was added by the Splash Screen component.
|
---|
99 | CSplashWnd::ShowSplashScreen(this);
|
---|
100 |
|
---|
101 | // Set up tray icon
|
---|
102 | m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
|
---|
103 | m_trayIcon.SetIcon(NULL);
|
---|
104 | m_bTeminate=FALSE;
|
---|
105 |
|
---|
106 | return 0;
|
---|
107 | }
|
---|
108 |
|
---|
109 | BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
|
---|
110 | {
|
---|
111 | // TODO: Modify the Window class or styles here by modifying
|
---|
112 | // the CREATESTRUCT cs
|
---|
113 |
|
---|
114 | cs.cx=1000;//j'aggrandis..
|
---|
115 | cs.cy=810;//la fenetre mère..
|
---|
116 | return CMDIFrameWnd::PreCreateWindow(cs);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /////////////////////////////////////////////////////////////////////////////
|
---|
120 | // CMainFrame diagnostics
|
---|
121 |
|
---|
122 | #ifdef _DEBUG
|
---|
123 | void CMainFrame::AssertValid() const
|
---|
124 | {
|
---|
125 | CMDIFrameWnd::AssertValid();
|
---|
126 | }
|
---|
127 |
|
---|
128 | void CMainFrame::Dump(CDumpContext& dc) const
|
---|
129 | {
|
---|
130 | CMDIFrameWnd::Dump(dc);
|
---|
131 | }
|
---|
132 |
|
---|
133 | #endif //_DEBUG
|
---|
134 |
|
---|
135 | /////////////////////////////////////////////////////////////////////////////
|
---|
136 | // CMainFrame message handlers
|
---|
137 |
|
---|
138 |
|
---|
139 | void CMainFrame::OnOptionsConnections()
|
---|
140 | {
|
---|
141 | CMDIChildWnd* pChildWnd=MDIGetActive();
|
---|
142 | CDlgConnections dlgConnections;
|
---|
143 |
|
---|
144 | if (pChildWnd!=NULL){
|
---|
145 | ShowWindow(SW_SHOWNORMAL);
|
---|
146 | AfxMessageBox("Close All documents before configuring connections");
|
---|
147 | return;
|
---|
148 | }
|
---|
149 |
|
---|
150 | m_bConfiguringConnections=TRUE;
|
---|
151 | dlgConnections.DoModal();
|
---|
152 | m_bConfiguringConnections=FALSE;
|
---|
153 | }
|
---|
154 |
|
---|
155 | // Handle notification from tray icon: display a message.
|
---|
156 | //
|
---|
157 | LRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent)
|
---|
158 | {
|
---|
159 |
|
---|
160 | // let tray icon do default stuff
|
---|
161 | return m_trayIcon.OnTrayNotification(uID, lEvent);
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | void CMainFrame::OnTrayMain()
|
---|
166 | {
|
---|
167 | // The main window has been initialized, so show and update it.
|
---|
168 | ShowWindow(SW_SHOWNORMAL);
|
---|
169 |
|
---|
170 | }
|
---|
171 |
|
---|
172 | void CMainFrame::OnTrayConnections()
|
---|
173 | {
|
---|
174 |
|
---|
175 | if (m_bConfiguringConnections) {
|
---|
176 | return;
|
---|
177 | }
|
---|
178 |
|
---|
179 | OnOptionsConnections();
|
---|
180 |
|
---|
181 |
|
---|
182 | }
|
---|
183 |
|
---|
184 | void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
|
---|
185 | {
|
---|
186 | CMDIFrameWnd::OnShowWindow(bShow, nStatus);
|
---|
187 |
|
---|
188 | // TODO: Add your message handler code here
|
---|
189 |
|
---|
190 | }
|
---|
191 |
|
---|
192 | void CMainFrame::OnClose()
|
---|
193 | {
|
---|
194 | // TODO: Add your message handler code here and/or call default
|
---|
195 | //ShowWindow(SW_HIDE);
|
---|
196 | CMDIFrameWnd::OnClose();
|
---|
197 | }
|
---|
198 |
|
---|
199 | void CMainFrame::OnTrayExit()
|
---|
200 | {
|
---|
201 | // TODO: Add your command handler code here
|
---|
202 | CMDIFrameWnd::OnClose();
|
---|
203 |
|
---|
204 | }
|
---|
205 |
|
---|
206 | void CMainFrame::OnSize(UINT nType, int cx, int cy)
|
---|
207 | {
|
---|
208 |
|
---|
209 |
|
---|
210 | CMDIFrameWnd::OnSize(nType, cx, cy);
|
---|
211 |
|
---|
212 | if (SIZE_MINIMIZED==nType) {
|
---|
213 | ShowWindow(SW_HIDE);
|
---|
214 | m_trayIcon.SetIcon(IDR_TRAY_ICON);
|
---|
215 | }
|
---|
216 | else {
|
---|
217 | m_trayIcon.SetIcon(NULL);
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 | }
|
---|
223 |
|
---|
224 | void CMainFrame::OnOptionsRegistertypeLibrary()
|
---|
225 | {
|
---|
226 |
|
---|
227 | CString sFilter;
|
---|
228 |
|
---|
229 |
|
---|
230 | sFilter="Library Files (*.tlb)|*.tlb|All Files (*.*)|*.*||";
|
---|
231 |
|
---|
232 | CFileDialog fileLib( TRUE,
|
---|
233 | NULL,
|
---|
234 | NULL,
|
---|
235 | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
|
---|
236 | sFilter,
|
---|
237 | (CWnd*)this);
|
---|
238 |
|
---|
239 |
|
---|
240 | if (IDOK==fileLib.DoModal()) {
|
---|
241 |
|
---|
242 | if (!RegTypeLib(fileLib.GetPathName())) {
|
---|
243 |
|
---|
244 | AfxMessageBox("Library registred failed");
|
---|
245 | }
|
---|
246 | else {
|
---|
247 | AfxMessageBox("Library registred");
|
---|
248 | }
|
---|
249 |
|
---|
250 | }
|
---|
251 |
|
---|
252 |
|
---|
253 | }
|
---|