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 8823 - (hide annotations) (download) (as text)
Fri Jul 3 14:42:55 2020 UTC (3 years, 9 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/broadcast.cpp
File MIME type: text/x-c++src
File size: 22341 byte(s)
ブロードキャスト関連を vtwin.cpp から broadcast.cpp へ分離
1 zmatsuo 8823 /*
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     // vtwin��������
30    
31     #include "teraterm_conf.h"
32     #include "teraterm.h"
33     #include "tttypes.h"
34     #include "ttcommon.h"
35     #include "ttwinman.h"
36    
37     #include <stdio.h>
38     #define _CRTDBG_MAP_ALLOC
39     #include <stdlib.h>
40     #include <crtdbg.h>
41     #include <string.h>
42     #include <windowsx.h>
43     #include <commctrl.h>
44    
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     #include "clipboar.h"
51    
52     #include "broadcast.h"
53    
54    
55     // WM_COPYDATA�������v���Z�X�����M������ (2005.1.22 yutaka)
56     #define IPC_BROADCAST_COMMAND 1 // �S�[�������M
57     #define IPC_MULTICAST_COMMAND 2 // �C�����[���Q�����M
58    
59     #define BROADCAST_LOGFILE "broadcast.log"
60    
61    
62     static void ApplyBroadCastCommandHisotry(HWND Dialog, char *historyfile)
63     {
64     char EntName[13];
65     char Command[HostNameMaxLength+1];
66     int i = 1;
67    
68     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_RESETCONTENT, 0, 0);
69     do {
70     _snprintf_s(EntName, sizeof(EntName), _TRUNCATE, "Command%d", i);
71     GetPrivateProfileString("BroadcastCommands",EntName,"",
72     Command,sizeof(Command), historyfile);
73     if (strlen(Command) > 0) {
74     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_ADDSTRING,
75     0, (LPARAM)Command);
76     }
77     i++;
78     } while ((i <= ts.MaxBroadcatHistory) && (strlen(Command)>0));
79    
80     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, EM_LIMITTEXT,
81     HostNameMaxLength-1, 0);
82    
83     SendDlgItemMessage(Dialog, IDC_COMMAND_EDIT, CB_SETCURSEL,0,0);
84     }
85    
86     // �h���b�v�_�E���������G�f�B�b�g�R���g���[����
87     // �T�u�N���X�������������E�C���h�E�v���V�[�W��
88     static WNDPROC OrigBroadcastEditProc; // Original window procedure
89     static HWND BroadcastWindowList;
90     static LRESULT CALLBACK BroadcastEditProc(HWND dlg, UINT msg,
91     WPARAM wParam, LPARAM lParam)
92     {
93     char buf[1024];
94     int len;
95    
96     switch (msg) {
97     case WM_CREATE:
98     break;
99    
100     case WM_DESTROY:
101     break;
102    
103     case WM_LBUTTONUP:
104     // �������e�L�X�g�����������������������A�J�[�\���������������������B
105     len = GetWindowText(dlg, buf, sizeof(buf));
106     SendMessage(dlg, EM_SETSEL, len, len);
107     SetFocus(dlg);
108     break;
109    
110     case WM_LBUTTONDOWN:
111     case WM_RBUTTONDOWN:
112     case WM_RBUTTONUP:
113     SetFocus(dlg);
114     break;
115    
116     case WM_KEYDOWN:
117     case WM_KEYUP:
118     case WM_SYSKEYDOWN:
119     case WM_SYSKEYUP:
120     {
121     int i;
122     HWND hd;
123     int count;
124    
125     if (wParam == 0x0d) { // Enter key
126     SetWindowText(dlg, "");
127     SendMessage(dlg, EM_SETSEL, 0, 0);
128     }
129    
130     count = SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0);
131     for (i = 0 ; i < count ; i++) {
132     if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) {
133     hd = GetNthWin(i);
134     if (hd) {
135     PostMessage(hd, msg, wParam, lParam);
136     }
137     }
138     }
139     }
140     break;
141    
142     case WM_CHAR:
143     // ��������������IDC_COMMAND_EDIT���c������������������
144     return FALSE;
145    
146     default:
147     return CallWindowProc(OrigBroadcastEditProc, dlg, msg, wParam, lParam);
148     }
149    
150     return FALSE;
151     }
152    
153     static void UpdateBroadcastWindowList(HWND hWnd)
154     {
155     int i, count;
156     HWND hd;
157     TCHAR szWindowText[256];
158    
159     SendMessage(hWnd, LB_RESETCONTENT, 0, 0);
160    
161     count = GetRegisteredWindowCount();
162     for (i = 0 ; i < count ; i++) {
163     hd = GetNthWin(i);
164     if (hd == NULL) {
165     break;
166     }
167    
168     GetWindowText(hd, szWindowText, 256);
169     SendMessage(hWnd, LB_INSERTSTRING, -1, (LPARAM)szWindowText);
170     }
171     }
172    
173     /*
174     * �_�C�A���O���I���������E�B���h�E�����A���������e�E�B���h�E�����������u���[�h�L���X�g���[�h�B
175     * ���A���^�C�����[�h�� off ���������p�������B
176     */
177     static void SendBroadcastMessageToSelected(HWND HVTWin, HWND hWnd, int parent_only, char *buf, int buflen)
178     {
179     int i;
180     int count;
181     HWND hd;
182     COPYDATASTRUCT cds;
183    
184     ZeroMemory(&cds, sizeof(cds));
185     cds.dwData = IPC_BROADCAST_COMMAND;
186     cds.cbData = buflen;
187     cds.lpData = buf;
188    
189     if (parent_only) {
190     // �e�E�B���h�E������ WM_COPYDATA ���b�Z�[�W������
191     SendMessage(GetParent(hWnd), WM_COPYDATA, (WPARAM)HVTWin, (LPARAM)&cds);
192     }
193     else {
194     // �_�C�A���O���I���������E�B���h�E�����b�Z�[�W������
195     count = SendMessage(BroadcastWindowList, LB_GETCOUNT, 0, 0);
196     for (i = 0 ; i < count ; i++) {
197     // ���X�g�{�b�N�X���I��������������
198     if (SendMessage(BroadcastWindowList, LB_GETSEL, i, 0)) {
199     if ((hd = GetNthWin(i)) != NULL) {
200     // WM_COPYDATA���g�����A�v���Z�X�����M���s���B
201     SendMessage(hd, WM_COPYDATA, (WPARAM)HVTWin, (LPARAM)&cds);
202     }
203     }
204     }
205     }
206     }
207    
208     /*
209     * �S Tera Term �����b�Z�[�W�����M�����u���[�h�L���X�g���[�h�B
210     * "sendbroadcast"�}�N���R�}���h�����������p�������B
211     */
212     void SendBroadcastMessage(HWND HVTWin, HWND hWnd, char *buf, int buflen)
213     {
214     int i, count;
215     HWND hd;
216     COPYDATASTRUCT cds;
217    
218     ZeroMemory(&cds, sizeof(cds));
219     cds.dwData = IPC_BROADCAST_COMMAND;
220     cds.cbData = buflen;
221     cds.lpData = buf;
222    
223     count = GetRegisteredWindowCount();
224    
225     // �S Tera Term �����b�Z�[�W�������B
226     for (i = 0 ; i < count ; i++) {
227     if ((hd = GetNthWin(i)) == NULL) {
228     break;
229     }
230     // WM_COPYDATA���g�����A�v���Z�X�����M���s���B
231     SendMessage(hd, WM_COPYDATA, (WPARAM)HVTWin, (LPARAM)&cds);
232     }
233     }
234    
235    
236     /*
237     * �C���� Tera Term �Q�����b�Z�[�W�����M�����}���`�L���X�g���[�h�B���������A
238     * �u���[�h�L���X�g���M���s���A���M�������b�Z�[�W�������I�������B
239     * "sendmulticast"�}�N���R�}���h�����������p�������B
240     */
241     void SendMulticastMessage(HWND hVTWin_, HWND hWnd, char *name, char *buf, int buflen)
242     {
243     int i, count;
244     HWND hd;
245     COPYDATASTRUCT cds;
246     char *msg = NULL;
247     int msglen, nlen;
248    
249     /* ���M���b�Z�[�W���\�z�����B
250     *
251     * msg
252     * +------+--------------+--+
253     * |name\0|buf |\0|
254     * +------+--------------+--+
255     * <--------------------->
256     * msglen = strlen(name) + 1 + buflen
257     * buf���������� \0 ���t�������B
258     */
259     nlen = strlen(name) + 1;
260     msglen = nlen + buflen;
261     if ((msg = (char *)malloc(msglen)) == NULL) {
262     return;
263     }
264     strcpy_s(msg, msglen, name);
265     memcpy_s(msg + nlen, msglen - nlen, buf, buflen);
266    
267     ZeroMemory(&cds, sizeof(cds));
268     cds.dwData = IPC_MULTICAST_COMMAND;
269     cds.cbData = msglen;
270     cds.lpData = msg;
271    
272     count = GetRegisteredWindowCount();
273    
274     // ��������Tera Term�����b�Z�[�W���f�[�^������
275     for (i = 0 ; i < count ; i++) {
276     if ((hd = GetNthWin(i)) == NULL) {
277     break;
278     }
279    
280     // WM_COPYDATA���g�����A�v���Z�X�����M���s���B
281     SendMessage(hd, WM_COPYDATA, (WPARAM)hVTWin_, (LPARAM)&cds);
282     }
283    
284     free(msg);
285     }
286    
287     void SetMulticastName(char *name)
288     {
289     strncpy_s(ts.MulticastName, sizeof(ts.MulticastName), name, _TRUNCATE);
290     }
291    
292     static int CompareMulticastName(char *name)
293     {
294     return strcmp(ts.MulticastName, name);
295     }
296    
297     //
298     // ���������^�[�~�i���������R�}���h�����M�������[�h���X�_�C�A���O���\��
299     // (2005.1.22 yutaka)
300     //
301     static LRESULT CALLBACK BroadcastCommandDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
302     {
303     static const DlgTextInfo TextInfos[] = {
304     { 0, "DLG_BROADCAST_TITLE" },
305     { IDC_HISTORY_CHECK, "DLG_BROADCAST_HISTORY" },
306     { IDC_ENTERKEY_CHECK, "DLG_BROADCAST_ENTER" },
307     { IDC_PARENT_ONLY, "DLG_BROADCAST_PARENTONLY" },
308     { IDC_REALTIME_CHECK, "DLG_BROADCAST_REALTIME" },
309     { IDOK, "DLG_BROADCAST_SUBMIT" },
310     { IDCANCEL, "BTN_CLOSE" },
311     };
312     char buf[256 + 3];
313     UINT ret;
314     LRESULT checked;
315     LRESULT history;
316     char historyfile[MAX_PATH];
317     static HWND hwndBroadcast = NULL; // Broadcast dropdown
318     static HWND hwndBroadcastEdit = NULL; // Edit control on Broadcast dropdown
319     // for resize
320     RECT rc_dlg, rc, rc_ok;
321     POINT p;
322     static int ok2right, cancel2right, cmdlist2ok, list2bottom, list2right;
323     // for update list
324     const int list_timer_id = 100;
325     const int list_timer_tick = 1000; // msec
326     static int prev_instances = 0;
327     // for status bar
328     static HWND hStatus = NULL;
329     static int init_width, init_height;
330    
331     switch (msg) {
332     case WM_SHOWWINDOW:
333     if (wp) { // show
334     // Tera Term window list
335     UpdateBroadcastWindowList(GetDlgItem(hWnd, IDC_LIST));
336     return TRUE;
337     }
338     break;
339    
340     case WM_INITDIALOG:
341     // ���W�I�{�^�����f�t�H���g�� CR �������B
342     SendMessage(GetDlgItem(hWnd, IDC_RADIO_CR), BM_SETCHECK, BST_CHECKED, 0);
343     // �f�t�H���g���`�F�b�N�{�b�N�X�� checked �����������B
344     SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_SETCHECK, BST_CHECKED, 0);
345     // history �����f���� (2007.3.3 maya)
346     if (ts.BroadcastCommandHistory) {
347     SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_SETCHECK, BST_CHECKED, 0);
348     }
349     GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile));
350     ApplyBroadCastCommandHisotry(hWnd, historyfile);
351    
352     // �G�f�B�b�g�R���g���[�����t�H�[�J�X��������
353     SetFocus(GetDlgItem(hWnd, IDC_COMMAND_EDIT));
354    
355     // �T�u�N���X�����������A���^�C�����[�h������ (2008.1.21 yutaka)
356     hwndBroadcast = GetDlgItem(hWnd, IDC_COMMAND_EDIT);
357     hwndBroadcastEdit = GetWindow(hwndBroadcast, GW_CHILD);
358     OrigBroadcastEditProc = (WNDPROC)GetWindowLongPtr(hwndBroadcastEdit, GWLP_WNDPROC);
359     SetWindowLongPtr(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)BroadcastEditProc);
360     // �f�t�H���g��on�B�c����disable�B
361     SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_SETCHECK, BST_CHECKED, 0); // default on
362     EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), FALSE);
363     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE);
364     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE);
365     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE);
366     EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), FALSE);
367     EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), FALSE);
368    
369     // Tera Term window list
370     BroadcastWindowList = GetDlgItem(hWnd, IDC_LIST);
371     UpdateBroadcastWindowList(BroadcastWindowList);
372    
373     // I18N
374     SetDlgTexts(hWnd, TextInfos, _countof(TextInfos), ts.UILanguageFile);
375    
376     // �_�C�A���O�������T�C�Y������
377     GetWindowRect(hWnd, &rc_dlg);
378     init_width = rc_dlg.right - rc_dlg.left;
379     init_height = rc_dlg.bottom - rc_dlg.top;
380    
381     // �����T�C�Y�����K�v���l���v�Z
382     GetClientRect(hWnd, &rc_dlg);
383     p.x = rc_dlg.right;
384     p.y = rc_dlg.bottom;
385     ClientToScreen(hWnd, &p);
386    
387     GetWindowRect(GetDlgItem(hWnd, IDOK), &rc_ok);
388     ok2right = p.x - rc_ok.left;
389    
390     GetWindowRect(GetDlgItem(hWnd, IDCANCEL), &rc);
391     cancel2right = p.x - rc.left;
392    
393     GetWindowRect(GetDlgItem(hWnd, IDC_COMMAND_EDIT), &rc);
394     cmdlist2ok = rc_ok.left - rc.right;
395    
396     GetWindowRect(GetDlgItem(hWnd, IDC_LIST), &rc);
397     list2bottom = p.y - rc.bottom;
398     list2right = p.x - rc.right;
399    
400     // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
401     InitCommonControls();
402     hStatus = CreateStatusWindow(
403     WS_CHILD | WS_VISIBLE |
404     CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hWnd, 1);
405    
406     // ���X�g�X�V�^�C�}�[���J�n
407     SetTimer(hWnd, list_timer_id, list_timer_tick, NULL);
408    
409     return FALSE;
410    
411     case WM_COMMAND:
412     switch (wp) {
413     case IDC_ENTERKEY_CHECK | (BN_CLICKED << 16):
414     // �`�F�b�N���L���������A���W�I�{�^�����L���E�������������B
415     checked = SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_GETCHECK, 0, 0);
416     if (checked & BST_CHECKED) { // ���s�R�[�h����
417     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), TRUE);
418     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), TRUE);
419     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), TRUE);
420    
421     } else {
422     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE);
423     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE);
424     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE);
425     }
426     return TRUE;
427    
428     case IDC_REALTIME_CHECK | (BN_CLICKED << 16):
429     checked = SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_GETCHECK, 0, 0);
430     if (checked & BST_CHECKED) { // check����
431     // new handler
432     hwndBroadcast = GetDlgItem(hWnd, IDC_COMMAND_EDIT);
433     hwndBroadcastEdit = GetWindow(hwndBroadcast, GW_CHILD);
434     OrigBroadcastEditProc = (WNDPROC)GetWindowLongPtr(hwndBroadcastEdit, GWLP_WNDPROC);
435     SetWindowLongPtr(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)BroadcastEditProc);
436    
437     EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), FALSE);
438     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), FALSE);
439     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), FALSE);
440     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), FALSE);
441     EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), FALSE);
442     EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), FALSE);
443     EnableWindow(GetDlgItem(hWnd, IDC_LIST), TRUE); // true
444     } else {
445     // restore old handler
446     SetWindowLongPtr(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)OrigBroadcastEditProc);
447    
448     EnableWindow(GetDlgItem(hWnd, IDC_HISTORY_CHECK), TRUE);
449     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CRLF), TRUE);
450     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_CR), TRUE);
451     EnableWindow(GetDlgItem(hWnd, IDC_RADIO_LF), TRUE);
452     EnableWindow(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), TRUE);
453     EnableWindow(GetDlgItem(hWnd, IDC_PARENT_ONLY), TRUE);
454     EnableWindow(GetDlgItem(hWnd, IDC_LIST), TRUE); // true
455     }
456     return TRUE;
457     }
458    
459     switch (LOWORD(wp)) {
460     case IDOK:
461     {
462     memset(buf, 0, sizeof(buf));
463    
464     // realtime mode�������AEnter key���������B
465     // cf. http://logmett.com/forum/viewtopic.php?f=8&t=1601
466     // (2011.3.14 hirata)
467     checked = SendMessage(GetDlgItem(hWnd, IDC_REALTIME_CHECK), BM_GETCHECK, 0, 0);
468     if (checked & BST_CHECKED) { // check����
469     strncpy_s(buf, sizeof(buf), "\n", _TRUNCATE);
470     SetDlgItemText(hWnd, IDC_COMMAND_EDIT, "");
471     goto skip;
472     }
473    
474     ret = GetDlgItemText(hWnd, IDC_COMMAND_EDIT, buf, 256 - 1);
475     if (ret == 0) { // error
476     memset(buf, 0, sizeof(buf));
477     }
478    
479     // �u���[�h�L���X�g�R�}���h������������ (2007.3.3 maya)
480     history = SendMessage(GetDlgItem(hWnd, IDC_HISTORY_CHECK), BM_GETCHECK, 0, 0);
481     if (history) {
482     GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile));
483     if (LoadTTSET()) {
484     (*AddValueToList)(historyfile, buf, "BroadcastCommands", "Command",
485     ts.MaxBroadcatHistory);
486     FreeTTSET();
487     }
488     ApplyBroadCastCommandHisotry(hWnd, historyfile);
489     ts.BroadcastCommandHistory = TRUE;
490     }
491     else {
492     ts.BroadcastCommandHistory = FALSE;
493     }
494     checked = SendMessage(GetDlgItem(hWnd, IDC_ENTERKEY_CHECK), BM_GETCHECK, 0, 0);
495     if (checked & BST_CHECKED) { // ���s�R�[�h����
496     if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_CRLF), BM_GETCHECK, 0, 0) & BST_CHECKED) {
497     strncat_s(buf, sizeof(buf), "\r\n", _TRUNCATE);
498    
499     } else if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_CR), BM_GETCHECK, 0, 0) & BST_CHECKED) {
500     strncat_s(buf, sizeof(buf), "\r", _TRUNCATE);
501    
502     } else if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_LF), BM_GETCHECK, 0, 0) & BST_CHECKED) {
503     strncat_s(buf, sizeof(buf), "\n", _TRUNCATE);
504    
505     } else {
506     strncat_s(buf, sizeof(buf), "\r", _TRUNCATE);
507    
508     }
509     }
510    
511     skip:;
512     // 337: 2007/03/20 �`�F�b�N�������������e�E�B���h�E���������M
513     checked = SendMessage(GetDlgItem(hWnd, IDC_PARENT_ONLY), BM_GETCHECK, 0, 0);
514    
515     SendBroadcastMessageToSelected(HVTWin, hWnd, checked, buf, strlen(buf));
516     }
517    
518     // ���[�h���X�_�C�A���O�����x�������������A�A�v���P�[�V�������I����������
519     // �j���������������A�������u�E�B���h�E�v���V�[�W�������v���s�v���v�������B(yutaka)
520     #if 0
521     SetWindowLongPtr(hwndBroadcastEdit, GWLP_WNDPROC, (LONG_PTR)OrigBroadcastEditProc);
522     #endif
523    
524     //EndDialog(hDlgWnd, IDOK);
525     return TRUE;
526    
527     case IDCANCEL:
528     EndDialog(hWnd, 0);
529     //DestroyWindow(hWnd);
530    
531     return TRUE;
532    
533     case IDC_COMMAND_EDIT:
534     if (HIWORD(wp) == CBN_DROPDOWN) {
535     GetDefaultFName(ts.HomeDir, BROADCAST_LOGFILE, historyfile, sizeof(historyfile));
536     ApplyBroadCastCommandHisotry(hWnd, historyfile);
537     }
538     return FALSE;
539    
540     case IDC_LIST:
541     // �����I���A�v���P�[�V�������������������������������A
542     // �uSHIFT+�N���b�N�v�������A���I���I�����T�|�[�g�����B
543     // (2009.9.28 yutaka)
544     if (HIWORD(wp) == LBN_SELCHANGE && ShiftKey()) {
545     int i, cur, prev;
546    
547     cur = ListBox_GetCurSel(BroadcastWindowList);
548     prev = -1;
549     for (i = cur - 1 ; i >= 0 ; i--) {
550     if (ListBox_GetSel(BroadcastWindowList, i)) {
551     prev = i;
552     break;
553     }
554     }
555     if (prev != -1) {
556     // �������I���������������������A���������A���I�������B
557     for (i = prev ; i < cur ; i++) {
558     ListBox_SetSel(BroadcastWindowList, TRUE, i);
559     }
560     }
561     }
562    
563     return FALSE;
564    
565     default:
566     return FALSE;
567     }
568     break;
569    
570     case WM_CLOSE:
571     //DestroyWindow(hWnd);
572     EndDialog(hWnd, 0);
573     return TRUE;
574    
575     case WM_SIZE:
576     {
577     // ���z�u
578     int dlg_w, dlg_h;
579     RECT rc_dlg;
580     RECT rc;
581     POINT p;
582    
583     // �V�����_�C�A���O���T�C�Y������
584     GetClientRect(hWnd, &rc_dlg);
585     dlg_w = rc_dlg.right;
586     dlg_h = rc_dlg.bottom;
587    
588     // OK button
589     GetWindowRect(GetDlgItem(hWnd, IDOK), &rc);
590     p.x = rc.left;
591     p.y = rc.top;
592     ScreenToClient(hWnd, &p);
593     SetWindowPos(GetDlgItem(hWnd, IDOK), 0,
594     dlg_w - ok2right, p.y, 0, 0,
595     SWP_NOSIZE | SWP_NOZORDER);
596    
597     // Cancel button
598     GetWindowRect(GetDlgItem(hWnd, IDCANCEL), &rc);
599     p.x = rc.left;
600     p.y = rc.top;
601     ScreenToClient(hWnd, &p);
602     SetWindowPos(GetDlgItem(hWnd, IDCANCEL), 0,
603     dlg_w - cancel2right, p.y, 0, 0,
604     SWP_NOSIZE | SWP_NOZORDER);
605    
606     // Command Edit box
607     GetWindowRect(GetDlgItem(hWnd, IDC_COMMAND_EDIT), &rc);
608     p.x = rc.left;
609     p.y = rc.top;
610     ScreenToClient(hWnd, &p);
611     SetWindowPos(GetDlgItem(hWnd, IDC_COMMAND_EDIT), 0,
612     0, 0, dlg_w - p.x - ok2right - cmdlist2ok, p.y,
613     SWP_NOMOVE | SWP_NOZORDER);
614    
615     // List Edit box
616     GetWindowRect(GetDlgItem(hWnd, IDC_LIST), &rc);
617     p.x = rc.left;
618     p.y = rc.top;
619     ScreenToClient(hWnd, &p);
620     SetWindowPos(GetDlgItem(hWnd, IDC_LIST), 0,
621     0, 0, dlg_w - p.x - list2right , dlg_h - p.y - list2bottom,
622     SWP_NOMOVE | SWP_NOZORDER);
623    
624     // status bar
625     SendMessage(hStatus , msg , wp , lp);
626     }
627     return TRUE;
628    
629     case WM_GETMINMAXINFO:
630     {
631     // �_�C�A���O�������T�C�Y����������������������������
632     LPMINMAXINFO lpmmi;
633     lpmmi = (LPMINMAXINFO)lp;
634     lpmmi->ptMinTrackSize.x = init_width;
635     lpmmi->ptMinTrackSize.y = init_height;
636     }
637     return FALSE;
638    
639     case WM_TIMER:
640     {
641     int n;
642    
643     if (wp != list_timer_id)
644     break;
645    
646     n = GetRegisteredWindowCount();
647     if (n != prev_instances) {
648     prev_instances = n;
649     UpdateBroadcastWindowList(BroadcastWindowList);
650     }
651     }
652     return TRUE;
653    
654     case WM_VKEYTOITEM:
655     // ���X�g�{�b�N�X���L�[����(CTRL+A)���������A�S�I���B
656     if ((HWND)lp == BroadcastWindowList) {
657     if (ControlKey() && LOWORD(wp) == 'A') {
658     int i, n;
659    
660     //OutputDebugPrintf("msg %x wp %x lp %x\n", msg, wp, lp);
661     n = GetRegisteredWindowCount();
662     for (i = 0 ; i < n ; i++) {
663     ListBox_SetSel(BroadcastWindowList, TRUE, i);
664     }
665     }
666     }
667     return TRUE;
668    
669     default:
670     //OutputDebugPrintf("msg %x wp %x lp %x\n", msg, wp, lp);
671     return FALSE;
672     }
673     return TRUE;
674     }
675    
676     static HWND hDlgWnd = NULL;
677    
678     void BroadCastShowDialog(HINSTANCE hInst, HWND hWnd)
679     {
680     RECT prc, rc;
681     LONG x, y;
682    
683     if (hDlgWnd != NULL) {
684     goto activate;
685     }
686    
687     hDlgWnd = TTCreateDialog(hInst, MAKEINTRESOURCE(IDD_BROADCAST_DIALOG),
688     hWnd, (DLGPROC)BroadcastCommandDlgProc);
689    
690     if (hDlgWnd == NULL) {
691     return;
692     }
693    
694     // �_�C�A���O���E�B���h�E���^�����z�u���� (2008.1.25 yutaka)
695     ::GetWindowRect(hWnd, &prc);
696     ::GetWindowRect(hDlgWnd, &rc);
697     x = prc.left;
698     y = prc.top - (rc.bottom - rc.top);
699     if (y < 0) {
700     y = 0;
701     }
702     ::SetWindowPos(hDlgWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
703    
704     activate:;
705     ::ShowWindow(hDlgWnd, SW_SHOW);
706     }
707    
708     BOOL BroadCastReceive(COPYDATASTRUCT *cds)
709     {
710     char *buf, *msg, *name;
711     int buflen, msglen, nlen;
712     int sending = 0;
713    
714     msglen = cds->cbData;
715     msg = (char *)cds->lpData;
716     if (cds->dwData == IPC_BROADCAST_COMMAND) {
717     buf = msg;
718     buflen = msglen;
719     sending = 1;
720    
721     } else if (cds->dwData == IPC_MULTICAST_COMMAND) {
722     name = msg;
723     nlen = strlen(name) + 1;
724     buf = msg + nlen;
725     buflen = msglen - nlen;
726    
727     // �}���`�L���X�g�����`�F�b�N����
728     if (CompareMulticastName(name) == 0) { // ����
729     sending = 1;
730     }
731     }
732    
733     if (sending) {
734     // �[��������������������
735     // DDE���M���g�����������X�B(2006.2.7 yutaka)
736     CBStartSend(buf, buflen, FALSE);
737     // ���M�f�[�^���������������M����
738     if (TalkStatus == IdTalkCB) {
739     CBSend();
740     }
741     }
742     return 1;
743     }

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