Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/broadcast.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9230 - (hide annotations) (download) (as text)
Mon May 3 15:04:42 2021 UTC (2 years, 11 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/broadcast.cpp
File MIME type: text/x-c++src
File size: 26124 byte(s)
_WIN32_WINNTをコンパイルオプションで指定

- Tera Term は _WIN32_WINNT >= 0x0501 でビルドすることが前提となっている
  - 0x0501=_WIN32_WINNT_WINXP
    - Windows XP
    - Windows Server 2003
  - Visual Studio 2005 のプロジェクトファイルに /D_WIN32_WINNT=0x0501 追加済み(r9191)
- teraterm_conf.h を削除
  - WIN32_WINNT をコンパイルオプションで指定するため r7554 で追加した
  - コマンドラインで明示的に指定するようになったた不要となった
    - SDK 7.0 では _WIN32_WINNT が自動で設定されない
    - SDK 7.0 より新しいSDKでは、特に指定されていない場合、自動で設定される
      - SDKのバージョンによって自動で設定される_WIN32_WINNT の値は異なっている
      - SDK 7.1 の場合 0x0601
      - SDK 10.0.18362.0 の場合 0x0A00
      - sdkddkver.h 内で設定される
        - MinGWの場合は _mingw.h
- Visual Studio 2005 では次のSDKでビルドできることを確認済み
  - SDK 7.0
  - SDK 7.1
- Tera Term は Visual Studio 2005 以上をサポート
  - MSC_VER >= 1400
1 zmatsuo 8823 /*
2 nmaya 9048 * Copyright (C) 2020- TeraTerm Project
3 zmatsuo 8823 * 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     // vtwin��������
30    
31     #include "teraterm.h"
32     #include "tttypes.h"
33     #include "ttcommon.h"
34     #include "ttwinman.h"
35    
36     #include <stdio.h>
37     #define _CRTDBG_MAP_ALLOC
38     #include <stdlib.h>
39     #include <crtdbg.h>
40     #include <string.h>
41     #include <windowsx.h>
42     #include <commctrl.h>
43 zmatsuo 8826 #include <wchar.h> // for wmemcpy_s()
44 zmatsuo 8823
45     #include "ttsetup.h"
46     #include "keyboard.h" // for ShiftKey() ControlKey()
47     #include "ttlib.h"
48     #include "dlglib.h"
49     #include "tt_res.h"
50 zmatsuo 8826 #include "layer_for_unicode.h"
51     #include "codeconv.h"
52     #include "sendmem.h"
53 zmatsuo 8827 //#include "clipboar.h" // TODO ����
54     #include "ttime.h"
55 zmatsuo 8823
56     #include "broadcast.h"
57    
58    
59     // WM_COPYDATA�������v���Z�X�����M������ (2005.1.22 yutaka)
60 zmatsuo 8826 #define IPC_BROADCAST_COMMAND 1 // �S�[�������M
61     #define IPC_MULTICAST_COMMAND 2 // �C�����[���Q�����M
62 zmatsuo 8823
63 zmatsuo 8826 /*
64     * COPYDATASTRUCT
65     *
66     * dwData
67     * IPC_BROADCAST_COMMAND
68     * lpData
69     * +--------------+--+
70     * |string |\0|
71     * +--------------+--+
72     * <-------------->
73     * cbData
74     * strlen(string) + 1
75     * (wcslen(string) + 1) * sizeof(wchar_t)
76     * buf���������� \0 ���t������
77     *
78     * dwData
79     * IPC_MULTICAST_COMMAND
80     * lpData
81     * +------+--------------+--+
82     * |name\0|string |\0|
83     * +------+--------------+--+
84     * <--------------------->
85     * cbData
86     * strlen(string) + 1 + strlen(string)
87     * (wcslen(name) + 1 + wcslen(string)) * sizeof(wchar_t)
88     * buf���������� \0 ���t������
89     */
90    
91 zmatsuo 8823 #define BROADCAST_LOGFILE "broadcast.log"
92    
93     static void ApplyBroadCastCommandHisotry(HWND Dialog, char *historyfile)
94     {
95     char EntName[13];
96     char Command[HostNameMaxLength+1];
97     int i = 1;
98    
99     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_RESETCONTENT, 0, 0);
100     do {
101     _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "Command%d", i);
102 zmatsuo 8827 GetPrivateProfileStringA("BroadcastCommands",EntName,"",
103     Command,sizeof(Command), historyfile);
104 zmatsuo 8823 if (strlen(Command) > 0) {
105     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_ADDSTRING,
106     0, (LPARAM)Command);
107     }
108     i++;
109     } while ((i <= ts.MaxBroadcatHistory) && (strlen(Command)>0));
110    
111     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, EM_LIMITTEXT,
112     HostNameMaxLength-1, 0);
113    
114     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_SETCURSEL,0,0);
115     }
116    
117 zmatsuo 8827 BOOL IsUnicharSupport(HWND hwnd)
118     {
119     LRESULT r = SendMessage(hwnd, WM_UNICHAR, UNICODE_NOCHAR, 0);
120     return (BOOL)r;
121     }
122    
123 zmatsuo 8823 // �h���b�v�_�E���������G�f�B�b�g�R���g���[����
124     // �T�u�N���X�������������E�C���h�E�v���V�[�W��
125     static WNDPROC OrigBroadcastEditProc; // Original window procedure
126     static HWND BroadcastWindowList;
127     static LRESULT CALLBACK BroadcastEditProc(HWND dlg, UINT msg,
128     WPARAM wParam, LPARAM lParam)
129     {
130     char buf[1024];
131     int len;
132 zmatsuo 8827 static BOOL ime_mode = FALSE;
133 zmatsuo 8823
134     switch (msg) {
135     case WM_CREATE:
136 zmatsuo 8827 ime_mode = FALSE;
137 zmatsuo 8823 break;
138    
139     case WM_DESTROY:
140     break;
141    
142     case WM_LBUTTONUP:
143     // �������e�L�X�g�����������������������A�J�[�\���������������������B
144     len = GetWindowText(dlg, buf, sizeof(buf));
145     SendMessage(dlg, EM_SETSEL, len, len);
146     SetFocus(dlg);
147     break;
148    
149     case WM_LBUTTONDOWN:
150     case WM_RBUTTONDOWN:
151     case WM_RBUTTONUP:
152     SetFocus(dlg);
153     break;
154    
155     case WM_KEYDOWN:
156     case WM_KEYUP:
157     case WM_SYSKEYDOWN:
158     case WM_SYSKEYUP:
159 zmatsuo 8827 if (ime_mode == FALSE) {
160 zmatsuo 8823 int i;
161     HWND hd;
162     int count;
163    
164     if (wParam == 0x0d) { // Enter key
165     SetWindowText(dlg, "");
166     SendMessage(dlg, EM_SETSEL, 0, 0);
167     }
168    
169 zmatsuo 8826 count = (int)SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0);
170 zmatsuo 8823 for (i = 0 ; i < count ; i++) {
171     if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) {
172     hd = GetNthWin(i);
173     if (hd) {
174     PostMessage(hd, msg, wParam, lParam);
175     }
176     }
177     }
178 zmatsuo 8827 return FALSE;
179 zmatsuo 8823 }
180     break;
181    
182     case WM_CHAR:
183     // ��������������IDC_COMMAND_EDIT���c������������������
184 zmatsuo 8827 if (ime_mode == FALSE) {
185     return FALSE;
186     }
187     break;
188 zmatsuo 8823
189 zmatsuo 8827 case WM_IME_NOTIFY:
190     switch (wParam) {
191     case IMN_SETOPENSTATUS:
192     // IME��On/Off����������
193     ime_mode = GetIMEOpenStatus(dlg);
194     }
195     break;
196    
197     case WM_IME_COMPOSITION: {
198     if (CanUseIME()) {
199     size_t len;
200     const wchar_t *lpstr = GetConvStringW(dlg, lParam, &len);
201     if (lpstr != NULL) {
202     char32_t *strU32 = ToU32W(lpstr);
203     int count = SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0);
204     for (int i = 0 ; i < count ; i++) {
205     if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) {
206     HWND hwnd = GetNthWin(i);
207     if (hwnd != NULL) {
208     BOOL support_unichar = IsUnicharSupport(hwnd);
209     if (!support_unichar) {
210     for (size_t j = 0; j < len; j++) {
211     ::PostMessageW(hwnd, WM_CHAR, lpstr[j], 1);
212     }
213     }
214     else {
215     const char32_t *p = strU32;
216     while (*p != 0) {
217     ::PostMessageW(hwnd, WM_UNICHAR, *p, 1);
218     p++;
219     }
220     }
221     }
222     }
223     }
224     free((void *)lpstr);
225     free(strU32);
226     return FALSE;
227     }
228     }
229     break;
230     }
231 zmatsuo 8823 default:
232 zmatsuo 8827 break;
233 zmatsuo 8823 }
234 zmatsuo 8827 return _CallWindowProcW(OrigBroadcastEditProc, dlg, msg, wParam, lParam);
235 zmatsuo 8823 }
236    
237     static void UpdateBroadcastWindowList(HWND hWnd)
238     {
239     int i, count;
240     HWND hd;
241     TCHAR szWindowText[256];
242    
243     SendMessage(hWnd, LB_RESETCONTENT, 0, 0);
244    
245     count = GetRegisteredWindowCount();
246     for (i = 0 ; i < count ; i++) {
247     hd = GetNthWin(i);
248     if (hd == NULL) {
249     break;
250     }
251    
252     GetWindowText(hd, szWindowText, 256);
253     SendMessage(hWnd, LB_INSERTSTRING, -1, (LPARAM)szWindowText);
254     }
255     }
256    
257 zmatsuo 8826 static COPYDATASTRUCT *BuildBroadcastCDSW(const wchar_t *buf)
258     {
259     COPYDATASTRUCT *cds = (COPYDATASTRUCT *)malloc(sizeof(COPYDATASTRUCT));
260     size_t buflen = wcslen(buf);
261    
262     cds->dwData = IPC_BROADCAST_COMMAND;
263     cds->cbData = (DWORD)(buflen * sizeof(wchar_t)); // '\0' ����������
264     cds->lpData = (void *)buf;
265    
266     return cds;
267     }
268    
269     static COPYDATASTRUCT *BuildMulticastCDSW(const wchar_t *name, const wchar_t *buf)
270     {
271     size_t buflen = wcslen(buf);
272     size_t nlen = wcslen(name) + 1;
273     size_t msglen = nlen + buflen;
274     wchar_t *msg = (wchar_t *)malloc(msglen * sizeof(wchar_t));
275     if (msg == NULL) {
276     return NULL;
277     }
278     wcscpy_s(msg, msglen, name);
279     wmemcpy_s(msg + nlen, msglen - nlen, buf, buflen);
280    
281     COPYDATASTRUCT *cds = (COPYDATASTRUCT *)malloc(sizeof(COPYDATASTRUCT));
282     if (cds == NULL) {
283     free(msg);
284     return NULL;
285     }
286     cds->dwData = IPC_MULTICAST_COMMAND;
287     cds->cbData = (DWORD)(msglen * sizeof(wchar_t));
288     cds->lpData = msg;
289    
290     return cds;
291     }
292    
293 zmatsuo 8823 /*
294     * �_�C�A���O���I���������E�B���h�E�����A���������e�E�B���h�E�����������u���[�h�L���X�g���[�h�B
295     * ���A���^�C�����[�h�� off ���������p�������B
296     */
297 zmatsuo 8826 static void SendBroadcastMessageToSelected(HWND HVTWin, HWND hWnd, int parent_only, const wchar_t *buf)
298 zmatsuo 8823 {
299 zmatsuo 8826 COPYDATASTRUCT *cds = BuildBroadcastCDSW(buf);
300 zmatsuo 8823
301     if (parent_only) {
302     // �e�E�B���h�E������ WM_COPYDATA ���b�Z�[�W������
303 zmatsuo 8826 SendMessage(GetParent(hWnd), WM_COPYDATA, (WPARAM)HVTWin, (LPARAM)cds);
304 zmatsuo 8823 }
305     else {
306     // �_�C�A���O���I���������E�B���h�E�����b�Z�[�W������
307 zmatsuo 8826 int count = (int)SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0);
308     for (int i = 0 ; i < count ; i++) {
309 zmatsuo 8823 // ���X�g�{�b�N�X���I��������������
310     if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) {
311 zmatsuo 8826 HWND hd = GetNthWin(i);
312     if (hd != NULL) {
313 zmatsuo 8823 // WM_COPYDATA���g�����A�v���Z�X�����M���s���B
314 zmatsuo 8826 SendMessage(hd, WM_COPYDATA, (WPARAM)HVTWin, (LPARAM)cds);
315 zmatsuo 8823 }
316     }
317     }
318     }
319 zmatsuo 8826
320     free(cds);
321 zmatsuo 8823 }
322    
323 zmatsuo 8826 /**
324     * �S Tera Term ��COPYDATASTRUCT�����M����
325     * @param[in] hWnd ���M��
326     * @param[in] cds COPYDATASTRUCT
327 zmatsuo 8823 */
328 zmatsuo 8826 static void SendCDS(HWND hWnd, const COPYDATASTRUCT *cds)
329 zmatsuo 8823 {
330 zmatsuo 8826 int count = GetRegisteredWindowCount();
331     for (int i = 0 ; i < count ; i++) {
332     HWND hd = GetNthWin(i);
333     if (hd == NULL) {
334 zmatsuo 8823 break;
335     }
336     // WM_COPYDATA���g�����A�v���Z�X�����M���s���B
337 zmatsuo 8826 SendMessage(hd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)cds);
338 zmatsuo 8823 }
339     }
340    
341     /*
342 zmatsuo 8826 * �S Tera Term �����b�Z�[�W�����M�����u���[�h�L���X�g���[�h�B
343     * "sendbroadcast"�}�N���R�}���h�����������p�������B
344 zmatsuo 8823 */
345 zmatsuo 8826 void SendBroadcastMessage(HWND HVTWin, HWND hWnd, const wchar_t *buf)
346 zmatsuo 8823 {
347 zmatsuo 8826 COPYDATASTRUCT *cds = BuildBroadcastCDSW(buf);
348     SendCDS(HVTWin, cds);
349     free(cds);
350     }
351 zmatsuo 8823
352 zmatsuo 8826 static COPYDATASTRUCT *BuildMulticastCopyData(const char *name, const char *buf)
353     {
354     size_t buflen = strlen(buf);
355     size_t nlen = strlen(name) + 1;
356     size_t msglen = nlen + buflen;
357     char *msg = (char *)malloc(msglen);
358     if (msg == NULL) {
359     return NULL;
360 zmatsuo 8823 }
361     strcpy_s(msg, msglen, name);
362     memcpy_s(msg + nlen, msglen - nlen, buf, buflen);
363    
364 zmatsuo 8826 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)malloc(sizeof(COPYDATASTRUCT));
365     if (cds == NULL) {
366     free(msg);
367     return NULL;
368 zmatsuo 8823 }
369 zmatsuo 8826 cds->dwData = IPC_MULTICAST_COMMAND;
370     cds->cbData = (DWORD)msglen;
371     cds->lpData = msg;
372 zmatsuo 8823
373 zmatsuo 8826 return cds;
374 zmatsuo 8823 }
375    
376 zmatsuo 8826 /*
377     * �C���� Tera Term �Q�����b�Z�[�W�����M�����}���`�L���X�g���[�h�B���������A
378     * �u���[�h�L���X�g���M���s���A���M�������b�Z�[�W�������I�������B
379     * "sendmulticast"�}�N���R�}���h�����������p�������B
380     */
381     void SendMulticastMessage(HWND HVTWin_, HWND hWnd, const wchar_t *name, const wchar_t *buf)
382 zmatsuo 8823 {
383 zmatsuo 8826 COPYDATASTRUCT *cdsW = BuildMulticastCDSW(name, buf);
384     SendCDS(HVTWin_, cdsW);
385     free(cdsW->lpData);
386     free(cdsW);
387 zmatsuo 8823 }
388    
389 zmatsuo 8826 void SetMulticastName(const wchar_t *name)
390 zmatsuo 8823 {
391 zmatsuo 8826 // TODO MulticastName �� wchar_t ��
392     char *nameA = ToCharW(name);
393     strncpy_s(ts.MulticastName, sizeof(ts.MulticastName), nameA, _TRUNCATE);
394     free(nameA);
395 zmatsuo 8823 }
396    
397 zmatsuo 8826 static int CompareMulticastName(const wchar_t *name)
398     {
399     // TODO MulticastName �� wchar_t ��
400     wchar_t *MulticastNameW = ToWcharA(ts.MulticastName);
401     int result = wcscmp(MulticastNameW, name);
402     free(MulticastNameW);
403     return result;
404     }
405    
406 zmatsuo 8823 //
407     // ���������^�[�~�i���������R�}���h�����M�������[�h���X�_�C�A���O���\��
408     // (2005.1.22 yutaka)
409     //
410 zmatsuo 8826 static INT_PTR CALLBACK BroadcastCommandDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
411 zmatsuo 8823 {
412     static const DlgTextInfo TextInfos[] = {
413     { 0, "DLG_BROADCAST_TITLE" },
414     { IDC_HISTORY_CHECK, "DLG_BROADCAST_HISTORY" },
415     { IDC_ENTERKEY_CHECK, "DLG_BROADCAST_ENTER" },
416     { IDC_PARENT_ONLY, "DLG_BROADCAST_PARENTONLY" },
417     { IDC_REALTIME_CHECK, "DLG_BROADCAST_REALTIME" },
418     { IDOK, "DLG_BROADCAST_SUBMIT" },
419     { IDCANCEL, "BTN_CLOSE" },
420     };
421     LRESULT checked;
422     LRESULT history;
423     char historyfile[MAX_PATH];
424     static HWND hwndBroadcast = NULL; // Broadcast dropdown
425     static HWND hwndBroadcastEdit = NULL; // Edit control on Broadcast dropdown
426     // for resize
427     RECT rc_dlg, rc, rc_ok;
428     POINT p;
429     static int ok2right, cancel2right, cmdlist2ok, list2bottom, list2right;
430     // for update list
431     const int list_timer_id = 100;
432     const int list_timer_tick = 1000; // msec
433     static int prev_instances = 0;
434     // for status bar
435     static HWND hStatus = NULL;
436     static int init_width, init_height;
437    
438     switch (msg) {
439     case WM_SHOWWINDOW:
440     if (wp) { // show
441     // Tera Term window list
442     UpdateBroadcastWindowList(GetDlgItem(hWnd, IDC_LIST));
443     return TRUE;
444     }
445     break;
446    
447     case WM_INITDIALOG:
448     // ���W�I�{�^�����f�t�H���g�� CR �������B
449     SendMessage(GetDlgItem(hWnd, IDC_RADIO_CR), BM_SETCHECK, BST_CHECKED, 0);
450     // �f�t�H���g���`�F�b�N�{�b�N�X�� checked �����������B
451     SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_SETCHECK, BST_CHECKED, 0);
452     // history �����f���� (2007.3.3 maya)
453     if (ts.BroadcastCommandHistory) {
454     SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_SETCHECK, BST_CHECKED, 0);
455     }
456     GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile));
457     ApplyBroadCastCommandHisotry(hWnd, historyfile);
458    
459     // �G�f�B�b�g�R���g���[�����t�H�[�J�X��������
460     SetFocus(GetDlgItem(hWnd, IDC_COMMAND_EDIT));
461    
462     // �T�u�N���X�����������A���^�C�����[�h������ (2008.1.21 yutaka)
463     hwndBroadcast = GetDlgItem(hWnd, IDC_COMMAND_EDIT);
464     hwndBroadcastEdit = GetWindow(hwndBroadcast, GW_CHILD);
465 zmatsuo 8826 OrigBroadcastEditProc = (WNDPROC)_SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)BroadcastEditProc);
466 zmatsuo 8823 // �f�t�H���g��on�B�c����disable�B
467     SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_SETCHECK, BST_CHECKED, 0); // default on
468     EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), FALSE);
469     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE);
470     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE);
471     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE);
472     EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), FALSE);
473     EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), FALSE);
474    
475     // Tera Term window list
476     BroadcastWindowList = GetDlgItem(hWnd, IDC_LIST);
477     UpdateBroadcastWindowList(BroadcastWindowList);
478    
479     // I18N
480     SetDlgTexts(hWnd, TextInfos, _countof(TextInfos), ts.UILanguageFile);
481    
482     // �_�C�A���O�������T�C�Y������
483     GetWindowRect(hWnd, &rc_dlg);
484     init_width = rc_dlg.right - rc_dlg.left;
485     init_height = rc_dlg.bottom - rc_dlg.top;
486    
487     // �����T�C�Y�����K�v���l���v�Z
488     GetClientRect(hWnd, &rc_dlg);
489     p.x = rc_dlg.right;
490     p.y = rc_dlg.bottom;
491     ClientToScreen(hWnd, &p);
492    
493     GetWindowRect(GetDlgItem(hWnd, IDOK), &rc_ok);
494     ok2right = p.x - rc_ok.left;
495    
496     GetWindowRect(GetDlgItem(hWnd, IDCANCEL), &rc);
497     cancel2right = p.x - rc.left;
498    
499     GetWindowRect(GetDlgItem(hWnd, IDC_COMMAND_EDIT), &rc);
500     cmdlist2ok = rc_ok.left - rc.right;
501    
502     GetWindowRect(GetDlgItem(hWnd, IDC_LIST), &rc);
503     list2bottom = p.y - rc.bottom;
504     list2right = p.x - rc.right;
505    
506     // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
507     InitCommonControls();
508     hStatus = CreateStatusWindow(
509     WS_CHILD | WS_VISIBLE |
510     CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hWnd, 1);
511    
512     // ���X�g�X�V�^�C�}�[���J�n
513     SetTimer(hWnd, list_timer_id, list_timer_tick, NULL);
514    
515     return FALSE;
516    
517     case WM_COMMAND:
518     switch (wp) {
519     case IDC_ENTERKEY_CHECK | (BN_CLICKED << 16):
520     // �`�F�b�N���L���������A���W�I�{�^�����L���E�������������B
521     checked = SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_GETCHECK, 0, 0);
522     if (checked & BST_CHECKED) { // ���s�R�[�h����
523     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), TRUE);
524     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), TRUE);
525     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), TRUE);
526    
527     } else {
528     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE);
529     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE);
530     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE);
531     }
532     return TRUE;
533    
534     case IDC_REALTIME_CHECK | (BN_CLICKED << 16):
535     checked = SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_GETCHECK, 0, 0);
536     if (checked & BST_CHECKED) { // check����
537     // new handler
538     hwndBroadcast = GetDlgItem(hWnd, IDC_COMMAND_EDIT);
539     hwndBroadcastEdit = GetWindow(hwndBroadcast, GW_CHILD);
540 zmatsuo 8826 OrigBroadcastEditProc = (WNDPROC)_SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)BroadcastEditProc);
541 zmatsuo 8823
542     EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), FALSE);
543     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE);
544     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE);
545     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE);
546     EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), FALSE);
547     EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), FALSE);
548     EnableWindow(GetDlgItem(hWnd, IDC_LIST), TRUE); // true
549     } else {
550     // restore old handler
551 zmatsuo 8826 _SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)OrigBroadcastEditProc);
552 zmatsuo 8823
553     EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), TRUE);
554     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), TRUE);
555     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), TRUE);
556     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), TRUE);
557     EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), TRUE);
558     EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), TRUE);
559     EnableWindow(GetDlgItem(hWnd, IDC_LIST), TRUE); // true
560     }
561     return TRUE;
562     }
563    
564     switch (LOWORD(wp)) {
565     case IDOK:
566     {
567 zmatsuo 8826 wchar_t buf[256 + 3];
568     //memset(buf, 0, sizeof(buf));
569 zmatsuo 8823
570     // realtime mode�������AEnter key���������B
571     // cf. http://logmett.com/forum/viewtopic.php?f=8&t=1601
572     // (2011.3.14 hirata)
573     checked = SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_GETCHECK, 0, 0);
574     if (checked & BST_CHECKED) { // check����
575 zmatsuo 8826 wcsncpy_s(buf, _countof(buf), L"\n", _TRUNCATE);
576     SetDlgItemTextA(hWnd, IDC_COMMAND_EDIT, "");
577 zmatsuo 8823 }
578 zmatsuo 8826 else {
579     UINT ret = _GetDlgItemTextW(hWnd, IDC_COMMAND_EDIT, buf, 256 - 1);
580     if (ret == 0) { // error
581     memset(buf, 0, sizeof(buf));
582     }
583 zmatsuo 8823
584 zmatsuo 8826 // �u���[�h�L���X�g�R�}���h������������ (2007.3.3 maya)
585     history = SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_GETCHECK, 0, 0);
586     if (history) {
587     GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile));
588     if (LoadTTSET()) {
589     char *bufA = ToCharW(buf); // TODO wchar_t ����
590     (*AddValueToList)(historyfile, bufA, "BroadcastCommands", "Command",
591     ts.MaxBroadcatHistory);
592     free(bufA);
593     FreeTTSET();
594     }
595     ApplyBroadCastCommandHisotry(hWnd, historyfile);
596     ts.BroadcastCommandHistory = TRUE;
597 zmatsuo 8823 }
598 zmatsuo 8826 else {
599     ts.BroadcastCommandHistory = FALSE;
600     }
601     checked = SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_GETCHECK, 0, 0);
602     if (checked & BST_CHECKED) { // ���s�R�[�h����
603     if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_CRLF), BM_GETCHECK, 0, 0) & BST_CHECKED) {
604     wcsncat_s(buf, _countof(buf), L"\r\n", _TRUNCATE);
605 zmatsuo 8823
606 zmatsuo 8826 } else if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_CR), BM_GETCHECK, 0, 0) & BST_CHECKED) {
607     wcsncat_s(buf, _countof(buf), L"\r", _TRUNCATE);
608 zmatsuo 8823
609 zmatsuo 8826 } else if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_LF), BM_GETCHECK, 0, 0) & BST_CHECKED) {
610     wcsncat_s(buf, _countof(buf), L"\n", _TRUNCATE);
611 zmatsuo 8823
612 zmatsuo 8826 } else {
613     wcsncat_s(buf, _countof(buf), L"\r", _TRUNCATE);
614 zmatsuo 8823
615 zmatsuo 8826 }
616 zmatsuo 8823 }
617     }
618    
619     // 337: 2007/03/20 �`�F�b�N�������������e�E�B���h�E���������M
620     checked = SendMessage(GetDlgItem(hWnd, IDC_PARENT_ONLY), BM_GETCHECK, 0, 0);
621    
622 zmatsuo 8826 SendBroadcastMessageToSelected(HVTWin, hWnd, (int)checked, buf);
623 zmatsuo 8823 }
624    
625     // ���[�h���X�_�C�A���O�����x�������������A�A�v���P�[�V�������I����������
626     // �j���������������A�������u�E�B���h�E�v���V�[�W�������v���s�v���v�������B(yutaka)
627     #if 0
628 zmatsuo 8826 _SetWindowLongPtrW(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)OrigBroadcastEditProc);
629 zmatsuo 8823 #endif
630    
631     //EndDialog(hDlgWnd, IDOK);
632     return TRUE;
633    
634     case IDCANCEL:
635     EndDialog(hWnd, 0);
636     //DestroyWindow(hWnd);
637    
638     return TRUE;
639    
640     case IDC_COMMAND_EDIT:
641     if (HIWORD(wp) == CBN_DROPDOWN) {
642     GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile));
643     ApplyBroadCastCommandHisotry(hWnd, historyfile);
644     }
645     return FALSE;
646    
647     case IDC_LIST:
648     // �����I���A�v���P�[�V�������������������������������A
649     // �uSHIFT+�N���b�N�v�������A���I���I�����T�|�[�g�����B
650     // (2009.9.28 yutaka)
651     if (HIWORD(wp) == LBN_SELCHANGE && ShiftKey()) {
652     int i, cur, prev;
653    
654     cur = ListBox_GetCurSel(BroadcastWindowList);
655     prev = -1;
656     for (i = cur - 1 ; i >= 0 ; i--) {
657     if (ListBox_GetSel(BroadcastWindowList, i)) {
658     prev = i;
659     break;
660     }
661     }
662     if (prev != -1) {
663     // �������I���������������������A���������A���I�������B
664     for (i = prev ; i < cur ; i++) {
665     ListBox_SetSel(BroadcastWindowList, TRUE, i);
666     }
667     }
668     }
669    
670     return FALSE;
671    
672     default:
673     return FALSE;
674     }
675     break;
676    
677     case WM_CLOSE:
678     //DestroyWindow(hWnd);
679     EndDialog(hWnd, 0);
680     return TRUE;
681    
682     case WM_SIZE:
683     {
684     // ���z�u
685     int dlg_w, dlg_h;
686     RECT rc_dlg;
687     RECT rc;
688     POINT p;
689    
690     // �V�����_�C�A���O���T�C�Y������
691     GetClientRect(hWnd, &rc_dlg);
692     dlg_w = rc_dlg.right;
693     dlg_h = rc_dlg.bottom;
694    
695     // OK button
696     GetWindowRect(GetDlgItem(hWnd, IDOK), &rc);
697     p.x = rc.left;
698     p.y = rc.top;
699     ScreenToClient(hWnd, &p);
700     SetWindowPos(GetDlgItem(hWnd, IDOK), 0,
701     dlg_w - ok2right, p.y, 0, 0,
702     SWP_NOSIZE | SWP_NOZORDER);
703    
704     // Cancel button
705     GetWindowRect(GetDlgItem(hWnd, IDCANCEL), &rc);
706     p.x = rc.left;
707     p.y = rc.top;
708     ScreenToClient(hWnd, &p);
709     SetWindowPos(GetDlgItem(hWnd, IDCANCEL), 0,
710     dlg_w - cancel2right, p.y, 0, 0,
711     SWP_NOSIZE | SWP_NOZORDER);
712    
713     // Command Edit box
714     GetWindowRect(GetDlgItem(hWnd, IDC_COMMAND_EDIT), &rc);
715     p.x = rc.left;
716     p.y = rc.top;
717     ScreenToClient(hWnd, &p);
718     SetWindowPos(GetDlgItem(hWnd, IDC_COMMAND_EDIT), 0,
719     0, 0, dlg_w - p.x - ok2right - cmdlist2ok, p.y,
720     SWP_NOMOVE | SWP_NOZORDER);
721    
722     // List Edit box
723     GetWindowRect(GetDlgItem(hWnd, IDC_LIST), &rc);
724     p.x = rc.left;
725     p.y = rc.top;
726     ScreenToClient(hWnd, &p);
727     SetWindowPos(GetDlgItem(hWnd, IDC_LIST), 0,
728     0, 0, dlg_w - p.x - list2right , dlg_h - p.y - list2bottom,
729     SWP_NOMOVE | SWP_NOZORDER);
730    
731     // status bar
732     SendMessage(hStatus , msg , wp , lp);
733     }
734     return TRUE;
735    
736     case WM_GETMINMAXINFO:
737     {
738     // �_�C�A���O�������T�C�Y����������������������������
739     LPMINMAXINFO lpmmi;
740     lpmmi = (LPMINMAXINFO)lp;
741     lpmmi->ptMinTrackSize.x = init_width;
742     lpmmi->ptMinTrackSize.y = init_height;
743     }
744     return FALSE;
745    
746     case WM_TIMER:
747     {
748     int n;
749    
750     if (wp != list_timer_id)
751     break;
752    
753     n = GetRegisteredWindowCount();
754     if (n != prev_instances) {
755     prev_instances = n;
756     UpdateBroadcastWindowList(BroadcastWindowList);
757     }
758     }
759     return TRUE;
760    
761     case WM_VKEYTOITEM:
762     // ���X�g�{�b�N�X���L�[����(CTRL+A)���������A�S�I���B
763     if ((HWND)lp == BroadcastWindowList) {
764     if (ControlKey() && LOWORD(wp) == 'A') {
765     int i, n;
766    
767     //OutputDebugPrintf("msg %x wp %x lp %x\n", msg, wp, lp);
768     n = GetRegisteredWindowCount();
769     for (i = 0 ; i < n ; i++) {
770     ListBox_SetSel(BroadcastWindowList, TRUE, i);
771     }
772     }
773     }
774     return TRUE;
775    
776     default:
777     //OutputDebugPrintf("msg %x wp %x lp %x\n", msg, wp, lp);
778     return FALSE;
779     }
780     return TRUE;
781     }
782    
783     static HWND hDlgWnd = NULL;
784    
785     void BroadCastShowDialog(HINSTANCE hInst, HWND hWnd)
786     {
787     RECT prc, rc;
788     LONG x, y;
789    
790     if (hDlgWnd != NULL) {
791     goto activate;
792     }
793    
794 zmatsuo 8826 SetDialogFont(ts.DialogFontName, ts.DialogFontPoint, ts.DialogFontCharSet,
795     ts.UILanguageFile, "Tera Term", "DLG_SYSTEM_FONT");
796    
797     // CreateDialogW() �����������_�C�A���O���A
798     // �G�f�B�b�g�{�b�N�X��IME���������������������������� (20/05/27,Windows10 64bit)
799     // �y�[�X�g��ok
800 zmatsuo 8823 hDlgWnd = TTCreateDialog(hInst, MAKEINTRESOURCE(IDD_BROADCAST_DIALOG),
801 zmatsuo 8826 hWnd, BroadcastCommandDlgProc);
802 zmatsuo 8823
803     if (hDlgWnd == NULL) {
804     return;
805     }
806    
807     // �_�C�A���O���E�B���h�E���^�����z�u���� (2008.1.25 yutaka)
808     ::GetWindowRect(hWnd, &prc);
809     ::GetWindowRect(hDlgWnd, &rc);
810     x = prc.left;
811     y = prc.top - (rc.bottom - rc.top);
812     if (y < 0) {
813     y = 0;
814     }
815     ::SetWindowPos(hDlgWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
816    
817     activate:;
818     ::ShowWindow(hDlgWnd, SW_SHOW);
819     }
820    
821 zmatsuo 8826 BOOL BroadCastReceive(const COPYDATASTRUCT *cds)
822 zmatsuo 8823 {
823 zmatsuo 8826 wchar_t *strW_ptr;
824     size_t strW_len = 0;
825 zmatsuo 8823
826 zmatsuo 8826 switch (cds->dwData) {
827     case IPC_BROADCAST_COMMAND: {
828     strW_len = cds->cbData / sizeof(wchar_t);
829     strW_ptr = (wchar_t *)malloc((strW_len + 1) * sizeof(wchar_t));
830     wmemcpy_s(strW_ptr, strW_len, (wchar_t *)cds->lpData, strW_len);
831     strW_ptr[strW_len] = 0; // �O����
832     break;
833     }
834     case IPC_MULTICAST_COMMAND: {
835     wchar_t *name = (wchar_t *)cds->lpData;
836 zmatsuo 8823
837     // �}���`�L���X�g�����`�F�b�N����
838 zmatsuo 8826 if (CompareMulticastName(name) != 0) {
839     // ���O����������������������������
840     return TRUE;
841 zmatsuo 8823 }
842 zmatsuo 8826
843     // �}���`�L���X�g��������������������
844     size_t nlen = wcslen(name);
845     strW_len = cds->cbData / sizeof(wchar_t) - nlen - 1; // -1 = name �� '\0'
846     strW_ptr = (wchar_t *)malloc((strW_len + 1) * sizeof(wchar_t));
847     wmemcpy_s(strW_ptr, strW_len, (wchar_t *)cds->lpData + nlen + 1, strW_len);
848     strW_ptr[strW_len] = 0; // �O����
849     break;
850 zmatsuo 8823 }
851    
852 zmatsuo 8826 default:
853     // �m���������b�Z�[�W������
854     return TRUE;
855 zmatsuo 8823 }
856 zmatsuo 8826
857     // �[��������������������
858     SendMem *sm = SendMemTextW(strW_ptr, strW_len);
859     if (sm != NULL) {
860     SendMemInitEcho(sm, FALSE);
861     SendMemInitDelay(sm, SENDMEM_DELAYTYPE_PER_LINE, 10, 0);
862     SendMemStart(sm);
863     }
864    
865     return TRUE;
866 zmatsuo 8823 }

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