-
Notifications
You must be signed in to change notification settings - Fork 10
/
NetPerSec.cpp
86 lines (66 loc) · 1.92 KB
/
NetPerSec.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Creates a hidden window to manage the system tray
* icons. See winproc.cpp.
*/
#include "StdAfx.h"
#include "NetPerSec.h"
#include "winsock2.h"
#pragma comment(lib, "Ws2_32.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// The one and only CNetPerSecApp object
CNetPerSecApp theApp;
// Private message for the taskbar
extern UINT TaskbarCallbackMsg;
// CNetPerSecApp
BEGIN_MESSAGE_MAP(CNetPerSecApp, CWinApp)
//{{AFX_MSG_MAP(CNetPerSecApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CNetPerSecApp construction
CNetPerSecApp::CNetPerSecApp() {
m_hMutex = NULL;
}
CNetPerSecApp::~CNetPerSecApp() {
if (m_hMutex != NULL)
::CloseHandle(m_hMutex);
}
// CNetPerSecApp initialization
BOOL CNetPerSecApp::InitInstance() {
// Single instance
m_hMutex = ::CreateMutex(NULL, FALSE, SZ_APPNAME);
if (m_hMutex != NULL && ::GetLastError() == ERROR_ALREADY_EXISTS) {
HWND hWnd = FindWindow(NULL, SZ_APPNAME);
if (hWnd != NULL) {
PostMessage(hWnd, TaskbarCallbackMsg, 0, WM_LBUTTONDBLCLK);
SetForegroundWindow(hWnd);
}
return FALSE;
}
WSADATA WinsockData;
if (WSAStartup(MAKEWORD(1, 1), &WinsockData) != 0)
AfxMessageBox("This program requires Winsock 2.x", MB_ICONHAND);
// Read saved settings from .ini file
ReadSettings();
// Create a hidden window to receive system tray messages
LPCTSTR pClass = AfxRegisterWndClass(0);
CRect rc;
rc.SetRectEmpty();
if (m_wnd.CreateEx(WS_EX_TOOLWINDOW, pClass, SZ_APPNAME, WS_OVERLAPPED, rc, NULL, 0) == 0) {
ShowError(IDS_CREATEWINDOW_ERR, MB_OK | MB_ICONHAND);
return FALSE; // Bail out
}
m_pMainWnd = &m_wnd;
m_wnd.StartUp();
WSACleanup();
return TRUE;
}
void CNetPerSecApp::WinHelp(DWORD dwData, UINT nCmd) {
m_wnd.WinHelp(dwData, nCmd);
}