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
|
/*
* This code implements window handling (connection error)
*
* (c) majvan 2002,2004
*/
#include "../stdafx.h"
#define BADCONNECTTITLE LPGEN("%s - connection error")
#define BADCONNECTMSG LPGEN("An error occurred. Error code: %d")//is in use?
//--------------------------------------------------------------------------------------------------
LRESULT CALLBACK BadConnectPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_COMMAND:
// if clicked and it's new mail popup window
if ((HIWORD(wParam) == STN_CLICKED) && (PUGetPluginData(hWnd))) {
PROCESS_INFORMATION pi;
STARTUPINFOW si;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
CAccount *ActualAccount = (CAccount *)PUGetPluginData(hWnd);
SReadGuard sra(ActualAccount->AccountAccessSO);
if (sra.Succeeded()) {
if (ActualAccount->BadConnectN.App != nullptr) {
wchar_t *Command;
if (ActualAccount->BadConnectN.AppParam != nullptr)
Command = new wchar_t[mir_wstrlen(ActualAccount->BadConnectN.App) + mir_wstrlen(ActualAccount->BadConnectN.AppParam) + 6];
else
Command = new wchar_t[mir_wstrlen(ActualAccount->BadConnectN.App) + 6];
if (Command != nullptr) {
mir_wstrcpy(Command, L"\"");
mir_wstrcat(Command, ActualAccount->BadConnectN.App);
mir_wstrcat(Command, L"\" ");
if (ActualAccount->BadConnectN.AppParam != nullptr)
mir_wstrcat(Command, ActualAccount->BadConnectN.AppParam);
CreateProcessW(nullptr, Command, nullptr, nullptr, FALSE, NORMAL_PRIORITY_CLASS, nullptr, nullptr, &si, &pi);
delete[] Command;
}
}
}
PUDeletePopup(hWnd);
}
break;
case UM_INITPOPUP:
//This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups.
break;
case WM_CONTEXTMENU:
PUDeletePopup(hWnd);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
INT_PTR CALLBACK DlgProcYAMNBadConnection(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
{
CMStringA szTitle;
wchar_t *Message1W = nullptr;
POPUPDATAW BadConnectPopup = {};
CAccount *ActualAccount = ((BadConnectionParam *)lParam)->account;
uint32_t ErrorCode = ((BadConnectionParam *)lParam)->errcode;
{
SReadGuard sra(ActualAccount->AccountAccessSO);
if (!sra.Succeeded())
return FALSE;
szTitle.Format(Translate(BADCONNECTTITLE), ActualAccount->Name);
BOOL ShowPopup = ActualAccount->BadConnectN.Flags & YAMN_ACC_POP;
BOOL ShowMsg = ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG;
BOOL ShowIco = ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO;
if (ShowPopup) {
BadConnectPopup.lchIcon = g_plugin.getIcon(IDI_BADCONNECT);
BadConnectPopup.colorBack = ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopupB : GetSysColor(COLOR_BTNFACE);
BadConnectPopup.colorText = ActualAccount->BadConnectN.Flags & YAMN_ACC_POPC ? ActualAccount->BadConnectN.PopupT : GetSysColor(COLOR_WINDOWTEXT);
BadConnectPopup.iSeconds = ActualAccount->BadConnectN.PopupTime;
BadConnectPopup.PluginWindowProc = BadConnectPopupProc;
BadConnectPopup.PluginData = ActualAccount;
mir_wstrncpy(BadConnectPopup.lpwzContactName, _A2T(ActualAccount->Name), _countof(BadConnectPopup.lpwzContactName));
}
if (ActualAccount->Plugin->Fcn != nullptr && ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr != nullptr) {
Message1W = ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode);
SetDlgItemText(hDlg, IDC_STATICMSG, Message1W);
wcsncpy_s(BadConnectPopup.lpwzText, Message1W, _TRUNCATE);
if (ShowPopup)
PUAddPopupW(&BadConnectPopup);
}
else if (ActualAccount->Plugin->Fcn != nullptr && ActualAccount->Plugin->Fcn->GetErrorStringAFcnPtr != nullptr) {
Message1W = ActualAccount->Plugin->Fcn->GetErrorStringWFcnPtr(ErrorCode);
SetDlgItemText(hDlg, IDC_STATICMSG, Message1W);
wcsncpy_s(BadConnectPopup.lpwzText, Message1W, _TRUNCATE);
if (ShowPopup)
PUAddPopupW(&BadConnectPopup);
}
else {
Message1W = TranslateT("Unknown error");
SetDlgItemText(hDlg, IDC_STATICMSG, Message1W);
wcsncpy_s(BadConnectPopup.lpwzText, Message1W, _TRUNCATE);
if (ShowPopup)
PUAddPopupW(&BadConnectPopup);
}
if (!ShowMsg && !ShowIco)
DestroyWindow(hDlg);
}
SetWindowTextA(hDlg, szTitle);
if (ActualAccount->Plugin->Fcn != nullptr && ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr != nullptr && Message1W != nullptr)
ActualAccount->Plugin->Fcn->DeleteErrorStringFcnPtr(Message1W);
return 0;
}
case WM_DESTROY:
{
NOTIFYICONDATA nid = {};
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hDlg;
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
}
break;
case WM_YAMN_NOTIFYICON:
switch (lParam) {
case WM_LBUTTONDBLCLK:
ShowWindow(hDlg, SW_SHOWNORMAL);
SetForegroundWindow(hDlg);
break;
}
return 0;
case WM_CHAR:
switch ((wchar_t)wParam) {
case 27:
case 13:
DestroyWindow(hDlg);
break;
}
break;
case WM_SYSCOMMAND:
switch (wParam) {
case SC_CLOSE:
DestroyWindow(hDlg);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_BTNOK:
DestroyWindow(hDlg);
}
break;
}
return 0;
}
static void __cdecl BadConnection(void *Param)
{
MSG msg;
HWND hBadConnect;
CAccount *ActualAccount;
auto *MyParam = (BadConnectionParam *)Param;
ActualAccount = MyParam->account;
SCGuard sc(ActualAccount->UsingThreads);
hBadConnect = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_DLGBADCONNECT), nullptr, DlgProcYAMNBadConnection, (LPARAM)MyParam);
Window_SetIcon_IcoLib(hBadConnect, g_plugin.getIconHandle(IDI_BADCONNECT));
SReadGuard sra(ActualAccount->AccountAccessSO);
if (WAIT_OBJECT_0 == sra) {
Skin_PlaySound(YAMN_CONNECTFAILSOUND);
if (ActualAccount->BadConnectN.Flags & YAMN_ACC_MSG)
ShowWindow(hBadConnect, SW_SHOWNORMAL);
if (ActualAccount->BadConnectN.Flags & YAMN_ACC_ICO) {
NOTIFYICONDATA nid = {};
nid.cbSize = sizeof(nid);
nid.hWnd = hBadConnect;
nid.hIcon = g_plugin.getIcon(IDI_BADCONNECT);
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_YAMN_NOTIFYICON;
mir_snwprintf(nid.szTip, L"%S%s", ActualAccount->Name, TranslateT(" - connection error"));
Shell_NotifyIcon(NIM_ADD, &nid);
}
sra.Uninit();
UpdateWindow(hBadConnect);
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
delete MyParam;
}
void RunBadConnection(CAccount *acc, UINT_PTR iErrorCode, void *pUserInfo)
{
BadConnectionParam param = { acc, iErrorCode, pUserInfo };
mir_forkthread(BadConnection, new BadConnectionParam(param));
}
|