-
Notifications
You must be signed in to change notification settings - Fork 0
/
Messager.cpp
154 lines (129 loc) · 3.67 KB
/
Messager.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
//---------------------------------------------------------------------------
//#define WINVER 0x0400
//#define _WIN32_NT 0x0400
#define MB_SERVICE_NOTIFICATION 0x00040000L
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <string.h>
#include "resource.h"
#include "Sound.h"
// Взято из нового Platform SDK
#define ICC_STANDARD_CLASSES 0x00004000
//---------------------------------------------------------------------------
#define MAX_TEXT 1024
#define MAX_TITLE 32
#define MAX_ICON 5
#define QUIT_TIMEOUT 1000
static int IconTable[] = { IDI_MESSAGER, IDI_ALARM, IDI_MOVIE };
static void __fastcall ErrorBox(void)
{
char text[MAX_TEXT],
title[MAX_TITLE];
LoadString(0, ERR_FORMAT, text, sizeof(text));
LoadString(0, IDS_ERRORTITLE, title, sizeof(title));
MessageBox(0, text, title, MB_ICONSTOP);
}
static const int Sequence[] = { 200, 300, 400, 300, 700, 500 };
static int pos = 0;
static volatile bool Terminate = false;
DWORD WINAPI ThreadProc(void *)
{
OSVERSIONINFO ver;
ver.dwOSVersionInfoSize = sizeof(ver);
GetVersionEx(&ver);
register bool WinNT = ver.dwPlatformId == VER_PLATFORM_WIN32_NT;
while (!Terminate)
{
if (Sequence[pos] != 0)
if (WinNT)
Beep(Sequence[pos], Sequence[pos + 1]);
else // if (WinNT)
{
Sound(Sequence[pos]);
Sleep(Sequence[pos + 1]);
NoSound();
} // if (WinNT) else
else // if (Sequence[pos] != 0)
Sleep(Sequence[pos + 1]);
pos += 2;
if (pos == 6)
pos = 0;
} // while (!Terminate)
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR CmdLine, int)
{
INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&icc);
// Ищем сообщение в командной строке
char *Start = strchr(CmdLine, '\"');
if (!Start)
{
ErrorBox();
return 0xFF;
} // if (!Start)
char *pos = strchr(Start += 1, '\"');
if (!pos)
{
ErrorBox();
return 0xFF;
} // if (!pos)
*pos = 0;
// Проверяем, есть ли заголовок
char *TtlStart = 0;
if (*(++pos))
{
TtlStart = strchr(pos, '\"');
if (TtlStart)
{
pos = strchr(TtlStart += 1, '\"');
if (!pos)
{
ErrorBox();
return 0xFF;
} // if (!pos)
*pos = 0;
} // if (TtlStart)
} // if (*(++pos))
// Проверяем наличие значка в командной строке
int Icon = -1;
if (*(++pos))
{
if (!sscanf(pos, "%i", &Icon))
Icon = -1;
}
// Проверяем наличие параметра nosound
bool NoSound = strstr(_strlwr(pos), "nosound") != NULL;
if (Icon > MAX_ICON || Icon < 0)
Icon = 0;
DWORD ThreadId;
HANDLE hThread = NULL;
if (!NoSound)
hThread = CreateThread(0, 0, ThreadProc, 0, 0, &ThreadId);
MSGBOXPARAMS Info;
Info.cbSize = sizeof(MSGBOXPARAMS);
Info.hwndOwner = GetDesktopWindow();
Info.hInstance = hInstance;
Info.lpszText = Start;
Info.lpszCaption = TtlStart ? TtlStart : MAKEINTRESOURCE(IDS_TITLE);
Info.dwStyle = MB_OK | MB_SETFOREGROUND | MB_TOPMOST | (Icon == 0 ?
MB_ICONASTERISK : (Icon == 1 ? MB_ICONEXCLAMATION :
(Icon == 2 ? MB_ICONHAND : MB_USERICON))) | MB_SERVICE_NOTIFICATION;
Info.lpszIcon = MAKEINTRESOURCE(IconTable[Icon - 3]);
Info.dwContextHelpId = 1;
Info.lpfnMsgBoxCallback = 0;
Info.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
if (Icon > 2)
MessageBeep(MB_OK);
MessageBoxIndirect(&Info);
Terminate = true;
if (hThread)
{
WaitForSingleObject(hThread, QUIT_TIMEOUT);
CloseHandle(hThread);
}
return 0;
}