svnno****@sourc*****
svnno****@sourc*****
2017年 4月 3日 (月) 21:51:37 JST
Revision: 6662 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6662 Author: doda Date: 2017-04-03 21:51:37 +0900 (Mon, 03 Apr 2017) Log Message: ----------- バルーン通知する為の関数を追加 ToDo: ・Windows95 等でも問題なく動く? ・_WIN32_IE を 0x501 に決め打ちしてるけれど問題ない? ・Windows8 以降ではトースト通知を使う方がいいかも。ただ、面倒そう。 ・Windows10 では発生するイベントが違ったり、NIN_BALOONTIMEOUT が発生 しなかったりするらしい(未確認) https://blogs.msdn.microsoft.com/japan_platform_sdkwindows_sdk_support_team_blog/2016/02/03/windows-10-12/ ・バルーン通知時に通知領域に通知アイコンが出るが、バルーンクリックや タイムアウト時に隠すようにしているから邪魔にならないよね? ・バルーン左クリック(Windows10 では右クリックも?)で SetForegroundWindow しているけれど、メッセージの履歴を覚えておいてクリックで表示履歴を 表示する方が便利かも。 Modified Paths: -------------- trunk/teraterm/common/ttcommon.h trunk/teraterm/common/tttypes.h trunk/teraterm/teraterm/commlib.c trunk/teraterm/teraterm/vtwin.cpp trunk/teraterm/teraterm/vtwin.h trunk/teraterm/ttpcmn/ttcmn.c trunk/teraterm/ttpcmn/ttpcmn.def -------------- next part -------------- Modified: trunk/teraterm/common/ttcommon.h =================================================================== --- trunk/teraterm/common/ttcommon.h 2017-04-03 12:51:34 UTC (rev 6661) +++ trunk/teraterm/common/ttcommon.h 2017-04-03 12:51:37 UTC (rev 6662) @@ -53,6 +53,13 @@ int FAR PASCAL CommBinaryEcho(PComVar cv, PCHAR B, int C); int FAR PASCAL CommTextEcho(PComVar cv, PCHAR B, int C); +void FAR PASCAL CreateNotifyIcon(PComVar cv); +void FAR PASCAL DeleteNotifyIcon(PComVar cv); +void FAR PASCAL NotifyMessage(PComVar cv, PCHAR message, PCHAR title); +void FAR PASCAL ShowNotifyIcon(PComVar cv); +void FAR PASCAL HideNotifyIcon(PComVar cv); +void FAR PASCAL SetVerNotifyIcon(PComVar cv, unsigned int ver); + WORD FAR PASCAL SJIS2JIS(WORD KCode); WORD FAR PASCAL SJIS2EUC(WORD KCode); WORD FAR PASCAL JIS2SJIS(WORD KCode); Modified: trunk/teraterm/common/tttypes.h =================================================================== --- trunk/teraterm/common/tttypes.h 2017-04-03 12:51:34 UTC (rev 6661) +++ trunk/teraterm/common/tttypes.h 2017-04-03 12:51:37 UTC (rev 6662) @@ -150,6 +150,7 @@ #define WM_USER_KEYCODE WM_USER+12 #define WM_USER_GETSERIALNO WM_USER+13 #define WM_USER_CHANGETITLE WM_USER+14 +#define WM_USER_NOTIFYICON WM_USER+15 #define WM_USER_DDEREADY WM_USER+21 #define WM_USER_DDECMNDEND WM_USER+22 @@ -1033,6 +1034,8 @@ BOOL TelLineMode; _locale_t locale; BOOL VirtualStoreEnabled; + + NOTIFYICONDATA *NotifyIcon; } TComVar; typedef TComVar far *PComVar; Modified: trunk/teraterm/teraterm/commlib.c =================================================================== --- trunk/teraterm/teraterm/commlib.c 2017-04-03 12:51:34 UTC (rev 6661) +++ trunk/teraterm/teraterm/commlib.c 2017-04-03 12:51:37 UTC (rev 6662) @@ -125,6 +125,8 @@ cv->ProtoFlag = FALSE; /* message flag */ cv->NoMsg = 0; + + cv->NotifyIcon = NULL; } /* reset a serial port which is already open */ Modified: trunk/teraterm/teraterm/vtwin.cpp =================================================================== --- trunk/teraterm/teraterm/vtwin.cpp 2017-04-03 12:51:34 UTC (rev 6661) +++ trunk/teraterm/teraterm/vtwin.cpp 2017-04-03 12:51:37 UTC (rev 6662) @@ -160,6 +160,7 @@ ON_MESSAGE(WM_USER_CHANGETITLE,OnChangeTitle) ON_MESSAGE(WM_COPYDATA,OnReceiveIpcMessage) ON_MESSAGE(WM_USER_NONCONFIRM_CLOSE, OnNonConfirmClose) + ON_MESSAGE(WM_USER_NOTIFYICON, OnNotifyIcon) ON_COMMAND(ID_FILE_NEWCONNECTION, OnFileNewConnection) ON_COMMAND(ID_FILE_DUPLICATESESSION, OnDuplicateSession) ON_COMMAND(ID_FILE_CYGWINCONNECTION, OnCygwinConnection) @@ -1982,6 +1983,8 @@ CFrameWnd::OnDestroy(); TTXEnd(); /* TTPLUG */ + + DeleteNotifyIcon(&cv); } static LRESULT CALLBACK OnDragDropDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp) @@ -3786,6 +3789,41 @@ return 0; } + +LONG CVTWindow::OnNotifyIcon(UINT wParam, LONG lParam) +{ + char buff[512]; + + if (wParam == 1) { + switch (lParam) { + case WM_MOUSEMOVE: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + case WM_RBUTTONDBLCLK: + case WM_CONTEXTMENU: + case NIN_BALLOONSHOW: + case NIN_BALLOONHIDE: + case NIN_KEYSELECT: + case NIN_SELECT: + // nothing to do + break; + case NIN_BALLOONTIMEOUT: + HideNotifyIcon(&cv); + break; + case NIN_BALLOONUSERCLICK: + ::SetForegroundWindow(HVTWin); + HideNotifyIcon(&cv); + break; + } + } + + return 0; +} + + void CVTWindow::OnFileNewConnection() { // char Command[MAXPATHLEN], Command2[MAXPATHLEN]; Modified: trunk/teraterm/teraterm/vtwin.h =================================================================== --- trunk/teraterm/teraterm/vtwin.h 2017-04-03 12:51:34 UTC (rev 6661) +++ trunk/teraterm/teraterm/vtwin.h 2017-04-03 12:51:37 UTC (rev 6662) @@ -117,6 +117,7 @@ afx_msg LONG OnChangeTitle(UINT wParam, LONG lParam); afx_msg LONG OnReceiveIpcMessage(UINT wParam, LONG lParam); afx_msg LONG OnNonConfirmClose(UINT wParam, LONG lParam); + afx_msg LONG OnNotifyIcon(UINT wParam, LONG lParam); afx_msg void OnFileNewConnection(); afx_msg void OnDuplicateSession(); afx_msg void OnCygwinConnection(); Modified: trunk/teraterm/ttpcmn/ttcmn.c =================================================================== --- trunk/teraterm/ttpcmn/ttcmn.c 2017-04-03 12:51:34 UTC (rev 6661) +++ trunk/teraterm/ttpcmn/ttcmn.c 2017-04-03 12:51:37 UTC (rev 6662) @@ -2,6 +2,10 @@ Copyright(C) 1994-1998 T. Teranishi All rights reserved. */ +#ifndef _WIN32_IE +#define _WIN32_IE 0x501 +#endif + /* TTCMN.DLL, main */ #include "teraterm.h" #include "tttypes.h" @@ -2377,6 +2381,107 @@ return found; } +// Notify Icon \x8A֘A +static NOTIFYICONDATA notify_icon = {0}; + +void FAR PASCAL CreateNotifyIcon(PComVar cv) +{ + if (cv->NotifyIcon == NULL) { + notify_icon.cbSize = sizeof(notify_icon); + notify_icon.hWnd = cv->HWin; + notify_icon.uID = 1; + notify_icon.uFlags = NIF_ICON | NIF_MESSAGE; + notify_icon.uCallbackMessage = WM_USER_NOTIFYICON; + notify_icon.hIcon = (HICON)SendMessage(cv->HWin, WM_GETICON, ICON_SMALL, 0); + notify_icon.szTip[0] = '\0'; + notify_icon.dwState = 0; + notify_icon.dwStateMask = 0; + notify_icon.szInfo[0] = '\0'; + notify_icon.uTimeout = 0; + notify_icon.szInfoTitle[0] = '\0'; + notify_icon.dwInfoFlags = 0; + + cv->NotifyIcon = ¬ify_icon; + + Shell_NotifyIcon(NIM_ADD, cv->NotifyIcon); + } + + return; +} + +void FAR PASCAL DeleteNotifyIcon(PComVar cv) +{ + if (cv->NotifyIcon) { + Shell_NotifyIcon(NIM_DELETE, cv->NotifyIcon); + cv->NotifyIcon = NULL; + } + + return; +} + +void FAR PASCAL ShowNotifyIcon(PComVar cv) +{ + if (cv->NotifyIcon == NULL) { + CreateNotifyIcon(cv); + } + + cv->NotifyIcon->uFlags = NIF_STATE; + cv->NotifyIcon->dwState = 0; + cv->NotifyIcon->dwStateMask = NIS_HIDDEN; + Shell_NotifyIcon(NIM_MODIFY, cv->NotifyIcon); + return; +} + +void FAR PASCAL HideNotifyIcon(PComVar cv) +{ + if (cv->NotifyIcon) { + cv->NotifyIcon->uFlags = NIF_STATE; + cv->NotifyIcon->dwState = NIS_HIDDEN; + cv->NotifyIcon->dwStateMask = NIS_HIDDEN; + Shell_NotifyIcon(NIM_MODIFY, cv->NotifyIcon); + } + return; +} + +void FAR PASCAL SetVerNotifyIcon(PComVar cv, unsigned int ver) +{ + if (cv->NotifyIcon) { + cv->NotifyIcon->uVersion = ver; + Shell_NotifyIcon(NIM_SETVERSION, cv->NotifyIcon); + } + return; +} + +void FAR PASCAL NotifyMessage(PComVar cv, char *msg, char *title) +{ + if (msg == NULL) { + return; + } + + if (cv->NotifyIcon == NULL) { + CreateNotifyIcon(cv); + } + + cv->NotifyIcon->uFlags = NIF_INFO | NIF_STATE; + cv->NotifyIcon->dwState = 0; + cv->NotifyIcon->dwStateMask = NIS_HIDDEN; + + if (title) { + cv->NotifyIcon->dwInfoFlags = NIIF_INFO; + strncpy_s(cv->NotifyIcon->szInfoTitle, sizeof(cv->NotifyIcon->szInfoTitle), title, _TRUNCATE); + } + else { + cv->NotifyIcon->dwInfoFlags = NIIF_NONE; + cv->NotifyIcon->szInfoTitle[0] = 0; + } + + strncpy_s(cv->NotifyIcon->szInfo, sizeof(cv->NotifyIcon->szInfo), msg, _TRUNCATE); + + Shell_NotifyIcon(NIM_MODIFY, cv->NotifyIcon); + + return; +} + BOOL WINAPI DllMain(HANDLE hInstance, ULONG ul_reason_for_call, LPVOID lpReserved) Modified: trunk/teraterm/ttpcmn/ttpcmn.def =================================================================== --- trunk/teraterm/ttpcmn/ttpcmn.def 2017-04-03 12:51:34 UTC (rev 6661) +++ trunk/teraterm/ttpcmn/ttpcmn.def 2017-04-03 12:51:37 UTC (rev 6662) @@ -30,6 +30,12 @@ replaceInvalidFileNameChar @74 b64encode @75 b64decode @76 + CreateNotifyIcon @77 + DeleteNotifyIcon @78 + ShowNotifyIcon @80 + HideNotifyIcon @81 + SetVerNotifyIcon @82 + NotifyMessage @79 SJIS2JIS @30 SJIS2EUC @31