• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision9331 (tree)
Time2021-07-03 13:08:22
Authorzmatsuo

Log Message

タスクトレイの通知が出なくなっていたので修正

- 32bit時のみ
- TT_NOTIFYICONDATAW_V2 のサイズが誤っていた

- 正 936byte
- 誤 952byte (偶然 NOTIFYICONDATAW の XP以上 (V3) と同じサイズ)

- #include <pshpack1.h> を追加
- assert()でサイズチェックするようにした
- layer_for_unicode.h から comapt_win.h へ移動
- Visual Studio 2008 でビルドできるようになった

Change Summary

Incremental Difference

--- trunk/teraterm/common/compat_win.cpp (revision 9330)
+++ trunk/teraterm/common/compat_win.cpp (revision 9331)
@@ -30,6 +30,7 @@
3030
3131 #include <windows.h>
3232 #include <windns.h>
33+#include <assert.h>
3334
3435 #include "compat_win.h"
3536 #include "compat_windns.h"
@@ -352,6 +353,16 @@
352353 if (done) return;
353354 done = TRUE;
354355
356+ assert(sizeof(TT_NOTIFYICONDATAA_V2) == NOTIFYICONDATAA_V2_SIZE);
357+ assert(sizeof(TT_NOTIFYICONDATAW_V2) == NOTIFYICONDATAW_V2_SIZE);
358+#if defined(_WIN64)
359+ assert(sizeof(TT_NOTIFYICONDATAA_V2) == 504);
360+ assert(sizeof(TT_NOTIFYICONDATAW_V2) == 952);
361+#else
362+ assert(sizeof(TT_NOTIFYICONDATAA_V2) == 488);
363+ assert(sizeof(TT_NOTIFYICONDATAW_V2) == 936);
364+#endif
365+
355366 DLLGetApiAddressFromLists(DllInfos);
356367
357368 // 9x特別処理
--- trunk/teraterm/common/compat_win.h (revision 9330)
+++ trunk/teraterm/common/compat_win.h (revision 9331)
@@ -68,6 +68,63 @@
6868 #define OPENFILENAME_SIZE_VERSION_400A 76
6969 #endif
7070
71+#if !defined(_WIN64)
72+#include <pshpack1.h>
73+#endif
74+
75+/**
76+ * NOTIFYICONDATA は define でサイズが変化する
77+ * どんな環境でも変化しないよう定義
78+ *
79+ * Shlwapi.dll 5.0
80+ * Win98(ME?)+,2000+
81+ */
82+typedef struct {
83+ DWORD cbSize;
84+ HWND hWnd;
85+ UINT uID;
86+ UINT uFlags;
87+ UINT uCallbackMessage;
88+ HICON hIcon;
89+ char szTip[128];
90+ DWORD dwState;
91+ DWORD dwStateMask;
92+ char szInfo[256];
93+ union {
94+ UINT uTimeout;
95+ UINT uVersion; // used with NIM_SETVERSION, values 0, 3 and 4
96+ } DUMMYUNIONNAME;
97+ char szInfoTitle[64];
98+ DWORD dwInfoFlags;
99+ //GUID guidItem; // XP+ (V3)
100+ //HICON hBalloonIcon; // Vista+ (V4)
101+} TT_NOTIFYICONDATAA_V2;
102+
103+typedef struct {
104+ DWORD cbSize;
105+ HWND hWnd;
106+ UINT uID;
107+ UINT uFlags;
108+ UINT uCallbackMessage;
109+ HICON hIcon;
110+ wchar_t szTip[128];
111+ DWORD dwState;
112+ DWORD dwStateMask;
113+ wchar_t szInfo[256];
114+ union {
115+ UINT uTimeout;
116+ UINT uVersion; // used with NIM_SETVERSION, values 0, 3 and 4
117+ } DUMMYUNIONNAME;
118+ wchar_t szInfoTitle[64];
119+ DWORD dwInfoFlags;
120+ //GUID guidItem; // XP+ (V3)
121+ //HICON hBalloonIcon; // Vista+ (V4)
122+} TT_NOTIFYICONDATAW_V2;
123+
124+#if !defined(_WIN64)
125+#include <poppack.h>
126+#endif
127+
71128 extern ATOM (WINAPI *pRegisterClassW)(const WNDCLASSW *lpWndClass);
72129 extern HWND (WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X,
73130 int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance,
--- trunk/teraterm/common/layer_for_unicode.cpp (revision 9330)
+++ trunk/teraterm/common/layer_for_unicode.cpp (revision 9331)
@@ -428,20 +428,14 @@
428428 return result;
429429 }
430430
431-/*
432- * lpData.cbSize == 952のときのみ ANSI関数で処理する
433- */
434431 BOOL WINAPI _Shell_NotifyIconW(DWORD dwMessage, TT_NOTIFYICONDATAW_V2 *lpData)
435432 {
436- if (pShell_NotifyIconW != NULL) {
437- return pShell_NotifyIconW(dwMessage, (PNOTIFYICONDATAW)lpData);
438- }
439-
440433 const TT_NOTIFYICONDATAW_V2 *w = lpData;
441434 if (w->cbSize != sizeof(TT_NOTIFYICONDATAW_V2)) {
442435 return FALSE;
443436 }
444437
438+ // lpData.cbSize == 952のときだけ ANSI関数で処理する
445439 TT_NOTIFYICONDATAA_V2 nid;
446440 TT_NOTIFYICONDATAA_V2 *p = &nid;
447441 p->cbSize = sizeof(nid);
--- trunk/teraterm/common/layer_for_unicode.h (revision 9330)
+++ trunk/teraterm/common/layer_for_unicode.h (revision 9331)
@@ -42,57 +42,6 @@
4242 extern "C" {
4343 #endif
4444
45-/**
46- * NOTIFYICONDATA は define でサイズが変化する
47- * どんな環境でも変化しないよう定義
48- *
49- * Shlwapi.dll 5.0
50- * Win98+,2000+
51- */
52-/* size 504 bytes */
53-typedef struct {
54- DWORD cbSize;
55- HWND hWnd;
56- UINT uID;
57- UINT uFlags;
58- UINT uCallbackMessage;
59- HICON hIcon;
60- char szTip[128];
61- DWORD dwState;
62- DWORD dwStateMask;
63- char szInfo[256];
64- union {
65- UINT uTimeout;
66- UINT uVersion; // used with NIM_SETVERSION, values 0, 3 and 4
67- } DUMMYUNIONNAME;
68- char szInfoTitle[64];
69- DWORD dwInfoFlags;
70- //GUID guidItem; // XP+
71- //HICON hBalloonIcon; // Vista+
72-} TT_NOTIFYICONDATAA_V2;
73-
74-/* size 952 bytes */
75-typedef struct {
76- DWORD cbSize;
77- HWND hWnd;
78- UINT uID;
79- UINT uFlags;
80- UINT uCallbackMessage;
81- HICON hIcon;
82- wchar_t szTip[128];
83- DWORD dwState;
84- DWORD dwStateMask;
85- wchar_t szInfo[256];
86- union {
87- UINT uTimeout;
88- UINT uVersion; // used with NIM_SETVERSION, values 0, 3 and 4
89- } DUMMYUNIONNAME;
90- wchar_t szInfoTitle[64];
91- DWORD dwInfoFlags;
92- //GUID guidItem; // XP+
93- //HICON hBalloonIcon; // Vista+
94-} TT_NOTIFYICONDATAW_V2;
95-
9645 BOOL WINAPI _SetWindowTextW(HWND hWnd, LPCWSTR lpString);
9746 BOOL WINAPI _SetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPCWSTR lpString);
9847 UINT WINAPI _GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int cchMax);
--- trunk/teraterm/ttpcmn/ttcmn_notify.cpp (revision 9330)
+++ trunk/teraterm/ttpcmn/ttcmn_notify.cpp (revision 9331)
@@ -47,39 +47,28 @@
4747 #include "tttypes.h"
4848 #include "ttcommon.h"
4949 #include "codeconv.h"
50+#include "compat_win.h"
5051
51-#if 0
52-// TODO 何とかする
5352 typedef struct {
54- DWORD cbSize;
55- HWND hWnd;
56- UINT uID;
57- UINT uFlags;
58- UINT uCallbackMessage;
59- HICON hIcon;
60- wchar_t szTip[128];
61- DWORD dwState;
62- DWORD dwStateMask;
63- wchar_t szInfo[256];
64- union {
65- UINT uTimeout;
66- UINT uVersion; // used with NIM_SETVERSION, values 0, 3 and 4
67- } DUMMYUNIONNAME;
68- wchar_t szInfoTitle[64];
69- DWORD dwInfoFlags;
70- //GUID guidItem; // XP+
71- //HICON hBalloonIcon; // Vista+
72-} TT_NOTIFYICONDATAW_V2;
73-#endif
74-
75-typedef struct {
76-// TT_NOTIFYICONDATAW_V2 notify_icon;
77- NOTIFYICONDATAW notify_icon;
53+ TT_NOTIFYICONDATAW_V2 notify_icon;
7854 int NotifyIconShowCount;
7955 HICON CustomIcon;
8056 } NotifyIcon;
8157
82-#define TT_NOTIFYICONDATAW_V2 NOTIFYICONDATAW
58+/**
59+ * Shell_NotifyIconW() wrapper
60+ * - TT_NOTIFYICONDATAW_V2 は Windows 2000 以降で使用可能
61+ * - タスクトレイにバルーンを出すことができるのは 2000 以降
62+ * - NT4は使えない
63+ * - HasBalloonTipSupport() で 2000以上としている
64+ * - 必ず Unicode 版が利用可能 → 9xサポート不要?
65+ * - Windows 98,ME で利用可能?
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+}
8372
8473 static NotifyIcon *NotifyCreate(HWND hWnd, HICON icon, UINT msg)
8574 {
@@ -86,14 +75,8 @@
8675 NotifyIcon *ni = (NotifyIcon *)malloc(sizeof(NotifyIcon));
8776 memset(ni, 0, sizeof(*ni));
8877
89- NOTIFYICONDATAW *p = &ni->notify_icon;
90-#if (_MSC_VER > 1400)
91- // VS2008+
92- p->cbSize = offsetof(NOTIFYICONDATAW, guidItem);
93-#else
94- // VS2005
78+ TT_NOTIFYICONDATAW_V2 *p = &ni->notify_icon;
9579 p->cbSize = sizeof(*p);
96-#endif
9780 p->hWnd = hWnd;
9881 p->uID = 1;
9982 p->uFlags = NIF_ICON | NIF_MESSAGE;
Show on old repository browser