| 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 | return CMDIFrameWnd::PreCreateWindow(cs); | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 118 | // CMainFrame diagnostics | 
|---|
| 119 |  | 
|---|
| 120 | #ifdef _DEBUG | 
|---|
| 121 | void CMainFrame::AssertValid() const | 
|---|
| 122 | { | 
|---|
| 123 | CMDIFrameWnd::AssertValid(); | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 126 | void CMainFrame::Dump(CDumpContext& dc) const | 
|---|
| 127 | { | 
|---|
| 128 | CMDIFrameWnd::Dump(dc); | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | #endif //_DEBUG | 
|---|
| 132 |  | 
|---|
| 133 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 134 | // CMainFrame message handlers | 
|---|
| 135 |  | 
|---|
| 136 |  | 
|---|
| 137 | void CMainFrame::OnOptionsConnections() | 
|---|
| 138 | { | 
|---|
| 139 | CMDIChildWnd* pChildWnd=MDIGetActive(); | 
|---|
| 140 | CDlgConnections dlgConnections; | 
|---|
| 141 |  | 
|---|
| 142 | if (pChildWnd!=NULL){ | 
|---|
| 143 | ShowWindow(SW_SHOWNORMAL); | 
|---|
| 144 | AfxMessageBox("Close All documents before configuring connections"); | 
|---|
| 145 | return; | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | m_bConfiguringConnections=TRUE; | 
|---|
| 149 | dlgConnections.DoModal(); | 
|---|
| 150 | m_bConfiguringConnections=FALSE; | 
|---|
| 151 | } | 
|---|
| 152 |  | 
|---|
| 153 | // Handle notification from tray icon: display a message. | 
|---|
| 154 | // | 
|---|
| 155 | LRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent) | 
|---|
| 156 | { | 
|---|
| 157 |  | 
|---|
| 158 | // let tray icon do default stuff | 
|---|
| 159 | return m_trayIcon.OnTrayNotification(uID, lEvent); | 
|---|
| 160 | } | 
|---|
| 161 |  | 
|---|
| 162 |  | 
|---|
| 163 | void CMainFrame::OnTrayMain() | 
|---|
| 164 | { | 
|---|
| 165 | // The main window has been initialized, so show and update it. | 
|---|
| 166 | ShowWindow(SW_SHOWNORMAL); | 
|---|
| 167 |  | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | void CMainFrame::OnTrayConnections() | 
|---|
| 171 | { | 
|---|
| 172 |  | 
|---|
| 173 | if (m_bConfiguringConnections) { | 
|---|
| 174 | return; | 
|---|
| 175 | } | 
|---|
| 176 |  | 
|---|
| 177 | OnOptionsConnections(); | 
|---|
| 178 |  | 
|---|
| 179 |  | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 | void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus) | 
|---|
| 183 | { | 
|---|
| 184 | CMDIFrameWnd::OnShowWindow(bShow, nStatus); | 
|---|
| 185 |  | 
|---|
| 186 | // TODO: Add your message handler code here | 
|---|
| 187 |  | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | void CMainFrame::OnClose() | 
|---|
| 191 | { | 
|---|
| 192 | // TODO: Add your message handler code here and/or call default | 
|---|
| 193 | //ShowWindow(SW_HIDE); | 
|---|
| 194 | CMDIFrameWnd::OnClose(); | 
|---|
| 195 | } | 
|---|
| 196 |  | 
|---|
| 197 | void CMainFrame::OnTrayExit() | 
|---|
| 198 | { | 
|---|
| 199 | // TODO: Add your command handler code here | 
|---|
| 200 | CMDIFrameWnd::OnClose(); | 
|---|
| 201 |  | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 204 | void CMainFrame::OnSize(UINT nType, int cx, int cy) | 
|---|
| 205 | { | 
|---|
| 206 |  | 
|---|
| 207 |  | 
|---|
| 208 | CMDIFrameWnd::OnSize(nType, cx, cy); | 
|---|
| 209 |  | 
|---|
| 210 | if (SIZE_MINIMIZED==nType) { | 
|---|
| 211 | ShowWindow(SW_HIDE); | 
|---|
| 212 | m_trayIcon.SetIcon(IDR_TRAY_ICON); | 
|---|
| 213 | } | 
|---|
| 214 | else { | 
|---|
| 215 | m_trayIcon.SetIcon(NULL); | 
|---|
| 216 | } | 
|---|
| 217 |  | 
|---|
| 218 |  | 
|---|
| 219 |  | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | void CMainFrame::OnOptionsRegistertypeLibrary() | 
|---|
| 223 | { | 
|---|
| 224 |  | 
|---|
| 225 | CString sFilter; | 
|---|
| 226 |  | 
|---|
| 227 |  | 
|---|
| 228 | sFilter="Library Files (*.tlb)|*.tlb|All Files (*.*)|*.*||"; | 
|---|
| 229 |  | 
|---|
| 230 | CFileDialog  fileLib( TRUE, | 
|---|
| 231 | NULL, | 
|---|
| 232 | NULL, | 
|---|
| 233 | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, | 
|---|
| 234 | sFilter, | 
|---|
| 235 | (CWnd*)this); | 
|---|
| 236 |  | 
|---|
| 237 |  | 
|---|
| 238 | if (IDOK==fileLib.DoModal()) { | 
|---|
| 239 |  | 
|---|
| 240 | if (!RegTypeLib(fileLib.GetPathName())) { | 
|---|
| 241 |  | 
|---|
| 242 | AfxMessageBox("Library registred failed"); | 
|---|
| 243 | } | 
|---|
| 244 | else { | 
|---|
| 245 | AfxMessageBox("Library registred"); | 
|---|
| 246 | } | 
|---|
| 247 |  | 
|---|
| 248 | } | 
|---|
| 249 |  | 
|---|
| 250 |  | 
|---|
| 251 | } | 
|---|