-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathTeamTalkApp.cpp
231 lines (185 loc) · 5.47 KB
/
TeamTalkApp.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*
* Copyright (c) 2005-2018, BearWare.dk
*
* Contact Information:
*
* Bjoern D. Rasmussen
* Kirketoften 5
* DK-8260 Viby J
* Denmark
* Email: contact@bearware.dk
* Phone: +45 20 20 54 59
* Web: http://www.bearware.dk
*
* This source code is part of the TeamTalk SDK owned by
* BearWare.dk. Use of this file, or its compiled unit, requires a
* TeamTalk SDK License Key issued by BearWare.dk.
*
* The TeamTalk SDK License Agreement along with its Terms and
* Conditions are outlined in the file License.txt included with the
* TeamTalk SDK distribution.
*
*/
#include "stdafx.h"
#include "TeamTalkApp.h"
#include "TeamTalkDlg.h"
#include "AppInfo.h"
#include "License.h"
#include <VersionHelpers.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////
/// C functions for libraries
extern "C"
{
LASTINPUT GetLastInputInfo_ = NULL;
DWORD GetLastInput()
{
DWORD dwResult = 0;
if(GetLastInputInfo_)
{
LASTINPUTINFO info;
memset(&info, 0, sizeof(info));
info.cbSize = sizeof(LASTINPUTINFO);
if( GetLastInputInfo_(&info))
dwResult = info.dwTime;
else
{
ASSERT(FALSE);
dwResult = ::GetTickCount();
}
}
return dwResult;
}
}
///////////////////////////////////////////////////////////////////////
// helper functions for IPC
typedef struct
{
HWND hwnd;
LPCTSTR title;
} FindWnd;
BOOL CALLBACK CheckWindowTitle( HWND hwnd, LPARAM lParam )
{
TCHAR buffer[MAX_PATH];
GetWindowText( hwnd, buffer, MAX_PATH );
FindWnd * fw = (FindWnd *)lParam;
if( _tcsncmp( buffer, fw->title, MAX_PATH ) == 0 )
{
fw->hwnd = hwnd;
return FALSE;
}
return TRUE;
}
HWND FindWinTitle( LPCTSTR title )
{
FindWnd fw;
fw.hwnd = 0;
fw.title = title;
EnumWindows( (WNDENUMPROC) CheckWindowTitle, (LPARAM) &fw );
return fw.hwnd;
}
BOOL IsWin2kPlus()
{
//detect windows version
return IsWindowsXPOrGreater();
}
void MyCommandLineInfo::ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast )
{
bFlag = bFlag;
m_args.AddTail(lpszParam);
}
// CTeamTalkApp
BEGIN_MESSAGE_MAP(CTeamTalkApp, CWinApp)
//ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CTeamTalkApp construction
CTeamTalkApp::CTeamTalkApp()
{
//EnableHtmlHelp();
// Place all significant initialization in InitInstance
}
// The one and only CTeamTalkApp object
CTeamTalkApp theApp;
const GUID CDECL BASED_CODE _tlid =
{ 0xBC4E1CC0, 0x8B80, 0x4BD4, { 0x85, 0xC3, 0xD1, 0xAC, 0x38, 0x6A, 0x29, 0xB8 } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;
// CTeamTalkApp initialization
BOOL CTeamTalkApp::InitInstance()
{
AfxOleInit();
// InitCommonControls() 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.
InitCommonControls();
CWinApp::InitInstance();
AfxEnableControlContainer();
HMODULE hCoreMod = 0;
// Load keyboard hook
if(IsWin2kPlus())
{
hCoreMod = LoadLibrary(_T("USER32.dll"));
GetLastInputInfo_ = (LASTINPUT)GetProcAddress(hCoreMod, "GetLastInputInfo");
ASSERT(GetLastInputInfo_);
}
//load richedit
if(!AfxInitRichEdit2( ))
AfxMessageBox(_T("Failed to initialize RichEdit component"));
SetCurrentDirectory(GetExecutableFolder());
/* Set license information before creating the first client instance */
TT_SetLicenseInformation(REGISTRATION_NAME, REGISTRATION_KEY);
// check whether an existing instance of TT is running an whether
// this instance has been passed a .tt file
HWND hRunningTT = FindWinTitle(APPTITLE);
MyCommandLineInfo info;
ParseCommandLine(info);
CString szArg;
//trim command line params for "
if(hRunningTT && info.m_args.GetCount() == 1)
{
BOOL bTTUrl = FALSE;
MsgCmdLine msg = {};
for(POSITION pos = info.m_args.GetHeadPosition(); pos != NULL;)
{
szArg = info.m_args.GetNext(pos);
_tcsncat(msg.szPath, szArg.GetBuffer(), MAX_PATH);
_tcsncat(msg.szPath, _T("¤"), MAX_PATH);
bTTUrl |= StartsWith(szArg, TTURL, FALSE);
bTTUrl |= EndsWith(szArg, _T( TTFILE_EXT ), FALSE);
}
if(bTTUrl)
{
COPYDATASTRUCT cds;
cds.dwData = 0;
cds.cbData = sizeof(msg);
cds.lpData = &msg;
::SendMessage(hRunningTT, WM_COPYDATA, 0, (LPARAM)&cds);
return FALSE;
}
}
szArg.Empty();
CTeamTalkDlg dlg;
dlg.m_cmdArgs.AddHead(&info.m_args);
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// dismissed with Cancel
}
if(hCoreMod)
FreeLibrary(hCoreMod);
hCoreMod = 0;
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
int CTeamTalkApp::ExitInstance()
{
return CWinApp::ExitInstance();
}