- Container objects can be created from GUI
[public/netxms.git] / src / console / win32 / nxcon.cpp
CommitLineData
3bf7e95e
VK
1// nxcon.cpp : Defines the class behaviors for the application.
2//
3
4#include "stdafx.h"
5#include "nxcon.h"
6
7#include "MainFrm.h"
8#include "LoginDialog.h"
6849d9be 9#include "CreateObjectDlg.h"
3bf7e95e
VK
10
11#ifdef _DEBUG
12#define new DEBUG_NEW
13#undef THIS_FILE
14static char THIS_FILE[] = __FILE__;
15#endif
16
17
34870fc0
VK
18//
19// Constants
20//
21
bfce8503 22#define LAST_APP_MENU 3
34870fc0
VK
23
24
3bf7e95e
VK
25//
26// Wrapper for client library event handler
27//
28
29static void ClientEventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
30{
31 theApp.EventHandler(dwEvent, dwCode, pArg);
32}
33
34
8e748b3e
VK
35//
36// Wrapper for client library debug callback
37//
38
39static void ClientDebugCallback(char *pszMsg)
40{
41 theApp.DebugCallback(pszMsg);
42}
43
44
3bf7e95e
VK
45//
46// CConsoleApp
47//
48
49BEGIN_MESSAGE_MAP(CConsoleApp, CWinApp)
50 //{{AFX_MSG_MAP(CConsoleApp)
51 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
52 ON_COMMAND(ID_VIEW_CONTROLPANEL, OnViewControlpanel)
53 ON_COMMAND(ID_VIEW_EVENTS, OnViewEvents)
54 ON_COMMAND(ID_VIEW_MAP, OnViewMap)
55 ON_COMMAND(ID_CONNECT_TO_SERVER, OnConnectToServer)
56 ON_COMMAND(ID_VIEW_OBJECTBROWSER, OnViewObjectbrowser)
a5f8f9b0 57 ON_COMMAND(ID_CONTROLPANEL_EVENTS, OnControlpanelEvents)
8e748b3e 58 ON_COMMAND(ID_VIEW_DEBUG, OnViewDebug)
417924d6 59 ON_COMMAND(ID_CONTROLPANEL_USERS, OnControlpanelUsers)
946d48b3 60 ON_COMMAND(ID_VIEW_NETWORKSUMMARY, OnViewNetworksummary)
34870fc0
VK
61 ON_COMMAND(ID_TOOLS_MIBBROWSER, OnToolsMibbrowser)
62 ON_COMMAND(ID_CONTROLPANEL_EVENTPOLICY, OnControlpanelEventpolicy)
ece89362 63 ON_COMMAND(ID_VIEW_ALARMS, OnViewAlarms)
bfce8503 64 ON_COMMAND(ID_FILE_SETTINGS, OnFileSettings)
925832ac 65 ON_COMMAND(ID_CONTROLPANEL_ACTIONS, OnControlpanelActions)
3bf7e95e
VK
66 //}}AFX_MSG_MAP
67END_MESSAGE_MAP()
68
69
70//
71// CConsoleApp construction
72//
73
74CConsoleApp::CConsoleApp()
75{
925832ac 76 m_bActionEditorActive = FALSE;
3bf7e95e 77 m_bCtrlPanelActive = FALSE;
ece89362 78 m_bAlarmBrowserActive = FALSE;
3bf7e95e 79 m_bEventBrowserActive = FALSE;
a5f8f9b0 80 m_bEventEditorActive = FALSE;
417924d6 81 m_bUserEditorActive = FALSE;
3bf7e95e 82 m_bObjectBrowserActive = FALSE;
8e748b3e 83 m_bDebugWindowActive = FALSE;
946d48b3 84 m_bNetSummaryActive = FALSE;
34870fc0 85 m_bEventPolicyEditorActive = FALSE;
3bf7e95e 86 m_dwClientState = STATE_DISCONNECTED;
f6915462 87 memset(m_openDCEditors, 0, sizeof(DC_EDITOR) * MAX_DC_EDITORS);
3bf7e95e
VK
88}
89
999bd324
VK
90
91//
92// CConsoleApp destruction
93//
94
95CConsoleApp::~CConsoleApp()
96{
999bd324
VK
97}
98
99
3bf7e95e
VK
100//
101// The one and only CConsoleApp object
102//
103
104CConsoleApp theApp;
105
106
34870fc0
VK
107//
108// Setup working directory
109//
110
111BOOL CConsoleApp::SetupWorkDir()
112{
113 int iLastChar;
114
115 // Get path to user's "Application Data" folder
116 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, g_szWorkDir) != S_OK)
117 {
118 AfxMessageBox(IDS_GETFOLDERPATH_FAILED, MB_OK | MB_ICONSTOP);
119 return FALSE;
120 }
121
122 // Create working directory root
123 strcat(g_szWorkDir, "\\NetXMS Console");
124 if (!CreateDirectory(g_szWorkDir, NULL))
125 if (GetLastError() != ERROR_ALREADY_EXISTS)
126 {
127 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
128 return FALSE;
129 }
130 iLastChar = strlen(g_szWorkDir);
131
132 // Create MIB cache directory
133 strcpy(&g_szWorkDir[iLastChar], WORKDIR_MIBCACHE);
134 if (!CreateDirectory(g_szWorkDir, NULL))
135 if (GetLastError() != ERROR_ALREADY_EXISTS)
136 {
137 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
138 return FALSE;
139 }
140
f70fc197
VK
141 // Create image cache directory
142 strcpy(&g_szWorkDir[iLastChar], WORKDIR_IMAGECACHE);
143 if (!CreateDirectory(g_szWorkDir, NULL))
144 if (GetLastError() != ERROR_ALREADY_EXISTS)
145 {
146 AfxMessageBox(IDS_WORKDIR_CREATION_FAILED, MB_OK | MB_ICONSTOP);
147 return FALSE;
148 }
149
34870fc0
VK
150 // Success
151 g_szWorkDir[iLastChar] = 0;
152 return TRUE;
153}
154
155
3bf7e95e
VK
156//
157// CConsoleApp initialization
158//
159
160BOOL CConsoleApp::InitInstance()
161{
162 BOOL bSetWindowPos;
163 DWORD dwBytes;
164 BYTE *pData;
8e748b3e 165 HMENU hMenu;
3bf7e95e 166
34870fc0
VK
167 // Setup our working directory
168 if (!SetupWorkDir())
169 return FALSE;
170
3bf7e95e
VK
171 if (!AfxSocketInit())
172 {
173 AfxMessageBox(IDP_SOCKETS_INIT_FAILED, MB_OK | MB_ICONSTOP);
174 return FALSE;
175 }
176
177 if (!NXCInitialize())
178 {
179 AfxMessageBox(IDS_NXC_INIT_FAILED, MB_OK | MB_ICONSTOP);
180 return FALSE;
181 }
182 NXCSetEventHandler(ClientEventHandler);
183
184 AfxEnableControlContainer();
185
186 // Standard initialization
187 // If you are not using these features and wish to reduce the size
188 // of your final executable, you should remove from the following
189 // the specific initialization routines you do not need.
190
191#ifdef _AFXDLL
192 Enable3dControls(); // Call this when using MFC in a shared DLL
193#else
194 Enable3dControlsStatic(); // Call this when linking to MFC statically
195#endif
196
197 // Change the registry key under which our settings are stored.
198 SetRegistryKey(_T("NetXMS"));
199
bfce8503
VK
200 // Load configuration from registry
201 dwBytes = sizeof(WINDOWPLACEMENT);
202 bSetWindowPos = GetProfileBinary(_T("General"), _T("WindowPlacement"),
203 &pData, (UINT *)&dwBytes);
204 g_dwOptions = GetProfileInt(_T("General"), _T("Options"), 0);
205 strcpy(g_szServer, (LPCTSTR)GetProfileString(_T("Connection"), _T("Server"), _T("localhost")));
206 strcpy(g_szLogin, (LPCTSTR)GetProfileString(_T("Connection"), _T("Login"), NULL));
8c290af0 207 g_dwEncryptionMethod = GetProfileInt(_T("Connection"), _T("Encryption"), CSCP_ENCRYPTION_NONE);
bfce8503 208
c7863da1
VK
209 // Create mutex for action list access
210 g_mutexActionListAccess = CreateMutex(NULL, FALSE, NULL);
211
3bf7e95e
VK
212 // To create the main window, this code creates a new frame window
213 // object and then sets it as the application's main window object.
3bf7e95e
VK
214 CMDIFrameWnd* pFrame = new CMainFrame;
215 m_pMainWnd = pFrame;
216
217 // create main MDI frame window
218 if (!pFrame->LoadFrame(IDR_MAINFRAME))
219 return FALSE;
220
790cd256
VK
221 // Load context menus
222 if (!m_ctxMenu.LoadMenu(IDM_CONTEXT))
223 MessageBox(NULL, "FAILED", "", 0);
224
8e748b3e
VK
225 // Load shared MDI menus and accelerator table
226 HINSTANCE hInstance = AfxGetResourceHandle();
227
228 hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDM_VIEW_SPECIFIC));
229
bfce8503
VK
230 // Modify application menu as needed
231 if (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL)
232 {
233 pFrame->GetMenu()->RemoveMenu(ID_VIEW_CONTROLPANEL, MF_BYCOMMAND);
234 pFrame->GetMenu()->InsertMenu(ID_VIEW_DEBUG, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 8), "&Control panel");
235 }
236
a0fcaaf6 237 m_hMDIMenu = LoadAppMenu(hMenu);
34870fc0 238 InsertMenu(m_hMDIMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
8e748b3e 239
a0fcaaf6 240 m_hEventBrowserMenu = LoadAppMenu(hMenu);
34870fc0
VK
241 InsertMenu(m_hEventBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
242 InsertMenu(m_hEventBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 1), "&Event");
8e748b3e 243
a0fcaaf6 244 m_hObjectBrowserMenu = LoadAppMenu(hMenu);
34870fc0
VK
245 InsertMenu(m_hObjectBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
246 InsertMenu(m_hObjectBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 2), "&Object");
2060ba91 247
a0fcaaf6 248 m_hUserEditorMenu = LoadAppMenu(hMenu);
34870fc0
VK
249 InsertMenu(m_hUserEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
250 InsertMenu(m_hUserEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 3), "&User");
cad81e33 251
a0fcaaf6 252 m_hDCEditorMenu = LoadAppMenu(hMenu);
34870fc0
VK
253 InsertMenu(m_hDCEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
254 InsertMenu(m_hDCEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 4), "&Item");
1c0c8dde 255
a0fcaaf6 256 m_hPolicyEditorMenu = LoadAppMenu(hMenu);
ef44d5ea
VK
257 InsertMenu(m_hPolicyEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
258 InsertMenu(m_hPolicyEditorMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 5), "&Policy");
259
a0fcaaf6 260 m_hAlarmBrowserMenu = LoadAppMenu(hMenu);
5cac98d8
VK
261 InsertMenu(m_hAlarmBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 0), "&Window");
262 InsertMenu(m_hAlarmBrowserMenu, LAST_APP_MENU, MF_BYPOSITION | MF_POPUP, (UINT_PTR)GetSubMenu(hMenu, 6), "&Alarm");
263
8e748b3e 264 m_hMDIAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
5cac98d8 265 m_hAlarmBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_ALARM_BROWSER));
8e748b3e 266 m_hEventBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
2060ba91 267 m_hObjectBrowserAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_OBJECT_BROWSER));
cad81e33 268 m_hUserEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
1c0c8dde 269 m_hDCEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_MDI_DEFAULT));
ef44d5ea 270 m_hPolicyEditorAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDA_EPP));
3bf7e95e 271
3bf7e95e
VK
272 // The main window has been initialized, so show and update it.
273 if (bSetWindowPos)
274 {
275 pFrame->SetWindowPlacement((WINDOWPLACEMENT *)pData);
276 if (pFrame->IsIconic())
277 pFrame->ShowWindow(SW_RESTORE);
278 }
279 else
280 {
281 pFrame->ShowWindow(m_nCmdShow);
282 }
283 pFrame->UpdateWindow();
34870fc0 284 //pFrame->PostMessage(WM_COMMAND, ID_VIEW_DEBUG, 0);
3bf7e95e
VK
285 pFrame->PostMessage(WM_COMMAND, ID_CONNECT_TO_SERVER, 0);
286
287 return TRUE;
288}
289
290/////////////////////////////////////////////////////////////////////////////
291// CConsoleApp message handlers
292
293int CConsoleApp::ExitInstance()
294{
8e748b3e
VK
295 NXCSetDebugCallback(NULL);
296 NXCDisconnect();
9cf2ab6f 297 NXCShutdown();
6849d9be 298 NXCDestroyCCList(g_pCCList);
8e748b3e 299
bfce8503
VK
300 // Save configuration
301 WriteProfileInt(_T("General"), _T("Options"), g_dwOptions);
302
3bf7e95e 303 // Free resources
8e748b3e
VK
304 SafeFreeResource(m_hMDIMenu);
305 SafeFreeResource(m_hMDIAccel);
5cac98d8
VK
306 SafeFreeResource(m_hAlarmBrowserMenu);
307 SafeFreeResource(m_hAlarmBrowserAccel);
8e748b3e
VK
308 SafeFreeResource(m_hEventBrowserMenu);
309 SafeFreeResource(m_hEventBrowserAccel);
1c0c8dde
VK
310 SafeFreeResource(m_hUserEditorMenu);
311 SafeFreeResource(m_hUserEditorAccel);
312 SafeFreeResource(m_hDCEditorMenu);
313 SafeFreeResource(m_hDCEditorAccel);
3bf7e95e 314
c7863da1
VK
315 CloseHandle(g_mutexActionListAccess);
316
cc068873 317 return CWinApp::ExitInstance();
3bf7e95e
VK
318}
319
320
321/////////////////////////////////////////////////////////////////////////////
322// CAboutDlg dialog used for App About
323
324class CAboutDlg : public CDialog
325{
326public:
327 CAboutDlg();
328
329// Dialog Data
330 //{{AFX_DATA(CAboutDlg)
331 enum { IDD = IDD_ABOUTBOX };
332 //}}AFX_DATA
333
334 // ClassWizard generated virtual function overrides
335 //{{AFX_VIRTUAL(CAboutDlg)
336 protected:
337 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
338 //}}AFX_VIRTUAL
339
340// Implementation
341protected:
342 //{{AFX_MSG(CAboutDlg)
343 // No message handlers
344 //}}AFX_MSG
345 DECLARE_MESSAGE_MAP()
346};
347
348CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
349{
350 //{{AFX_DATA_INIT(CAboutDlg)
351 //}}AFX_DATA_INIT
352}
353
354void CAboutDlg::DoDataExchange(CDataExchange* pDX)
355{
356 CDialog::DoDataExchange(pDX);
357 //{{AFX_DATA_MAP(CAboutDlg)
358 //}}AFX_DATA_MAP
359}
360
361BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
362 //{{AFX_MSG_MAP(CAboutDlg)
363 // No message handlers
364 //}}AFX_MSG_MAP
365END_MESSAGE_MAP()
366
367// App command to run the dialog
368void CConsoleApp::OnAppAbout()
369{
370 CAboutDlg aboutDlg;
371 aboutDlg.DoModal();
372}
373
374/////////////////////////////////////////////////////////////////////////////
375// CConsoleApp message handlers
376
377
378void CConsoleApp::OnViewControlpanel()
379{
380 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
381
382 // create a new MDI child window or open existing
383 if (m_bCtrlPanelActive)
384 m_pwndCtrlPanel->BringWindowToTop();
385 else
386 pFrame->CreateNewChild(
8e748b3e 387 RUNTIME_CLASS(CControlPanel), IDR_CTRLPANEL, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
388}
389
390
391//
392// This method called when new view is created
393//
394
f6915462 395void CConsoleApp::OnViewCreate(DWORD dwView, CWnd *pWnd, DWORD dwArg)
3bf7e95e 396{
f6915462
VK
397 DWORD i;
398
3bf7e95e
VK
399 switch(dwView)
400 {
401 case IDR_CTRLPANEL:
402 m_bCtrlPanelActive = TRUE;
403 m_pwndCtrlPanel = pWnd;
404 break;
ece89362
VK
405 case IDR_ALARMS:
406 m_bAlarmBrowserActive = TRUE;
407 m_pwndAlarmBrowser = (CAlarmBrowser *)pWnd;
408 break;
3bf7e95e
VK
409 case IDR_EVENTS:
410 m_bEventBrowserActive = TRUE;
411 m_pwndEventBrowser = (CEventBrowser *)pWnd;
412 break;
413 case IDR_OBJECTS:
414 m_bObjectBrowserActive = TRUE;
415 m_pwndObjectBrowser = pWnd;
416 break;
a5f8f9b0
VK
417 case IDR_EVENT_EDITOR:
418 m_bEventEditorActive = TRUE;
419 m_pwndEventEditor = (CEventEditor *)pWnd;
420 break;
925832ac
VK
421 case IDR_ACTION_EDITOR:
422 m_bActionEditorActive = TRUE;
423 m_pwndActionEditor = (CActionEditor *)pWnd;
424 break;
417924d6
VK
425 case IDR_USER_EDITOR:
426 m_bUserEditorActive = TRUE;
427 m_pwndUserEditor = (CUserEditor *)pWnd;
428 break;
8e748b3e
VK
429 case IDR_DEBUG_WINDOW:
430 m_bDebugWindowActive = TRUE;
431 m_pwndDebugWindow = (CDebugFrame *)pWnd;
432 NXCSetDebugCallback(ClientDebugCallback);
433 break;
946d48b3
VK
434 case IDR_NETWORK_SUMMARY:
435 m_bNetSummaryActive = TRUE;
436 m_pwndNetSummary = (CNetSummaryFrame *)pWnd;
437 break;
f6915462
VK
438 case IDR_DC_EDITOR:
439 // Register new DC editor
440 for(i = 0; i < MAX_DC_EDITORS; i++)
441 if (m_openDCEditors[i].pWnd == NULL)
442 {
443 m_openDCEditors[i].pWnd = pWnd;
444 m_openDCEditors[i].dwNodeId = dwArg;
445 break;
446 }
447 break;
34870fc0
VK
448 case IDR_EPP_EDITOR:
449 m_bEventPolicyEditorActive = TRUE;
450 m_pwndEventPolicyEditor = (CEventPolicyEditor *)pWnd;
451 break;
3bf7e95e
VK
452 default:
453 break;
454 }
455}
456
457
458//
459// This method called when view is destroyed
460//
461
f6915462 462void CConsoleApp::OnViewDestroy(DWORD dwView, CWnd *pWnd, DWORD dwArg)
3bf7e95e 463{
f6915462
VK
464 DWORD i;
465
3bf7e95e
VK
466 switch(dwView)
467 {
468 case IDR_CTRLPANEL:
469 m_bCtrlPanelActive = FALSE;
470 break;
ece89362
VK
471 case IDR_ALARMS:
472 m_bAlarmBrowserActive = FALSE;
473 break;
3bf7e95e
VK
474 case IDR_EVENTS:
475 m_bEventBrowserActive = FALSE;
476 break;
477 case IDR_OBJECTS:
478 m_bObjectBrowserActive = FALSE;
479 break;
a5f8f9b0
VK
480 case IDR_EVENT_EDITOR:
481 m_bEventEditorActive = FALSE;
482 break;
925832ac
VK
483 case IDR_ACTION_EDITOR:
484 m_bActionEditorActive = FALSE;
485 break;
417924d6
VK
486 case IDR_USER_EDITOR:
487 m_bUserEditorActive = FALSE;
488 break;
8e748b3e
VK
489 case IDR_DEBUG_WINDOW:
490 m_bDebugWindowActive = FALSE;
491 NXCSetDebugCallback(NULL);
492 break;
946d48b3
VK
493 case IDR_NETWORK_SUMMARY:
494 m_bNetSummaryActive = FALSE;
495 break;
f6915462
VK
496 case IDR_DC_EDITOR:
497 // Unregister DC editor
498 for(i = 0; i < MAX_DC_EDITORS; i++)
499 if (m_openDCEditors[i].pWnd == pWnd)
500 {
501 m_openDCEditors[i].pWnd = NULL;
502 m_openDCEditors[i].dwNodeId = 0;
503 break;
504 }
505 break;
34870fc0
VK
506 case IDR_EPP_EDITOR:
507 m_bEventPolicyEditorActive = FALSE;
508 break;
3bf7e95e
VK
509 default:
510 break;
511 }
512}
513
7ac0c0a8
VK
514
515//
516// WM_COMMAND::ID_VIEW_EVENTS message handler
517//
518
3bf7e95e
VK
519void CConsoleApp::OnViewEvents()
520{
521 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
522
523 // create a new MDI child window or open existing
524 if (m_bEventBrowserActive)
525 m_pwndEventBrowser->BringWindowToTop();
526 else
527 pFrame->CreateNewChild(
8e748b3e 528 RUNTIME_CLASS(CEventBrowser), IDR_EVENTS, m_hEventBrowserMenu, m_hEventBrowserAccel);
3bf7e95e
VK
529}
530
7ac0c0a8
VK
531
532//
533// WM_COMMAND::ID_VIEW_MAP message handler
534//
535
3bf7e95e
VK
536void CConsoleApp::OnViewMap()
537{
538 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
539
540 // create a new MDI child window
f7a7f8e4 541 pFrame->CreateNewChild(RUNTIME_CLASS(CMapFrame), IDR_MAPFRAME, m_hMDIMenu, m_hMDIAccel);
3bf7e95e
VK
542}
543
7ac0c0a8
VK
544
545//
546// WM_COMMAND::ID_CONNECT_TO_SERVER message handler
547//
548
3bf7e95e
VK
549void CConsoleApp::OnConnectToServer()
550{
551 CLoginDialog dlgLogin;
f7a7f8e4 552 DWORD dwResult;
3bf7e95e
VK
553
554 dlgLogin.m_szServer = g_szServer;
555 dlgLogin.m_szLogin = g_szLogin;
8c290af0 556 dlgLogin.m_iEncryption = g_dwEncryptionMethod;
f7a7f8e4 557 do
3bf7e95e
VK
558 {
559 if (dlgLogin.DoModal() != IDOK)
560 {
561 PostQuitMessage(1);
562 break;
563 }
564 strcpy(g_szServer, (LPCTSTR)dlgLogin.m_szServer);
565 strcpy(g_szLogin, (LPCTSTR)dlgLogin.m_szLogin);
566 strcpy(g_szPassword, (LPCTSTR)dlgLogin.m_szPassword);
8c290af0 567 g_dwEncryptionMethod = dlgLogin.m_iEncryption;
3bf7e95e
VK
568
569 // Save last connection parameters
570 WriteProfileString(_T("Connection"), _T("Server"), g_szServer);
571 WriteProfileString(_T("Connection"), _T("Login"), g_szLogin);
8c290af0 572 WriteProfileInt(_T("Connection"), _T("Encryption"), g_dwEncryptionMethod);
3bf7e95e
VK
573
574 // Initiate connection
f7a7f8e4
VK
575 dwResult = DoLogin();
576 if (dwResult != RCC_SUCCESS)
7ac0c0a8 577 ErrorBox(dwResult, "Unable to connect: %s", "Connection error");
3bf7e95e 578 }
f7a7f8e4 579 while(dwResult != RCC_SUCCESS);
3bf7e95e
VK
580}
581
7ac0c0a8
VK
582
583//
584// WM_COMMAND::ID_VIEW_OBJECTBROWSER message handler
585//
586
3bf7e95e
VK
587void CConsoleApp::OnViewObjectbrowser()
588{
589 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
590
591 // create a new MDI child window or open existing
592 if (m_bObjectBrowserActive)
593 m_pwndObjectBrowser->BringWindowToTop();
594 else
595 pFrame->CreateNewChild(
2060ba91 596 RUNTIME_CLASS(CObjectBrowser), IDR_OBJECTS, m_hObjectBrowserMenu, m_hObjectBrowserAccel);
3bf7e95e
VK
597}
598
599
600//
601// Event handler for client libray events
602//
603
604void CConsoleApp::EventHandler(DWORD dwEvent, DWORD dwCode, void *pArg)
605{
3bf7e95e
VK
606 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
607
608 switch(dwEvent)
609 {
610 case NXC_EVENT_STATE_CHANGED:
3bf7e95e 611 m_dwClientState = dwCode;
9cf2ab6f 612 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_STATE_CHANGE, dwCode, (LPARAM)pArg);
3bf7e95e 613 break;
3bf7e95e
VK
614 case NXC_EVENT_NEW_ELOG_RECORD:
615 if (m_bEventBrowserActive)
616 m_pwndEventBrowser->AddEvent((NXC_EVENT *)pArg);
9d72bde1 617 free(pArg);
3bf7e95e 618 break;
89d4d2a2
VK
619 case NXC_EVENT_OBJECT_CHANGED:
620 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_OBJECT_CHANGE, dwCode, (LPARAM)pArg);
621 break;
fadbdf37
VK
622 case NXC_EVENT_USER_DB_CHANGED:
623 ((CMainFrame *)m_pMainWnd)->PostMessage(WM_USERDB_CHANGE, dwCode, (LPARAM)pArg);
624 break;
3421c063
VK
625 case NXC_EVENT_NOTIFICATION:
626 switch(dwCode)
627 {
628 case NX_NOTIFY_SHUTDOWN:
629 m_pMainWnd->MessageBox("Server was shutdown", "Warning", MB_OK | MB_ICONSTOP);
630 PostQuitMessage(0);
631 break;
632 case NX_NOTIFY_EVENTDB_CHANGED:
633 m_pMainWnd->PostMessage(WM_COMMAND, ID_UPDATE_EVENT_LIST, 0);
634 break;
a10722f0
VK
635 case NX_NOTIFY_NEW_ALARM:
636 case NX_NOTIFY_ALARM_DELETED:
637 case NX_NOTIFY_ALARM_ACKNOWLEGED:
638 m_pMainWnd->PostMessage(WM_ALARM_UPDATE, dwCode,
639 (LPARAM)nx_memdup(pArg, sizeof(NXC_ALARM)));
640 break;
8c290af0
VK
641 case NX_NOTIFY_ACTION_CREATED:
642 case NX_NOTIFY_ACTION_MODIFIED:
643 case NX_NOTIFY_ACTION_DELETED:
644 UpdateActions(dwCode, (NXC_ACTION *)pArg);
645 break;
3421c063
VK
646 default:
647 break;
648 }
649 break;
3bf7e95e
VK
650 default:
651 break;
652 }
653}
a5f8f9b0 654
999bd324
VK
655
656//
657// Handler for WM_COMMAND(ID_CONTROLPANEL_EVENTS) message
658//
659
a5f8f9b0
VK
660void CConsoleApp::OnControlpanelEvents()
661{
662 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
663
664 // create a new MDI child window or open existing
665 if (m_bEventEditorActive)
666 m_pwndEventEditor->BringWindowToTop();
667 else
417924d6
VK
668 {
669 DWORD dwResult;
670
f7a7f8e4 671 dwResult = DoRequest(NXCOpenEventDB, "Opening event configuration database...");
417924d6
VK
672 if (dwResult == RCC_SUCCESS)
673 {
674 pFrame->CreateNewChild(
675 RUNTIME_CLASS(CEventEditor), IDR_EVENT_EDITOR, m_hMDIMenu, m_hMDIAccel);
676 }
677 else
678 {
7ac0c0a8 679 ErrorBox(dwResult, "Unable to open event configuration database:\n%s");
417924d6
VK
680 }
681 }
682}
683
684
685//
7ac0c0a8 686// Handler for WM_COMMAND::ID_CONTROLPANEL_USERS message
417924d6
VK
687//
688
689void CConsoleApp::OnControlpanelUsers()
690{
691 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
692
693 // create a new MDI child window or open existing
694 if (m_bUserEditorActive)
695 m_pwndUserEditor->BringWindowToTop();
696 else
697 {
698 DWORD dwResult;
699
f7a7f8e4 700 dwResult = DoRequest(NXCLockUserDB, "Locking user database...");
417924d6
VK
701 if (dwResult == RCC_SUCCESS)
702 {
703 pFrame->CreateNewChild(
cad81e33 704 RUNTIME_CLASS(CUserEditor), IDR_USER_EDITOR, m_hUserEditorMenu, m_hUserEditorAccel);
417924d6
VK
705 }
706 else
707 {
7ac0c0a8 708 ErrorBox(dwResult, "Unable to lock user database:\n%s");
417924d6
VK
709 }
710 }
a5f8f9b0
VK
711}
712
713
8e748b3e
VK
714//
715// Handler for WM_COMMAND::ID_VIEW_DEBUG message
716//
717
718void CConsoleApp::OnViewDebug()
719{
720 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
721
722 // create a new MDI child window or open existing
723 if (m_bDebugWindowActive)
724 m_pwndDebugWindow->BringWindowToTop();
725 else
726 pFrame->CreateNewChild(
727 RUNTIME_CLASS(CDebugFrame), IDR_DEBUG_WINDOW, m_hMDIMenu, m_hMDIAccel);
728}
89d4d2a2
VK
729
730
731//
732// Print debug information
733//
734
735void CConsoleApp::DebugPrintf(char *szFormat, ...)
736{
737 if (m_bDebugWindowActive)
738 {
739 char szBuffer[1024];
740 va_list args;
741
742 va_start(args, szFormat);
743 vsprintf(szBuffer, szFormat, args);
744 va_end(args);
745
746 m_pwndDebugWindow->AddMessage(szBuffer);
747 }
748}
2057008d
VK
749
750
751//
752// Edit properties of specific object
753//
754
755void CConsoleApp::ObjectProperties(DWORD dwObjectId)
756{
757 CObjectPropSheet wndPropSheet("Object Properties", GetMainWnd(), 0);
758 CNodePropsGeneral wndNodeGeneral;
8e2809bb 759 CObjectPropsGeneral wndObjectGeneral;
2057008d 760 CObjectPropCaps wndObjectCaps;
8e2809bb 761 CObjectPropsSecurity wndObjectSecurity;
2a41a4b5 762 CObjectPropsPresentation wndObjectPresentation;
2057008d
VK
763 NXC_OBJECT *pObject;
764 char szBuffer[32];
765
766 pObject = NXCFindObjectById(dwObjectId);
767 if (pObject != NULL)
768 {
769 // Create "General" tab
8e2809bb 770 if (pObject->iClass == OBJECT_NODE)
2057008d 771 {
8e2809bb
VK
772 wndNodeGeneral.m_dwObjectId = dwObjectId;
773 wndNodeGeneral.m_strName = pObject->szName;
774 wndNodeGeneral.m_strOID = pObject->node.szObjectId;
775 wndNodeGeneral.m_strPrimaryIp = IpToStr(pObject->dwIpAddr, szBuffer);
776 wndNodeGeneral.m_iAgentPort = (int)pObject->node.wAgentPort;
777 wndNodeGeneral.m_strCommunity = pObject->node.szCommunityString;
778 wndNodeGeneral.m_iAuthType = pObject->node.wAuthMethod;
779 wndNodeGeneral.m_strSecret = pObject->node.szSharedSecret;
780 wndPropSheet.AddPage(&wndNodeGeneral);
781 }
782 else
783 {
784 wndObjectGeneral.m_dwObjectId = dwObjectId;
785 wndObjectGeneral.m_strClass = g_szObjectClass[pObject->iClass];
786 wndObjectGeneral.m_strName = pObject->szName;
787 wndPropSheet.AddPage(&wndObjectGeneral);
2057008d
VK
788 }
789
790 // Create tabs specific for node objects
791 if (pObject->iClass == OBJECT_NODE)
792 {
793 // Create "Capabilities" tab
794 wndObjectCaps.m_pObject = pObject;
795 wndPropSheet.AddPage(&wndObjectCaps);
796 }
797
f6d9527a 798 // Create "Security" tab
8e2809bb
VK
799 wndObjectSecurity.m_pObject = pObject;
800 wndObjectSecurity.m_bInheritRights = pObject->bInheritRights;
801 wndPropSheet.AddPage(&wndObjectSecurity);
f6d9527a 802
2a41a4b5
VK
803 // Create "Presentation" tab
804 wndObjectPresentation.m_dwImageId = pObject->dwImage;
805 wndObjectPresentation.m_bUseDefaultImage = (pObject->dwImage == IMG_DEFAULT);
806 wndPropSheet.AddPage(&wndObjectPresentation);
807
f6d9527a
VK
808 wndPropSheet.SetObject(pObject);
809 if (wndPropSheet.DoModal() == IDOK)
810 wndPropSheet.SaveObjectChanges();
2057008d
VK
811 }
812}
790cd256
VK
813
814
815//
816// Get context menu
817//
818
819CMenu *CConsoleApp::GetContextMenu(int iIndex)
820{
821 return m_ctxMenu.GetSubMenu(iIndex);
822}
946d48b3
VK
823
824
825//
826// Start data collection editor for specific object
827//
828
829void CConsoleApp::StartObjectDCEditor(NXC_OBJECT *pObject)
830{
223ffcfa
VK
831 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
832 NXC_DCI_LIST *pItemList;
833 DWORD dwResult;
f6915462 834 CDataCollectionEditor *pWnd;
946d48b3 835
f6915462
VK
836 pWnd = (CDataCollectionEditor *)FindOpenDCEditor(pObject->dwId);
837 if (pWnd == NULL)
223ffcfa 838 {
f6915462
VK
839 dwResult = DoRequestArg2(NXCOpenNodeDCIList, (void *)pObject->dwId,
840 &pItemList, "Loading node's data collection information...");
841 if (dwResult == RCC_SUCCESS)
842 {
843 CCreateContext context;
844
845 pWnd = new CDataCollectionEditor(pItemList);
846
847 // load the frame
848 context.m_pCurrentFrame = pFrame;
849
850 if (pWnd->LoadFrame(IDR_DC_EDITOR, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
851 {
852 CString strFullString, strTitle;
853
854 if (strFullString.LoadString(IDR_DC_EDITOR))
855 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
856
857 // add node name to title
858 strTitle += " - [";
859 strTitle += pObject->szName;
860 strTitle += "]";
861
862 // set the handles and redraw the frame and parent
1c0c8dde 863 pWnd->SetHandles(m_hDCEditorMenu, m_hDCEditorAccel);
f6915462
VK
864 pWnd->SetTitle(strTitle);
865 pWnd->InitialUpdateFrame(NULL, TRUE);
866 }
867 else
868 {
869 delete pWnd;
870 }
871 }
872 else
873 {
7ac0c0a8 874 ErrorBox(dwResult, "Unable to load data collection information for node:\n%s");
f6915462 875 }
223ffcfa
VK
876 }
877 else
878 {
f6915462
VK
879 // Data collection editor already open, activate it
880 pWnd->BringWindowToTop();
223ffcfa 881 }
946d48b3
VK
882}
883
884
885//
886// Show network summary view
887//
888
889void CConsoleApp::OnViewNetworksummary()
890{
891 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
892
893 // create a new MDI child window or open existing
894 if (m_bNetSummaryActive)
895 m_pwndNetSummary->BringWindowToTop();
896 else
897 pFrame->CreateNewChild(
898 RUNTIME_CLASS(CNetSummaryFrame), IDR_NETWORK_SUMMARY, m_hMDIMenu, m_hMDIAccel);
899}
223ffcfa
VK
900
901
902//
903// Set object's management status
904//
905
906void CConsoleApp::SetObjectMgmtStatus(NXC_OBJECT *pObject, BOOL bIsManaged)
907{
908 DWORD dwResult;
909
910 dwResult = DoRequestArg2(NXCSetObjectMgmtStatus, (void *)pObject->dwId,
911 (void *)bIsManaged, "Changing object status...");
912 if (dwResult != RCC_SUCCESS)
913 {
914 char szBuffer[256];
915
916 sprintf(szBuffer, "Unable to change management status for object %s:\n%s",
917 pObject->szName, NXCGetErrorText(dwResult));
918 GetMainWnd()->MessageBox(szBuffer, "Error", MB_ICONSTOP);
919 }
920}
f6915462
VK
921
922
923//
924// Find open data collection editor for given node, if any
925//
926
927CWnd *CConsoleApp::FindOpenDCEditor(DWORD dwNodeId)
928{
929 DWORD i;
930
931 for(i = 0; i < MAX_DC_EDITORS; i++)
932 if (m_openDCEditors[i].dwNodeId == dwNodeId)
933 return m_openDCEditors[i].pWnd;
934 return NULL;
935}
7ac0c0a8
VK
936
937
938//
939// Display message box with error text from client library
940//
941
942void CConsoleApp::ErrorBox(DWORD dwError, char *pszMessage, char *pszTitle)
943{
944 char szBuffer[512];
945
946 sprintf(szBuffer, (pszMessage != NULL) ? pszMessage : "Error: %s",
947 NXCGetErrorText(dwError));
948 m_pMainWnd->MessageBox(szBuffer, (pszTitle != NULL) ? pszTitle : "Error", MB_ICONSTOP);
949}
9f20696e
VK
950
951
952//
953// Show window with DCI's data
954//
955
956void CConsoleApp::ShowDCIData(DWORD dwNodeId, DWORD dwItemId, char *pszItemName)
957{
958 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
959 CCreateContext context;
960 CDCIDataView *pWnd;
961
962 pWnd = new CDCIDataView(dwNodeId, dwItemId);
963
964 // load the frame
965 context.m_pCurrentFrame = pFrame;
966
967 if (pWnd->LoadFrame(IDR_DCI_DATA_VIEW, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
968 {
969 CString strFullString, strTitle;
970
971 if (strFullString.LoadString(IDR_DCI_DATA_VIEW))
972 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
973
974 // add node name to title
975 strTitle += " - [";
976 strTitle += pszItemName;
977 strTitle += "]";
978
979 // set the handles and redraw the frame and parent
980 pWnd->SetHandles(m_hMDIMenu, m_hMDIAccel);
981 pWnd->SetTitle(strTitle);
982 pWnd->InitialUpdateFrame(NULL, TRUE);
983 }
984 else
985 {
986 delete pWnd;
987 }
988}
989
990
991//
23e62c09 992// Show graph for collected data
9f20696e
VK
993//
994
23e62c09 995void CConsoleApp::ShowDCIGraph(DWORD dwNodeId, DWORD dwItemId, char *pszItemName)
9f20696e 996{
23e62c09
VK
997 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
998 CCreateContext context;
999 CGraphFrame *pWnd;
1000 DWORD dwCurrTime;
1001
1002 pWnd = new CGraphFrame;
1003 pWnd->AddItem(dwNodeId, dwItemId);
1004 dwCurrTime = time(NULL);
1005 pWnd->SetTimeFrame(dwCurrTime - 3600, dwCurrTime); // Last hour
9f20696e 1006
23e62c09
VK
1007 // load the frame
1008 context.m_pCurrentFrame = pFrame;
1009
1010 if (pWnd->LoadFrame(IDR_DCI_HISTORY_GRAPH, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
9f20696e 1011 {
23e62c09
VK
1012 CString strFullString, strTitle;
1013
1014 if (strFullString.LoadString(IDR_DCI_HISTORY_GRAPH))
1015 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
1016
1017 // add item name to title
1018 strTitle += " - [";
1019 strTitle += pszItemName;
1020 strTitle += "]";
1021
1022 // set the handles and redraw the frame and parent
1023 pWnd->SetHandles(m_hMDIMenu, m_hMDIAccel);
1024 pWnd->SetTitle(strTitle);
1025 pWnd->InitialUpdateFrame(NULL, TRUE);
9f20696e 1026 }
23e62c09
VK
1027 else
1028 {
1029 delete pWnd;
1030 }
9f20696e 1031}
34870fc0
VK
1032
1033
1034//
1035// WM_COMMAND::ID_TOOLS_MIBBROWSER message handler
1036//
1037
1038void CConsoleApp::OnToolsMibbrowser()
1039{
1040 CMIBBrowserDlg dlg;
1041 dlg.DoModal();
1042}
1043
1044
1045//
1046// WM_COMMAND::ID_CONTROLPANEL_EVENTPOLICY message handler
1047//
1048
1049void CConsoleApp::OnControlpanelEventpolicy()
1050{
1051 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1052
1053 // create a new MDI child window or open existing
1054 if (m_bEventPolicyEditorActive)
618d6256 1055 {
34870fc0 1056 m_pwndEventPolicyEditor->BringWindowToTop();
618d6256 1057 }
34870fc0
VK
1058 else
1059 {
1060 DWORD dwResult;
1061
1062 dwResult = DoRequestArg1(NXCOpenEventPolicy, &m_pEventPolicy, "Loading event processing policy...");
1063 if (dwResult == RCC_SUCCESS)
1064 {
1065 pFrame->CreateNewChild(
ef44d5ea 1066 RUNTIME_CLASS(CEventPolicyEditor), IDR_EPP_EDITOR, m_hPolicyEditorMenu, m_hPolicyEditorAccel);
34870fc0
VK
1067 }
1068 else
1069 {
7b053de2 1070 ErrorBox(dwResult, "Unable to load event processing policy:\n%s");
34870fc0
VK
1071 }
1072 }
1073}
ece89362
VK
1074
1075
1076//
1077// WM_COMMAND::ID_VIEW_ALARMS message handler
1078//
1079
1080void CConsoleApp::OnViewAlarms()
1081{
1082 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1083
1084 // create a new MDI child window or open existing
1085 if (m_bAlarmBrowserActive)
1086 m_pwndAlarmBrowser->BringWindowToTop();
1087 else
1088 pFrame->CreateNewChild(
5cac98d8 1089 RUNTIME_CLASS(CAlarmBrowser), IDR_ALARMS, m_hAlarmBrowserMenu, m_hAlarmBrowserAccel);
ece89362 1090}
bfce8503
VK
1091
1092
1093//
1094// WM_COMMAND::ID_FILE_SETTINGS message handler
1095//
1096
1097void CConsoleApp::OnFileSettings()
1098{
1099 CPropertySheet wndPropSheet("Settings", GetMainWnd(), 0);
1100 CConsolePropsGeneral wndGeneral;
1101
1102 // "General" page
1103 wndGeneral.m_bExpandCtrlPanel = (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL) ? TRUE : FALSE;
1104 wndGeneral.m_bShowGrid = (g_dwOptions & UI_OPT_SHOW_GRID) ? TRUE : FALSE;
1105 wndPropSheet.AddPage(&wndGeneral);
1106
1107 if (wndPropSheet.DoModal() == IDOK)
1108 {
1109 if (wndGeneral.m_bExpandCtrlPanel)
1110 g_dwOptions |= UI_OPT_EXPAND_CTRLPANEL;
1111 else
1112 g_dwOptions &= ~UI_OPT_EXPAND_CTRLPANEL;
1113
1114 if (wndGeneral.m_bShowGrid)
1115 g_dwOptions |= UI_OPT_SHOW_GRID;
1116 else
1117 g_dwOptions &= ~UI_OPT_SHOW_GRID;
1118 }
1119}
925832ac
VK
1120
1121
1122//
1123// WM_COMMAND::ID_CONTROLPANEL_ACTIONS message handler
1124//
1125
1126void CConsoleApp::OnControlpanelActions()
1127{
1128 CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
1129
1130 // create a new MDI child window or open existing
1131 if (m_bActionEditorActive)
1132 {
1133 m_pwndActionEditor->BringWindowToTop();
1134 }
1135 else
1136 {
1137 DWORD dwResult;
1138
1139 dwResult = DoRequest(NXCLockActionDB, "Locking action configuration database...");
1140 if (dwResult == RCC_SUCCESS)
1141 {
1142 pFrame->CreateNewChild(
1143 RUNTIME_CLASS(CActionEditor), IDR_ACTION_EDITOR, m_hMDIMenu, m_hMDIAccel);
1144 }
1145 else
1146 {
1147 ErrorBox(dwResult, "Unable to lock action configuration database:\n%s");
1148 }
1149 }
1150}
a0fcaaf6
VK
1151
1152
1153//
1154// Load application menu from resources and modify it as needed
1155//
1156
1157HMENU CConsoleApp::LoadAppMenu(HMENU hViewMenu)
1158{
1159 HMENU hMenu;
1160
1161 hMenu = ::LoadMenu(m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
1162
1163 if (g_dwOptions & UI_OPT_EXPAND_CTRLPANEL)
1164 {
1165 RemoveMenu(hMenu, ID_VIEW_CONTROLPANEL, MF_BYCOMMAND);
1166 InsertMenu(hMenu, ID_VIEW_DEBUG, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)GetSubMenu(hViewMenu, 8), "&Control panel");
1167 }
1168
1169 return hMenu;
1170}
6849d9be
VK
1171
1172
1173//
1174// Create new object
1175//
1176
1177void CConsoleApp::CreateObject(int iClass, DWORD dwParent)
1178{
1179 CCreateObjectDlg dlg;
1180 DWORD dwResult, dwObjectId;
1181 NXC_OBJECT_CREATE_INFO ci;
1182
1183 dlg.m_pParentObject = NXCFindObjectById(dwParent);
1184 if (dlg.DoModal() == IDOK)
1185 {
1186 ci.dwParentId = (dlg.m_pParentObject != NULL) ? dlg.m_pParentObject->dwId : 0;
1187 ci.iClass = iClass;
1188 ci.pszName = (char *)((LPCTSTR)dlg.m_strObjectName);
1189 switch(iClass)
1190 {
1191 case OBJECT_NODE:
1192 break;
1193 case OBJECT_CONTAINER:
1194 ci.cs.container.dwCategory = 1;
1195 ci.cs.container.pszDescription = (char *)((LPCTSTR)dlg.m_strDescription);
1196 break;
1197 }
1198
1199 dwResult = DoRequestArg2(NXCCreateObject, &ci, &dwObjectId, "Creating object...");
1200 if (dwResult != RCC_SUCCESS)
1201 {
1202 ErrorBox(dwResult, "Error creating object: %s");
1203 }
1204 }
1205}