Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/ttpcmn/ttcmn_notify.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9331 - (show annotations) (download) (as text)
Sat Jul 3 04:08:22 2021 UTC (2 years, 9 months ago) by zmatsuo
File MIME type: text/x-c++src
File size: 6586 byte(s)
タスクトレイの通知が出なくなっていたので修正

- 32bit時のみ
- TT_NOTIFYICONDATAW_V2 のサイズが誤っていた
  - 正 936byte
  - 誤 952byte (偶然 NOTIFYICONDATAW の XP以上 (V3) と同じサイズ)
- #include <pshpack1.h> を追加
- assert()でサイズチェックするようにした
- layer_for_unicode.h から comapt_win.h へ移動
- Visual Studio 2008 でビルドできるようになった
1 /*
2 * Copyright (C) 2020- TeraTerm Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /* TTCMN.DLL, notify icon */
30
31 // SDK7.0�������AWIN32_IE���K�������`��������
32 #if _MSC_VER == 1400 // VS2005����������
33 #if !defined(_WIN32_IE)
34 #define _WIN32_IE 0x0501
35 //#define _WIN32_IE 0x0600
36 #endif
37 #endif
38
39 #include <string.h>
40 #include <windows.h>
41 #include <wchar.h>
42 #define _CRTDBG_MAP_ALLOC
43 #include <stdlib.h>
44 #include <crtdbg.h>
45
46 #include "teraterm.h"
47 #include "tttypes.h"
48 #include "ttcommon.h"
49 #include "codeconv.h"
50 #include "compat_win.h"
51
52 typedef struct {
53 TT_NOTIFYICONDATAW_V2 notify_icon;
54 int NotifyIconShowCount;
55 HICON CustomIcon;
56 } NotifyIcon;
57
58 /**
59 * Shell_NotifyIconW() wrapper
60 * - TT_NOTIFYICONDATAW_V2 �� Windows 2000 ���~���g�p���\
61 * - �^�X�N�g���C���o���[�����o������������������ 2000 ���~
62 * - NT4���g������
63 * - HasBalloonTipSupport() �� 2000��������������
64 * - �K�� Unicode �������p���\ �� 9x�T�|�[�g�s�v?
65 * - Windows 98,ME �����p���\?
66 * - TT_NOTIFYICONDATAA_V2
67 */
68 static BOOL Shell_NotifyIconW(DWORD dwMessage, TT_NOTIFYICONDATAW_V2 *lpData)
69 {
70 return Shell_NotifyIconW(dwMessage, (NOTIFYICONDATAW*)lpData);
71 }
72
73 static NotifyIcon *NotifyCreate(HWND hWnd, HICON icon, UINT msg)
74 {
75 NotifyIcon *ni = (NotifyIcon *)malloc(sizeof(NotifyIcon));
76 memset(ni, 0, sizeof(*ni));
77
78 TT_NOTIFYICONDATAW_V2 *p = &ni->notify_icon;
79 p->cbSize = sizeof(*p);
80 p->hWnd = hWnd;
81 p->uID = 1;
82 p->uFlags = NIF_ICON | NIF_MESSAGE;
83 p->uCallbackMessage = msg;
84 p->hIcon = icon;
85
86 Shell_NotifyIconW(NIM_ADD, p);
87
88 ni->NotifyIconShowCount = 0;
89
90 return ni;
91 }
92
93 static void NotifyDelete(NotifyIcon *ni)
94 {
95 TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
96 Shell_NotifyIconW(NIM_DELETE, NotifyIcon);
97 ni->NotifyIconShowCount = 0;
98 }
99
100 static void NotifyShowIcon(NotifyIcon *ni)
101 {
102 TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
103 NotifyIcon->uFlags = NIF_STATE;
104 NotifyIcon->dwState = 0;
105 NotifyIcon->dwStateMask = NIS_HIDDEN;
106 Shell_NotifyIconW(NIM_MODIFY, NotifyIcon);
107 ni->NotifyIconShowCount += 1;
108 }
109
110 static void NotifyHide(NotifyIcon *ni)
111 {
112 if (ni->NotifyIconShowCount > 1) {
113 ni->NotifyIconShowCount -= 1;
114 }
115 else {
116 TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
117 NotifyIcon->uFlags = NIF_STATE;
118 NotifyIcon->dwState = NIS_HIDDEN;
119 NotifyIcon->dwStateMask = NIS_HIDDEN;
120 Shell_NotifyIconW(NIM_MODIFY, NotifyIcon);
121 ni->NotifyIconShowCount = 0;
122 }
123 }
124
125 static void NotifySetVersion(NotifyIcon *ni, unsigned int ver)
126 {
127 TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
128 NotifyIcon->uVersion = ver;
129 Shell_NotifyIconW(NIM_SETVERSION, NotifyIcon);
130 }
131
132 static void NotifySetMessageW(NotifyIcon *ni, const wchar_t *msg, const wchar_t *title, DWORD flag)
133 {
134 if (msg == NULL) {
135 return;
136 }
137
138 if (! HasBalloonTipSupport()) {
139 return;
140 }
141
142 TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon;
143 NotifyIcon->uFlags = NIF_INFO | NIF_STATE;
144 NotifyIcon->dwState = 0;
145 NotifyIcon->dwStateMask = NIS_HIDDEN;
146
147 if (title) {
148 NotifyIcon->dwInfoFlags = flag;
149 wcsncpy_s(NotifyIcon->szInfoTitle, _countof(NotifyIcon->szInfoTitle), title, _TRUNCATE);
150 }
151 else {
152 NotifyIcon->dwInfoFlags = NIIF_NONE;
153 NotifyIcon->szInfoTitle[0] = 0;
154 }
155
156 wcsncpy_s(NotifyIcon->szInfo, _countof(NotifyIcon->szInfo), msg, _TRUNCATE);
157
158 Shell_NotifyIconW(NIM_MODIFY, NotifyIcon);
159
160 ni->NotifyIconShowCount += 1;
161 }
162
163 /*
164 * EXPORT API
165 */
166 static HICON CustomIcon = NULL;
167
168 static NotifyIcon *GetNotifyData(PComVar cv)
169 {
170 NotifyIcon *p = (NotifyIcon *)cv->NotifyIcon;
171 return p;
172 }
173
174 void WINAPI SetCustomNotifyIcon(HICON icon)
175 {
176 CustomIcon = icon;
177 }
178
179 HICON WINAPI GetCustomNotifyIcon()
180 {
181 return CustomIcon;
182 }
183
184 void WINAPI CreateNotifyIcon(PComVar cv)
185 {
186 NotifyIcon *ni = GetNotifyData(cv);
187 if (ni != NULL) {
188 return;
189 }
190 HICON icon = CustomIcon;
191 if (icon == NULL) {
192 icon = (HICON)SendMessage(cv->HWin, WM_GETICON, ICON_SMALL, 0);
193 }
194
195 ni = NotifyCreate(cv->HWin, icon, WM_USER_NOTIFYICON);
196 cv->NotifyIcon = ni;
197 }
198
199 void WINAPI DeleteNotifyIcon(PComVar cv)
200 {
201 NotifyIcon* ni = GetNotifyData(cv);
202 if (ni == NULL) {
203 return;
204 }
205 NotifyDelete(ni);
206 }
207
208 void WINAPI ShowNotifyIcon(PComVar cv)
209 {
210 NotifyIcon* ni = GetNotifyData(cv);
211 if (ni == NULL) {
212 CreateNotifyIcon(cv);
213 ni = GetNotifyData(cv);
214 }
215
216 NotifyShowIcon(ni);
217 }
218
219 void WINAPI HideNotifyIcon(PComVar cv)
220 {
221 NotifyIcon *ni = GetNotifyData(cv);
222 NotifyHide(ni);
223 }
224
225 // �g������������
226 void WINAPI SetVerNotifyIcon(PComVar cv, unsigned int ver)
227 {
228 NotifyIcon *ni = GetNotifyData(cv);
229 NotifySetVersion(ni, ver);
230 }
231
232 void WINAPI NotifyMessageW(PComVar cv, const wchar_t *msg, const wchar_t *title, DWORD flag)
233 {
234 NotifyIcon *ni = GetNotifyData(cv);
235 if (ni == NULL) {
236 CreateNotifyIcon(cv);
237 ni = GetNotifyData(cv);
238 }
239
240 NotifySetMessageW(ni, msg, title, flag);
241 }
242
243 void WINAPI NotifyMessage(PComVar cv, const char *msg, const char *title, DWORD flag)
244 {
245 wchar_t *titleW = ToWcharA(title);
246 wchar_t *msgW = ToWcharA(msg);
247 NotifyMessageW(cv, msgW, titleW, flag);
248 free(titleW);
249 free(msgW);
250 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26