-
Notifications
You must be signed in to change notification settings - Fork 11
/
microsip.cpp
152 lines (121 loc) · 3.96 KB
/
microsip.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright (C) 2011-2016 MicroSIP (http://www.microsip.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// microsip.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "microsip.h"
#include "mainDlg.h"
#include "const.h"
#include "settings.h"
#include "Strsafe.h"
#include <afxinet.h>
#pragma comment(linker, "/SECTION:.shr,RWS")
#pragma data_seg(".shr")
HWND hGlobal = NULL;
#pragma data_seg()
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CmicrosipApp
BEGIN_MESSAGE_MAP(CmicrosipApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CmicrosipApp construction
CmicrosipApp::CmicrosipApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CmicrosipApp object
CmicrosipApp theApp;
// CmicrosipApp initialization
BOOL CmicrosipApp::InitInstance()
{
bool AlreadyRunning;
HANDLE hMutexOneInstance = ::CreateMutex( NULL, TRUE,
_T("MICROSIP-088FA840-B10D-11D3-BC36-006067709674"));
AlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS);
if (hMutexOneInstance != NULL) {
::ReleaseMutex(hMutexOneInstance);
}
if ( AlreadyRunning && hGlobal != NULL) {
if ( lstrcmp(theApp.m_lpCmdLine, _T("/exit"))==0) {
::SendMessage(hGlobal, WM_CLOSE, NULL, NULL);
} else if ( lstrcmp(theApp.m_lpCmdLine, _T("/minimized"))==0) {
} else if ( lstrcmp(theApp.m_lpCmdLine, _T("/hidden"))==0) {
} else {
::ShowWindow(hGlobal, SW_SHOW);
::SetForegroundWindow(hGlobal);
if (lstrlen(theApp.m_lpCmdLine)) {
COPYDATASTRUCT cd;
cd.dwData = 1;
cd.lpData = theApp.m_lpCmdLine;
cd.cbData = sizeof(TCHAR) * (lstrlen(theApp.m_lpCmdLine) + 1);
::SendMessage(hGlobal, WM_COPYDATA, NULL, (LPARAM)&cd);
}
}
return FALSE;
} else {
if ( lstrcmp(theApp.m_lpCmdLine, _T("/exit"))==0) {
return FALSE;
}
}
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
// Set this to include all the common control classes you want to use
// in your application.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_LISTVIEW_CLASSES |
ICC_LINK_CLASS |
ICC_BAR_CLASSES |
ICC_LINK_CLASS |
ICC_STANDARD_CLASSES |
ICC_TAB_CLASSES |
ICC_UPDOWN_CLASS;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
//AfxEnableControlContainer();
CoInitializeEx(NULL, COINIT_MULTITHREADED);
AfxInitRichEdit2();
WNDCLASS wc;
// Get the info for this class.
// #32770 is the default class name for dialogs boxes.
::GetClassInfo(AfxGetInstanceHandle(), L"#32770", &wc);
wc.lpszClassName = _T(_GLOBAL_NAME);
// Register this class so that MFC can use it.
if (!::AfxRegisterClass(&wc)) return FALSE;
CmainDlg *mainDlg = new CmainDlg;
m_pMainWnd = mainDlg;
hGlobal = m_pMainWnd->m_hWnd;
//--
LRESULT pResult;
mainDlg->OnTcnSelchangeTab(NULL, &pResult);
if (mainDlg->m_startMinimized) {
m_pMainWnd->ShowWindow(SW_HIDE);
}
mainDlg->OnCreated();
//--
if (m_pMainWnd)
return TRUE;
else
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}