Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8445 - (hide annotations) (download) (as text)
Tue Dec 17 12:15:31 2019 UTC (4 years, 3 months ago) by doda
Original Path: trunk/teraterm/teraterm/vtwin.cpp
File MIME type: text/x-c++src
File size: 186738 byte(s)
Merge branch 'unicode_buf'
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 zmatsuo 7390 * (C) 2004-2019 TeraTerm Project
4 doda 6806 * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17 doda 6806 *
18 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 doda 6806 */
29 maya 3227 /* IPv6 modification is Copyright(C) 2000 Jun-ya Kato <kato@win6.jp> */
30    
31     /* TERATERM.EXE, VT window */
32    
33 zmatsuo 7554 #include "teraterm_conf.h"
34 maya 3227 #include "teraterm.h"
35     #include "tttypes.h"
36    
37     #include "ttcommon.h"
38     #include "ttwinman.h"
39     #include "ttsetup.h"
40     #include "keyboard.h"
41     #include "buffer.h"
42     #include "vtterm.h"
43     #include "vtdisp.h"
44     #include "ttdialog.h"
45     #include "ttime.h"
46     #include "commlib.h"
47     #include "clipboar.h"
48     #include "ttftypes.h"
49     #include "filesys.h"
50     #include "telnet.h"
51     #include "tektypes.h"
52     #include "ttdde.h"
53     #include "ttlib.h"
54 zmatsuo 7528 #include "dlglib.h"
55 maya 3227 #include "helpid.h"
56     #include "teraprn.h"
57     #include <winsock2.h>
58     #include <ws2tcpip.h>
59     #include "ttplug.h" /* TTPLUG */
60 zmatsuo 7589 #include "teraterml.h"
61 maya 3227
62     #include <stdio.h>
63     #include <stdlib.h>
64     #include <string.h>
65     #include <locale.h>
66 zmatsuo 7528 #include <tchar.h>
67 maya 3227
68     #include <shlobj.h>
69     #include <io.h>
70     #include <errno.h>
71     #include <imagehlp.h>
72 zmatsuo 7528 #include <crtdbg.h>
73 maya 3227
74     #include <windowsx.h>
75 yutakapon 3898 #include <imm.h>
76 zmatsuo 7542 #include <dbt.h>
77 zmatsuo 7487 #include <assert.h>
78 doda 8445 #include <wchar.h>
79 maya 3227
80     #include "tt_res.h"
81     #include "vtwin.h"
82     #include "addsetting.h"
83 yutakapon 4385 #include "winjump.h"
84 doda 7089 #include "sizetip.h"
85 zmatsuo 7148 #include "dnddlg.h"
86 zmatsuo 7527 #include "tekwin.h"
87 zmatsuo 7528 #include <htmlhelp.h>
88 zmatsuo 7457 #include "compat_win.h"
89 doda 8445 #include "unicode_test.h"
90     #if UNICODE_DEBUG
91 zmatsuo 8122 #include "tipwin.h"
92 doda 8445 #endif
93     #include "codeconv.h"
94     #include "layer_for_unicode.h"
95     #include "sendmem.h"
96 maya 3227
97 salarm 6100 #include "initguid.h"
98 maya 6101 //#include "Usbiodef.h"
99     DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, \
100     0xC0, 0x4F, 0xB9, 0x51, 0xED);
101 salarm 6100
102 zmatsuo 7528 #define VTClassName _T("VTWin32")
103    
104     #undef SetDlgItemText
105     #define SetDlgItemText SetDlgItemTextA
106     #undef CreateProcess
107     #define CreateProcess CreateProcessA
108     #undef STARTUPINFO
109     #define STARTUPINFO STARTUPINFOA
110     #undef GetStartupInfo
111     #define GetStartupInfo GetStartupInfoA
112    
113     #if defined(UNICODE)
114     #define CreateProcessT CreateProcessW
115     #define GetStartupInfoT GetStartupInfoW
116     #define STARTUPINFOT STARTUPINFOW
117     #define SetDlgItemTextT SetDlgItemTextW
118     #else
119     #define CreateProcessT CreateProcessA
120     #define GetStartupInfoT GetStartupInfoA
121     #define STARTUPINFOT STARTUPINFOA
122     #define SetDlgItemTextT SetDlgItemTextA
123     #endif
124    
125 maya 3227 #ifdef _DEBUG
126 zmatsuo 7644 #define malloc(l) _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
127     #define free(p) _free_dbg((p), _NORMAL_BLOCK)
128 zmatsuo 7657 #if defined(_MSC_VER)
129 zmatsuo 7528 #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
130 maya 3227 #endif
131 zmatsuo 7657 #endif
132 maya 3227
133     // �E�B���h�E�������{�^�����L�������� (2005.1.15 yutaka)
134     #define WINDOW_MAXMIMUM_ENABLED 1
135    
136     // WM_COPYDATA�������v���Z�X�����M������ (2005.1.22 yutaka)
137     #define IPC_BROADCAST_COMMAND 1 // �S�[�������M
138     #define IPC_MULTICAST_COMMAND 2 // �C�����[���Q�����M
139    
140     #define BROADCAST_LOGFILE "broadcast.log"
141    
142 doda 3580 static BOOL TCPLocalEchoUsed = FALSE;
143     static BOOL TCPCRSendUsed = FALSE;
144    
145 doda 5341 static BOOL IgnoreRelease = FALSE;
146    
147 salarm 6100 static HDEVNOTIFY hDevNotify = NULL;
148    
149 salarm 6076 static int AutoDisconnectedPort = -1;
150    
151 zmatsuo 7485 #ifndef WM_IME_COMPOSITION
152     #define WM_IME_COMPOSITION 0x010F
153     #endif
154    
155 doda 8445 #if UNICODE_INTERNAL_BUFF
156     CUnicodeDebugParam UnicodeDebugParam;
157     #endif
158    
159 maya 3227 /////////////////////////////////////////////////////////////////////////////
160     // CVTWindow
161    
162     // Tera Term�N������URL������mouse over������������ (2005.4.2 yutaka)
163 zmatsuo 7528 static void SetMouseCursor(const char *cursor)
164 maya 3227 {
165     HCURSOR hc;
166     LPCTSTR name = NULL;
167     int i;
168    
169     for (i = 0 ; MouseCursor[i].name ; i++) {
170     if (_stricmp(cursor, MouseCursor[i].name) == 0) {
171     name = MouseCursor[i].id;
172     break;
173     }
174     }
175 maya 3392 if (name == NULL) {
176 maya 3227 return;
177 maya 3392 }
178 maya 3227
179 yutakapon 6286 hc = (HCURSOR)LoadImage(NULL, name, IMAGE_CURSOR,
180 maya 3227 0, 0, LR_DEFAULTSIZE | LR_SHARED);
181    
182     if (hc != NULL) {
183     SetClassLongPtr(HVTWin, GCLP_HCURSOR, (LONG_PTR)hc);
184     }
185     }
186    
187 zmatsuo 7390 /**
188     * @param[in] alpha 0-255
189     */
190     void CVTWindow::SetWindowAlpha(BYTE alpha)
191 maya 3227 {
192 zmatsuo 7457 if (pSetLayeredWindowAttributes == NULL) {
193     return; // ���C���[�h�E�C���h�E���T�|�[�g����
194     }
195 zmatsuo 7390 if (Alpha == alpha) {
196     return; // ����������������������
197     }
198 zmatsuo 7528 LONG_PTR lp = GetWindowLongPtr(GWL_EXSTYLE);
199 zmatsuo 7390 if (lp == 0) {
200     return;
201     }
202 maya 3227
203     // 2006/03/16 by 337: BGUseAlphaBlendAPI��On������Layered����������
204     //if (ts->EtermLookfeel.BGUseAlphaBlendAPI) {
205     // �A���t�@�l��255�������A�����������������}�����������������������������B(2006.4.1 yutaka)
206     // �����o�������A�l�����X�����������������������f�����B(2007.10.19 maya)
207 zmatsuo 7390 if (alpha < 255) {
208     ::SetWindowLongPtr(HVTWin, GWL_EXSTYLE, lp | WS_EX_LAYERED);
209 zmatsuo 7457 pSetLayeredWindowAttributes(HVTWin, 0, alpha, LWA_ALPHA);
210 maya 3227 }
211     else {
212 zmatsuo 7390 // �A���t�@�l�� 255 �������A�����������������������`�������B(2007.10.22 maya)
213     ::SetWindowLongPtr(HVTWin, GWL_EXSTYLE, lp & ~WS_EX_LAYERED);
214     ::RedrawWindow(HVTWin, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME);
215 maya 3227 }
216 zmatsuo 7390 Alpha = alpha;
217 maya 3227 }
218    
219 salarm 6100 void RegDeviceNotify(HWND hWnd)
220     {
221     typedef HDEVNOTIFY (WINAPI *PRegisterDeviceNotification)(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags);
222     HMODULE h;
223     PRegisterDeviceNotification pRegisterDeviceNotification;
224     DEV_BROADCAST_DEVICEINTERFACE filter;
225 maya 3227
226 salarm 6100 if (((h = GetModuleHandle("user32.dll")) == NULL) ||
227     ((pRegisterDeviceNotification = (PRegisterDeviceNotification)GetProcAddress(h, "RegisterDeviceNotificationA")) == NULL)) {
228     return;
229     }
230    
231     ZeroMemory(&filter, sizeof(filter));
232     filter.dbcc_size = sizeof(filter);
233     filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
234     filter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
235     hDevNotify = pRegisterDeviceNotification(hWnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
236     }
237    
238     void UnRegDeviceNotify(HWND hWnd)
239     {
240     typedef BOOL (WINAPI *PUnregisterDeviceNotification)(HDEVNOTIFY Handle);
241     HMODULE h;
242     PUnregisterDeviceNotification pUnregisterDeviceNotification;
243    
244     if (((h = GetModuleHandle("user32.dll")) == NULL) ||
245     ((pUnregisterDeviceNotification = (PUnregisterDeviceNotification)GetProcAddress(h, "UnregisterDeviceNotification")) == NULL)) {
246     return;
247     }
248    
249     pUnregisterDeviceNotification(hDevNotify);
250     }
251    
252 salarm 6347 void SetAutoConnectPort(int port)
253     {
254     AutoDisconnectedPort = port;
255     }
256    
257 maya 3227 //
258     // ���O�n���h�����t�b�N�i�X�^�b�N�g���[�X���_���v�j
259     //
260     // cf. http://svn.collab.net/repos/svn/trunk/subversion/libsvn_subr/win32_crashrpt.c
261     // (2007.9.30 yutaka)
262     //
263     // ���O�R�[�h������������������
264 zmatsuo 7896 #if !defined(_M_X64)
265 zmatsuo 7541 static const char *GetExceptionString(DWORD exception)
266 maya 3227 {
267     #define EXCEPTION(x) case EXCEPTION_##x: return (#x);
268     static char buf[16];
269    
270     switch (exception)
271     {
272     EXCEPTION(ACCESS_VIOLATION)
273     EXCEPTION(DATATYPE_MISALIGNMENT)
274     EXCEPTION(BREAKPOINT)
275     EXCEPTION(SINGLE_STEP)
276     EXCEPTION(ARRAY_BOUNDS_EXCEEDED)
277     EXCEPTION(FLT_DENORMAL_OPERAND)
278     EXCEPTION(FLT_DIVIDE_BY_ZERO)
279     EXCEPTION(FLT_INEXACT_RESULT)
280     EXCEPTION(FLT_INVALID_OPERATION)
281     EXCEPTION(FLT_OVERFLOW)
282     EXCEPTION(FLT_STACK_CHECK)
283     EXCEPTION(FLT_UNDERFLOW)
284     EXCEPTION(INT_DIVIDE_BY_ZERO)
285     EXCEPTION(INT_OVERFLOW)
286     EXCEPTION(PRIV_INSTRUCTION)
287     EXCEPTION(IN_PAGE_ERROR)
288     EXCEPTION(ILLEGAL_INSTRUCTION)
289     EXCEPTION(NONCONTINUABLE_EXCEPTION)
290     EXCEPTION(STACK_OVERFLOW)
291     EXCEPTION(INVALID_DISPOSITION)
292     EXCEPTION(GUARD_PAGE)
293     EXCEPTION(INVALID_HANDLE)
294    
295     default:
296     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "0x%x", exception);
297     return buf;
298     //return "UNKNOWN_ERROR";
299     }
300     #undef EXCEPTION
301     }
302    
303     /* ���O�������������������o���������\�������A���O�t�B���^���� */
304     static LONG CALLBACK ApplicationFaultHandler(EXCEPTION_POINTERS *ExInfo)
305     {
306     HGLOBAL gptr;
307     STACKFRAME sf;
308     BOOL bResult;
309     PIMAGEHLP_SYMBOL pSym;
310     DWORD Disp;
311     HANDLE hProcess = GetCurrentProcess();
312     HANDLE hThread = GetCurrentThread();
313     IMAGEHLP_MODULE ih_module;
314     IMAGEHLP_LINE ih_line;
315     int frame;
316     char msg[3072], buf[256];
317     HMODULE h, h2;
318 maya 4134 char imagehlp_dll[MAX_PATH];
319 maya 3227
320     // Windows98/Me/NT4�����������������X�L�b�v�����B(2007.10.9 yutaka)
321 maya 4134 GetSystemDirectory(imagehlp_dll, sizeof(imagehlp_dll));
322     strncat_s(imagehlp_dll, sizeof(imagehlp_dll), "\\imagehlp.dll", _TRUNCATE);
323     h2 = LoadLibrary(imagehlp_dll);
324     if (((h = GetModuleHandle(imagehlp_dll)) == NULL) ||
325 maya 3227 (GetProcAddress(h, "SymGetLineFromAddr") == NULL)) {
326     FreeLibrary(h2);
327     goto error;
328     }
329     FreeLibrary(h2);
330    
331     /* �V���{�������i�[�p�o�b�t�@�������� */
332     gptr = GlobalAlloc(GMEM_FIXED, 10000);
333 maya 3392 if (gptr == NULL) {
334 maya 3227 goto error;
335 maya 3392 }
336 maya 3227 pSym = (PIMAGEHLP_SYMBOL)GlobalLock(gptr);
337     ZeroMemory(pSym, sizeof(IMAGEHLP_SYMBOL));
338     pSym->SizeOfStruct = 10000;
339     pSym->MaxNameLength = 10000 - sizeof(IMAGEHLP_SYMBOL);
340    
341     /* �X�^�b�N�t���[���������� */
342     ZeroMemory(&sf, sizeof(sf));
343     sf.AddrPC.Offset = ExInfo->ContextRecord->Eip;
344     sf.AddrStack.Offset = ExInfo->ContextRecord->Esp;
345     sf.AddrFrame.Offset = ExInfo->ContextRecord->Ebp;
346     sf.AddrPC.Mode = AddrModeFlat;
347     sf.AddrStack.Mode = AddrModeFlat;
348     sf.AddrFrame.Mode = AddrModeFlat;
349    
350     /* �V���{���n���h���������� */
351     SymInitialize(hProcess, NULL, TRUE);
352 doda 6435
353 maya 3227 // ���W�X�^�_���v
354     msg[0] = '\0';
355     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "eax=%08X ebx=%08X ecx=%08X edx=%08X esi=%08X edi=%08X\r\n"
356     "ebp=%08X esp=%08X eip=%08X efl=%08X\r\n"
357     "cs=%04X ss=%04X ds=%04X es=%04X fs=%04X gs=%04X\r\n",
358 doda 6435 ExInfo->ContextRecord->Eax,
359     ExInfo->ContextRecord->Ebx,
360     ExInfo->ContextRecord->Ecx,
361     ExInfo->ContextRecord->Edx,
362     ExInfo->ContextRecord->Esi,
363     ExInfo->ContextRecord->Edi,
364     ExInfo->ContextRecord->Ebp,
365     ExInfo->ContextRecord->Esp,
366 maya 3227 ExInfo->ContextRecord->Eip,
367     ExInfo->ContextRecord->EFlags,
368     ExInfo->ContextRecord->SegCs,
369     ExInfo->ContextRecord->SegSs,
370     ExInfo->ContextRecord->SegDs,
371     ExInfo->ContextRecord->SegEs,
372     ExInfo->ContextRecord->SegFs,
373     ExInfo->ContextRecord->SegGs
374     );
375     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
376    
377     if (ExInfo->ExceptionRecord != NULL) {
378     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "Exception: %s\r\n", GetExceptionString(ExInfo->ExceptionRecord->ExceptionCode));
379     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
380     }
381    
382     /* �X�^�b�N�t���[���������\���������� */
383     frame = 0;
384     for (;;) {
385     /* �����X�^�b�N�t���[�������� */
386     bResult = StackWalk(
387     IMAGE_FILE_MACHINE_I386,
388     hProcess,
389     hThread,
390     &sf,
391     NULL,
392 doda 6435 NULL,
393 maya 3227 SymFunctionTableAccess,
394     SymGetModuleBase,
395     NULL);
396    
397     /* ���s�������A���[�v�������� */
398 doda 6435 if (!bResult || sf.AddrFrame.Offset == 0)
399 maya 3227 break;
400 doda 6435
401 maya 3227 frame++;
402    
403     /* �v���O�����J�E���^�i���z�A�h���X�j�������������I�t�Z�b�g������ */
404     bResult = SymGetSymFromAddr(hProcess, sf.AddrPC.Offset, &Disp, pSym);
405 doda 6435
406 maya 3227 /* �����������\�� */
407     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "#%d 0x%08x in ", frame, sf.AddrPC.Offset);
408     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
409     if (bResult) {
410     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s() + 0x%x ", pSym->Name, Disp);
411     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
412     } else {
413     _snprintf_s(buf, sizeof(buf), _TRUNCATE, " --- ");
414     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
415     }
416 doda 6435
417 maya 3227 // ���s�t�@�C����������
418     ZeroMemory( &(ih_module), sizeof(ih_module) );
419     ih_module.SizeOfStruct = sizeof(ih_module);
420     bResult = SymGetModuleInfo( hProcess, sf.AddrPC.Offset, &(ih_module) );
421     strncat_s(msg, sizeof(msg), "at ", _TRUNCATE);
422     if (bResult) {
423     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s ", ih_module.ImageName );
424     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
425     } else {
426     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s ", "<Unknown Module>" );
427     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
428     }
429 doda 6435
430 maya 3227 // �t�@�C�������s����������
431     ZeroMemory( &(ih_line), sizeof(ih_line) );
432     ih_line.SizeOfStruct = sizeof(ih_line);
433     bResult = SymGetLineFromAddr( hProcess, sf.AddrPC.Offset, &Disp, &ih_line );
434     if (bResult)
435     {
436     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s:%lu", ih_line.FileName, ih_line.LineNumber );
437     strncat_s(msg, sizeof(msg), buf, _TRUNCATE);
438     }
439 doda 6435
440 maya 3352 strncat_s(msg, sizeof(msg), "\n", _TRUNCATE);
441 maya 3227 }
442    
443     /* ������ */
444     SymCleanup(hProcess);
445     GlobalUnlock(pSym);
446     GlobalFree(pSym);
447    
448     MessageBox(NULL, msg, "Tera Term: Application fault", MB_OK | MB_ICONEXCLAMATION);
449    
450     error:
451     // return (EXCEPTION_EXECUTE_HANDLER); /* ���������v���Z�X���I�������� */
452     return (EXCEPTION_CONTINUE_SEARCH); /* ���������m�A�v���P�[�V�����G���[�n�|�b�v�A�b�v���b�Z�[�W�{�b�N�X�������o�� */
453     }
454 zmatsuo 7896 #endif // !defined(_M_X64 )
455 maya 3227
456    
457 yutakapon 6130 // Virtual Store���L���������������������������B
458     //
459     // [Windows 95-XP]
460     // return FALSE (always)
461     //
462     // [Windows Vista-10]
463     // return TRUE: Virtual Store Enabled
464     // FALSE: Virtual Store Disabled or Unknown
465     //
466     BOOL GetVirtualStoreEnvironment(void)
467     {
468 yutakapon 6131 #if _MSC_VER == 1400 // VSC2005(VC8.0)
469     typedef struct _TOKEN_ELEVATION {
470     DWORD TokenIsElevated;
471     } TOKEN_ELEVATION, *PTOKEN_ELEVATION;
472     int TokenElevation = 20;
473     #endif
474 yutakapon 6130 BOOL ret = FALSE;
475     int flag = 0;
476     HANDLE hToken;
477     DWORD dwLength;
478     TOKEN_ELEVATION tokenElevation;
479     LONG lRet;
480     HKEY hKey;
481     TCHAR lpData[256];
482     DWORD dwDataSize;
483     DWORD dwType;
484     BYTE bValue;
485    
486     // Windows Vista���O�����������B
487 yutakapon 6286 if (!IsWindowsVistaOrLater())
488 yutakapon 6130 goto error;
489    
490     // UAC���L�����������B
491     // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System��EnableLUA(DWORD�l)��0�������������f��������(0��UAC�����A1��UAC�L��)�B
492     flag = 0;
493     lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
494     TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"),
495     NULL, KEY_QUERY_VALUE, &hKey
496     );
497     if (lRet == ERROR_SUCCESS) {
498     dwDataSize = sizeof(lpData) / sizeof(lpData[0]);
499     lRet = RegQueryValueEx(
500     hKey,
501     TEXT("EnableLUA"),
502     0,
503     &dwType,
504     (LPBYTE)lpData,
505     &dwDataSize);
506     if (lRet == ERROR_SUCCESS) {
507     bValue = ((LPBYTE)lpData)[0];
508     if (bValue == 1)
509     // UAC���L���������AVirtual Store�������B
510     flag = 1;
511     }
512     RegCloseKey(hKey);
513     }
514     if (flag == 0)
515     goto error;
516    
517     // UAC���L�����A�v���Z�X�����������������i�����������B
518     flag = 0;
519     if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_DEFAULT, &hToken)) {
520     if (GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)TokenElevation, &tokenElevation, sizeof(TOKEN_ELEVATION), &dwLength)) {
521     // (0�����i�����������A��0�����i��������)�B
522     if (tokenElevation.TokenIsElevated == 0) {
523     // �����������������������������AVirtual Store�������B
524     flag = 1;
525     }
526     }
527     CloseHandle(hToken);
528     }
529     if (flag == 0)
530     goto error;
531    
532     ret = TRUE;
533     return (ret);
534    
535     error:
536     return (ret);
537     }
538    
539 doda 6782 /////////////////////////////////////////////////////////////////////////////
540     // CVTWindow constructor
541    
542 zmatsuo 7916 CVTWindow::CVTWindow(HINSTANCE hInstance)
543 maya 3227 {
544     WNDCLASS wc;
545     RECT rect;
546     DWORD Style;
547     char *Param;
548     int CmdShow;
549 maya 5784 #ifdef SHARED_KEYMAP
550     char Temp[MAX_PATH];
551 maya 3227 PKeyMap tempkm;
552 maya 5784 #endif
553 maya 3227 int fuLoad = LR_DEFAULTCOLOR;
554 doda 6790 BOOL isFirstInstance;
555 zmatsuo 7916 m_hInst = hInstance;
556 maya 3227
557 maya 3392 // ���O�n���h�����t�b�N (2007.9.30 yutaka)
558 zmatsuo 7896 #if !defined(_M_X64)
559 maya 3227 SetUnhandledExceptionFilter(ApplicationFaultHandler);
560 zmatsuo 7896 #endif
561 maya 3227
562 doda 6790 CommInit(&cv);
563     isFirstInstance = StartTeraTerm(&ts);
564    
565 maya 3227 TTXInit(&ts, &cv); /* TTPLUG */
566    
567     MsgDlgHelp = RegisterWindowMessage(HELPMSGSTRING);
568    
569 doda 6790 if (isFirstInstance) {
570 maya 3227 /* first instance */
571     if (LoadTTSET()) {
572     /* read setup info from "teraterm.ini" */
573     (*ReadIniFile)(ts.SetupFName, &ts);
574 maya 5784 #ifdef SHARED_KEYMAP
575 maya 3227 /* read keycode map from "keyboard.cnf" */
576     tempkm = (PKeyMap)malloc(sizeof(TKeyMap));
577     if (tempkm!=NULL) {
578     strncpy_s(Temp, sizeof(Temp), ts.HomeDir, _TRUNCATE);
579     AppendSlash(Temp,sizeof(Temp));
580     strncat_s(Temp,sizeof(Temp),"KEYBOARD.CNF",_TRUNCATE);
581     (*ReadKeyboardCnf)(Temp,tempkm,TRUE);
582     }
583 maya 5784 #endif
584 maya 3227 FreeTTSET();
585 maya 5784 #ifdef SHARED_KEYMAP
586 maya 3227 /* store default sets in TTCMN */
587     #if 0
588     ChangeDefaultSet(&ts,tempkm);
589     #else
590     ChangeDefaultSet(NULL,tempkm);
591     #endif
592     if (tempkm!=NULL) free(tempkm);
593 maya 5784 #endif
594 maya 3227 }
595 doda 6783 else {
596     abort();
597     }
598 maya 3227
599     } else {
600     // 2�������~���v���Z�X�����������A�f�B�X�N���� TERATERM.INI �������B(2004.11.4 yutaka)
601     if (LoadTTSET()) {
602     /* read setup info from "teraterm.ini" */
603     (*ReadIniFile)(ts.SetupFName, &ts);
604 maya 5784 #ifdef SHARED_KEYMAP
605 maya 3227 /* read keycode map from "keyboard.cnf" */
606     tempkm = (PKeyMap)malloc(sizeof(TKeyMap));
607     if (tempkm!=NULL) {
608 doda 5345 strncpy_s(Temp, sizeof(Temp), ts.HomeDir, _TRUNCATE);
609 maya 3227 AppendSlash(Temp,sizeof(Temp));
610     strncat_s(Temp,sizeof(Temp),"KEYBOARD.CNF",_TRUNCATE);
611     (*ReadKeyboardCnf)(Temp,tempkm,TRUE);
612     }
613 maya 5784 #endif
614 maya 3227 FreeTTSET();
615 maya 5784 #ifdef SHARED_KEYMAP
616 maya 3227 /* store default sets in TTCMN */
617 maya 3392 if (tempkm!=NULL) {
618     free(tempkm);
619     }
620 maya 5784 #endif
621 maya 3227 }
622 doda 6783 else {
623     abort();
624     }
625 maya 3227 }
626    
627     /* Parse command line parameters*/
628     // 256�o�C�g�������R�}���h���C���p�����[�^�w�����������ABOF(Buffer Over Flow)��
629     // �������o�O���C���B(2007.6.12 maya)
630     Param = GetCommandLine();
631 maya 3392 if (LoadTTSET()) {
632 maya 3227 (*ParseParam)(Param, &ts, &(TopicName[0]));
633 maya 3392 }
634 maya 3227 FreeTTSET();
635    
636 zmatsuo 7594 // DPI Aware (��DPI����)
637 zmatsuo 7715 if (pIsValidDpiAwarenessContext != NULL && pSetThreadDpiAwarenessContext != NULL) {
638     char Temp[4];
639     GetPrivateProfileString("Tera Term", "DPIAware", NULL, Temp, sizeof(Temp), ts.SetupFName);
640     if (_stricmp(Temp, "on") == 0) {
641     if (pIsValidDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE) {
642 zmatsuo 7594 pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
643     }
644     }
645     }
646    
647 maya 3227 // duplicate session���w�������������A���L�����������R�s�[���� (2004.12.7 yutaka)
648     if (ts.DuplicateSession == 1) {
649     CopyShmemToTTSet(&ts);
650     }
651    
652     InitKeyboard();
653     SetKeyMap();
654    
655     /* window status */
656     AdjustSize = TRUE;
657     Minimized = FALSE;
658     LButton = FALSE;
659     MButton = FALSE;
660     RButton = FALSE;
661     DblClk = FALSE;
662     AfterDblClk = FALSE;
663     TplClk = FALSE;
664     Hold = FALSE;
665     FirstPaint = TRUE;
666     ScrollLock = FALSE; // �����l������ (2006.11.14 yutaka)
667 zmatsuo 7390 Alpha = 255;
668 zmatsuo 7717 IgnoreSizeMessage = FALSE;
669 doda 8445 #if UNICODE_DEBUG
670     TipWinCodeDebug = NULL;
671     #endif
672 maya 3227
673     /* Initialize scroll buffer */
674     InitBuffer();
675    
676     InitDisp();
677    
678     if (ts.HideTitle>0) {
679     Style = WS_VSCROLL | WS_HSCROLL |
680     WS_BORDER | WS_THICKFRAME | WS_POPUP;
681    
682     #ifdef ALPHABLEND_TYPE2
683     if(BGNoFrame)
684     Style &= ~(WS_BORDER | WS_THICKFRAME);
685     #endif
686     }
687     else
688     #ifdef WINDOW_MAXMIMUM_ENABLED
689     Style = WS_VSCROLL | WS_HSCROLL |
690     WS_BORDER | WS_THICKFRAME |
691     WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
692     #else
693     Style = WS_VSCROLL | WS_HSCROLL |
694     WS_BORDER | WS_THICKFRAME |
695     WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
696     #endif
697    
698     wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
699 zmatsuo 7528 wc.lpfnWndProc = (WNDPROC)ProcStub;
700 maya 3227 wc.cbClsExtra = 0;
701     wc.cbWndExtra = 0;
702 zmatsuo 7916 wc.hInstance = hInstance;
703 maya 3227 wc.hIcon = NULL;
704     //wc.hCursor = LoadCursor(NULL,IDC_IBEAM);
705     wc.hCursor = NULL; // �}�E�X�J�[�\�������I�����X���� (2005.4.2 yutaka)
706     wc.hbrBackground = NULL;
707     wc.lpszMenuName = NULL;
708     wc.lpszClassName = VTClassName;
709    
710     RegisterClass(&wc);
711 zmatsuo 7916 m_hAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACC));
712 maya 3227
713 maya 3392 if (ts.VTPos.x==CW_USEDEFAULT) {
714 maya 3227 rect = rectDefault;
715 maya 3392 }
716 maya 3227 else {
717     rect.left = ts.VTPos.x;
718     rect.top = ts.VTPos.y;
719     rect.right = rect.left + 100;
720     rect.bottom = rect.top + 100;
721     }
722 zmatsuo 7916 Create(hInstance, VTClassName, _T("Tera Term"), Style, rect, NULL, NULL);
723 maya 3227
724     /*--------- Init2 -----------------*/
725     HVTWin = GetSafeHwnd();
726     if (HVTWin == NULL) return;
727     // register this window to the window list
728     SerialNo = RegWin(HVTWin,NULL);
729    
730     logfile_lock_initialize();
731 zmatsuo 7390 SetMouseCursor(ts.MouseCursorName);
732 maya 3227 // ���P�[��������
733     // wctomb ������
734     setlocale(LC_ALL, ts.Locale);
735    
736     #ifdef ALPHABLEND_TYPE2
737     //<!--by AKASI
738     if(BGNoFrame && ts.HideTitle > 0) {
739 doda 8445 DWORD ExStyle = (DWORD)::GetWindowLongPtr(HVTWin,GWL_EXSTYLE);
740 maya 3227 ExStyle &= ~WS_EX_CLIENTEDGE;
741 zmatsuo 7528 ::SetWindowLongPtr(HVTWin,GWL_EXSTYLE,ExStyle);
742 maya 3227 }
743     //-->
744     #endif
745    
746 salarm 6100 // USB�f�o�C�X�������m�o�^
747     RegDeviceNotify(HVTWin);
748    
749 yutakapon 6286 if (IsWindowsNT4()) {
750 maya 3227 fuLoad = LR_VGACOLOR;
751     }
752     ::PostMessage(HVTWin,WM_SETICON,ICON_SMALL,
753 zmatsuo 7916 (LPARAM)LoadImage(hInstance,
754 maya 3227 MAKEINTRESOURCE((ts.VTIcon!=IdIconDefault)?ts.VTIcon:IDI_VT),
755     IMAGE_ICON,16,16,fuLoad));
756     // Vista �� Aero �������� Alt+Tab �����������\���������A�C�R����
757     // 16x16 �A�C�R�����g���������������������A�������A�C�R����
758     // �Z�b�g���� (2008.9.3 maya)
759     ::PostMessage(HVTWin,WM_SETICON,ICON_BIG,
760 zmatsuo 7916 (LPARAM)LoadImage(hInstance,
761 maya 3227 MAKEINTRESOURCE((ts.VTIcon!=IdIconDefault)?ts.VTIcon:IDI_VT),
762     IMAGE_ICON, 0, 0, fuLoad));
763    
764 doda 6690 SetCustomNotifyIcon(
765     (HICON)LoadImage(
766 zmatsuo 7916 hInstance,
767 doda 6690 MAKEINTRESOURCE((ts.VTIcon!=IdIconDefault)?ts.VTIcon:IDI_VT),
768     IMAGE_ICON, 16, 16, LR_VGACOLOR|LR_SHARED));
769    
770 maya 3227 MainMenu = NULL;
771     WinMenu = NULL;
772     if ((ts.HideTitle==0) && (ts.PopupMenu==0)) {
773     InitMenu(&MainMenu);
774     ::SetMenu(HVTWin,MainMenu);
775     }
776    
777     /* Reset Terminal */
778     ResetTerminal();
779    
780 maya 3392 if ((ts.PopupMenu>0) || (ts.HideTitle>0)) {
781 maya 3227 ::PostMessage(HVTWin,WM_USER_CHANGEMENU,0,0);
782 maya 3392 }
783 maya 3227
784     ChangeFont();
785    
786     ResetIME();
787    
788     BuffChangeWinSize(NumOfColumns,NumOfLines);
789    
790     ChangeTitle();
791     /* Enable drag-drop */
792     ::DragAcceptFiles(HVTWin,TRUE);
793    
794     if (ts.HideWindow>0) {
795     if (strlen(TopicName)>0) {
796     InitDDE();
797     SendDDEReady();
798     }
799     FirstPaint = FALSE;
800     Startup();
801     return;
802     }
803 maya 3392 CmdShow = SW_SHOWDEFAULT;
804     if (ts.Minimize>0) {
805 maya 3227 CmdShow = SW_SHOWMINIMIZED;
806 maya 3392 }
807 zmatsuo 7390 SetWindowAlpha(ts.AlphaBlendActive);
808 maya 3227 ShowWindow(CmdShow);
809     ChangeCaret();
810 yutakapon 6130
811     // Tera Term���N�����AVirtual Store�����������������o���������B
812     // (2015.11.14 yutaka)
813     cv.VirtualStoreEnabled = GetVirtualStoreEnvironment();
814 zmatsuo 7148
815     DropLists = NULL;
816     DropListCount = 0;
817 yasuhide 8143
818 doda 8445 #if UNICODE_DEBUG
819     CtrlKeyState = 0;
820     #endif
821    
822 yasuhide 8143 // TipWin
823 yasuhide 8268 TipWin = new CTipWin(hInstance);
824     TipWin->Create(HVTWin);
825 maya 3227 }
826    
827     /////////////////////////////////////////////////////////////////////////////
828 yasuhide 8268 // CVTWindow destructor
829 maya 3227
830 yasuhide 8268 CVTWindow::~CVTWindow()
831     {
832     TipWin->Destroy();
833     delete TipWin;
834     TipWin = NULL;
835     }
836    
837     /////////////////////////////////////////////////////////////////////////////
838    
839 maya 3227 int CVTWindow::Parse()
840     {
841     // added ScrollLock (2006.11.14 yutaka)
842     if (LButton || MButton || RButton || ScrollLock)
843     return 0;
844     return (VTParse()); // Parse received characters
845     }
846    
847     void CVTWindow::ButtonUp(BOOL Paste)
848     {
849     BOOL disableBuffEndSelect = false;
850    
851     /* disable autoscrolling */
852     ::KillTimer(HVTWin,IdScrollTimer);
853     ReleaseCapture();
854    
855     if (ts.SelectOnlyByLButton &&
856     (MButton || RButton)) {
857     disableBuffEndSelect = true;
858     }
859    
860     LButton = FALSE;
861     MButton = FALSE;
862     RButton = FALSE;
863     DblClk = FALSE;
864     TplClk = FALSE;
865     CaretOn();
866    
867     // SelectOnlyByLButton �� on �� ���E�E�N���b�N����������
868     // �o�b�t�@���I���������������A�I�����e���N���b�v�{�[�h��
869     // �R�s�[�������������������C�� (2007.12.6 maya)
870     if (!disableBuffEndSelect) {
871     BuffEndSelect();
872     }
873    
874 doda 6415 if (Paste) {
875 doda 6456 CBStartPaste(HVTWin, FALSE, BracketedPasteMode());
876 doda 8445
877 doda 6456 // �X�N���[�����u�����Z�b�g
878     if (WinOrgY != 0) {
879     DispVScroll(SCROLL_BOTTOM, 0);
880 maya 3227 }
881     }
882     }
883    
884     void CVTWindow::ButtonDown(POINT p, int LMR)
885     {
886     HMENU PopupMenu, PopupBase;
887     BOOL mousereport;
888    
889     if ((LMR==IdLeftButton) && ControlKey() && (MainMenu==NULL) &&
890     ((ts.MenuFlag & MF_NOPOPUP)==0)) {
891     int i, numItems;
892     char itemText[256];
893    
894     InitMenu(&PopupMenu);
895    
896     PopupBase = CreatePopupMenu();
897     numItems = GetMenuItemCount(PopupMenu);
898    
899     for (i = 0; i < numItems; i++) {
900     HMENU submenu = GetSubMenu(PopupMenu, i);
901    
902     if (submenu != NULL) {
903     InitMenuPopup(submenu);
904     }
905    
906     if (GetMenuString(PopupMenu, i, itemText, sizeof(itemText), MF_BYPOSITION) != 0) {
907     int state = GetMenuState(PopupMenu, i, MF_BYPOSITION) &
908     (MF_CHECKED | MF_DISABLED | MF_GRAYED | MF_HILITE |
909     MF_MENUBARBREAK | MF_MENUBREAK | MF_SEPARATOR);
910    
911     AppendMenu(PopupBase,
912     submenu != NULL ? LOBYTE(state) | MF_POPUP : state,
913 zmatsuo 7896 submenu != NULL ? (UINT_PTR)submenu : GetMenuItemID(PopupMenu, i),
914 maya 3227 itemText);
915     }
916     }
917    
918     ::ClientToScreen(HVTWin, &p);
919     TrackPopupMenu(PopupBase,TPM_LEFTALIGN | TPM_LEFTBUTTON,
920     p.x,p.y,0,HVTWin,NULL);
921     if (WinMenu!=NULL) {
922     DestroyMenu(WinMenu);
923     WinMenu = NULL;
924     }
925     DestroyMenu(PopupBase);
926     DestroyMenu(PopupMenu);
927     PopupMenu = 0;
928     return;
929     }
930    
931 zmatsuo 7528 mousereport = MouseReport(IdMouseEventBtnDown, LMR, p.x, p.y);
932     if (mousereport) {
933     ::SetCapture(m_hWnd);
934 doda 3987 return;
935     }
936 maya 3227
937     // added ConfirmPasteMouseRButton (2007.3.17 maya)
938     if ((LMR == IdRightButton) &&
939 doda 6594 (ts.PasteFlag & CPF_DISABLE_RBUTTON) == 0 &&
940     (ts.PasteFlag & CPF_CONFIRM_RBUTTON) != 0 &&
941 maya 3227 cv.Ready &&
942     !mousereport &&
943     (SendVar==NULL) && (FileVar==NULL) &&
944     (cv.PortType!=IdFile) &&
945     (IsClipboardFormatAvailable(CF_TEXT) ||
946     IsClipboardFormatAvailable(CF_OEMTEXT))) {
947    
948     int i, numItems;
949     char itemText[256];
950    
951     InitPasteMenu(&PopupMenu);
952     PopupBase = CreatePopupMenu();
953     numItems = GetMenuItemCount(PopupMenu);
954    
955     for (i = 0; i < numItems; i++) {
956     if (GetMenuString(PopupMenu, i, itemText, sizeof(itemText), MF_BYPOSITION) != 0) {
957     int state = GetMenuState(PopupMenu, i, MF_BYPOSITION) &
958     (MF_CHECKED | MF_DISABLED | MF_GRAYED | MF_HILITE |
959     MF_MENUBARBREAK | MF_MENUBREAK | MF_SEPARATOR);
960    
961     AppendMenu(PopupBase, state,
962     GetMenuItemID(PopupMenu, i), itemText);
963     }
964     }
965    
966     ::ClientToScreen(HVTWin, &p);
967     TrackPopupMenu(PopupBase,TPM_LEFTALIGN | TPM_LEFTBUTTON,
968     p.x,p.y,0,HVTWin,NULL);
969     if (WinMenu!=NULL) {
970     DestroyMenu(WinMenu);
971     WinMenu = NULL;
972     }
973     DestroyMenu(PopupBase);
974     DestroyMenu(PopupMenu);
975     PopupMenu = 0;
976     return;
977     }
978    
979     if (AfterDblClk && (LMR==IdLeftButton) &&
980     (abs(p.x-DblClkX)<=GetSystemMetrics(SM_CXDOUBLECLK)) &&
981     (abs(p.y-DblClkY)<=GetSystemMetrics(SM_CYDOUBLECLK))) {
982     /* triple click */
983     ::KillTimer(HVTWin, IdDblClkTimer);
984     AfterDblClk = FALSE;
985     BuffTplClk(p.y);
986     LButton = TRUE;
987     TplClk = TRUE;
988     /* for AutoScrolling */
989     ::SetCapture(HVTWin);
990     ::SetTimer(HVTWin, IdScrollTimer, 100, NULL);
991     }
992     else {
993     if (! (LButton || MButton || RButton)) {
994     BOOL box = FALSE;
995    
996     // select several pages of output from Tera Term window (2005.5.15 yutaka)
997     if (LMR == IdLeftButton && ShiftKey()) {
998     BuffSeveralPagesSelect(p.x, p.y);
999    
1000     } else {
1001     // Select rectangular block with Alt Key. Delete Shift key.(2005.5.15 yutaka)
1002     if (LMR == IdLeftButton && AltKey()) {
1003     box = TRUE;
1004     }
1005    
1006     // Starting the selection only by a left button.(2007.11.20 maya)
1007     if (!ts.SelectOnlyByLButton ||
1008     (ts.SelectOnlyByLButton && LMR == IdLeftButton) ) {
1009     BuffStartSelect(p.x,p.y, box);
1010     TplClk = FALSE;
1011    
1012     /* for AutoScrolling */
1013     ::SetCapture(HVTWin);
1014     ::SetTimer(HVTWin, IdScrollTimer, 100, NULL);
1015     }
1016     }
1017     }
1018    
1019     switch (LMR) {
1020     case IdRightButton:
1021     RButton = TRUE;
1022     break;
1023     case IdMiddleButton:
1024     MButton = TRUE;
1025     break;
1026     case IdLeftButton:
1027     LButton = TRUE;
1028     break;
1029     }
1030     }
1031     }
1032    
1033     // LogMeIn.exe -> LogMeTT.exe �����l�[�� (2005.2.21 yutaka)
1034     static char LogMeTTMenuString[] = "Log&MeTT";
1035 yutakapon 3648 static char LogMeTT[MAX_PATH];
1036    
1037 doda 8395 #define IS_LOGMETT_NOTFOUND 0
1038     #define IS_LOGMETT_FOUND 1
1039     #define IS_LOGMETT_UNKNOWN 2
1040    
1041 maya 3227 static BOOL isLogMeTTExist()
1042     {
1043 yutakapon 3648 const char *LogMeTTexename = "LogMeTT.exe";
1044     LONG result;
1045     HKEY key;
1046     int inregist = 0;
1047     DWORD dwSize;
1048     DWORD dwType;
1049     DWORD dwDisposition;
1050     char *path;
1051 maya 3227
1052 doda 8395 static int status = IS_LOGMETT_UNKNOWN;
1053    
1054     if (status != IS_LOGMETT_UNKNOWN) {
1055     return status == IS_LOGMETT_FOUND;
1056     }
1057    
1058 yutakapon 3648 /* LogMeTT 2.9.6���������W�X�g�����C���X�g�[���p�X�����������B*/
1059     result = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\LogMeTT", 0, NULL,
1060     REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &key, &dwDisposition);
1061     if (result == ERROR_SUCCESS) {
1062     result = RegQueryValueEx(key, "InstallPath", NULL, &dwType, NULL, &dwSize);
1063     if (result == ERROR_SUCCESS) {
1064     path = (char *)malloc(dwSize);
1065     if (path != NULL) {
1066     result = RegQueryValueEx(key, "InstallPath", NULL, &dwType, (LPBYTE)path, &dwSize);
1067     if (result == ERROR_SUCCESS) {
1068     inregist = 1;
1069     strncpy_s(LogMeTT, sizeof(LogMeTT), path, _TRUNCATE);
1070     }
1071     free(path);
1072     }
1073     }
1074 yutakapon 3649 RegCloseKey(key);
1075 yutakapon 3648 }
1076    
1077     if (inregist == 0) {
1078     strncpy_s(LogMeTT, sizeof(LogMeTT), ts.HomeDir, _TRUNCATE);
1079     AppendSlash(LogMeTT, sizeof(LogMeTT));
1080     strncat_s(LogMeTT, sizeof(LogMeTT), LogMeTTexename, _TRUNCATE);
1081     }
1082    
1083 maya 3227 if (_access(LogMeTT, 0) == -1) {
1084 doda 8395 status = IS_LOGMETT_NOTFOUND;
1085 maya 3227 return FALSE;
1086     }
1087 doda 8395 status = IS_LOGMETT_FOUND;
1088 maya 3227 return TRUE;
1089     }
1090    
1091     void CVTWindow::InitMenu(HMENU *Menu)
1092     {
1093 doda 8445 static const DlgTextInfo MenuTextInfo[] = {
1094     { ID_FILE, "MENU_FILE" },
1095     { ID_EDIT, "MENU_EDIT" },
1096     { ID_SETUP, "MENU_SETUP" },
1097     { ID_CONTROL, "MENU_CONTROL" },
1098     { ID_HELPMENU, "MENU_HELP" },
1099     };
1100     static const DlgTextInfo FileMenuTextInfo[] = {
1101     { ID_FILE_NEWCONNECTION, "MENU_FILE_NEW" },
1102     { ID_FILE_DUPLICATESESSION, "MENU_FILE_DUPLICATE" },
1103     { ID_FILE_CYGWINCONNECTION, "MENU_FILE_GYGWIN" },
1104     { ID_FILE_LOG, "MENU_FILE_LOG" },
1105     { ID_FILE_COMMENTTOLOG, "MENU_FILE_COMMENTLOG" },
1106     { ID_FILE_VIEWLOG, "MENU_FILE_VIEWLOG" },
1107     { ID_FILE_SHOWLOGDIALOG, "MENU_FILE_SHOWLOGDIALOG" },
1108     { ID_FILE_PAUSELOG, "MENU_FILE_PAUSELOG" },
1109     { ID_FILE_STOPLOG, "MENU_FILE_STOPLOG" },
1110     { ID_FILE_SENDFILE, "MENU_FILE_SENDFILE" },
1111     { ID_FILE_REPLAYLOG, "MENU_FILE_REPLAYLOG" },
1112     { ID_FILE_CHANGEDIR, "MENU_FILE_CHANGEDIR" },
1113     { ID_FILE_LOGMEIN, "MENU_FILE_LOGMETT" },
1114     { ID_FILE_PRINT2, "MENU_FILE_PRINT" },
1115     { ID_FILE_DISCONNECT, "MENU_FILE_DISCONNECT" },
1116     { ID_FILE_EXIT, "MENU_FILE_EXIT" },
1117     { ID_FILE_EXITALL, "MENU_FILE_EXITALL" },
1118     { 11, "MENU_TRANS" },
1119     { ID_FILE_KERMITRCV, "MENU_TRANS_KERMIT_RCV" },
1120     { ID_FILE_KERMITGET, "MENU_TRANS_KERMIT_GET" },
1121     { ID_FILE_KERMITSEND, "MENU_TRANS_KERMIT_SEND" },
1122     { ID_FILE_KERMITFINISH, "MENU_TRANS_KERMIT_FINISH" },
1123     { ID_FILE_XRCV, "MENU_TRANS_X_RCV" },
1124     { ID_FILE_XSEND, "MENU_TRANS_X_SEND" },
1125     { ID_FILE_YRCV, "MENU_TRANS_Y_RCV" },
1126     { ID_FILE_YSEND, "MENU_TRANS_Y_SEND" },
1127     { ID_FILE_ZRCV, "MENU_TRANS_Z_RCV" },
1128     { ID_FILE_ZSEND, "MENU_TRANS_Z_SEND" },
1129     { ID_FILE_BPRCV, "MENU_TRANS_BP_RCV" },
1130     { ID_FILE_BPSEND, "MENU_TRANS_BP_SEND" },
1131     { ID_FILE_QVRCV, "MENU_TRANS_QV_RCV" },
1132     { ID_FILE_QVSEND, "MENU_TRANS_QV_SEND" },
1133     };
1134     static const DlgTextInfo EditMenuTextInfo[] = {
1135     { ID_EDIT_COPY2, "MENU_EDIT_COPY" },
1136     { ID_EDIT_COPYTABLE, "MENU_EDIT_COPYTABLE" },
1137     { ID_EDIT_PASTE2, "MENU_EDIT_PASTE" },
1138     { ID_EDIT_PASTECR, "MENU_EDIT_PASTECR" },
1139     { ID_EDIT_CLEARSCREEN, "MENU_EDIT_CLSCREEN" },
1140     { ID_EDIT_CLEARBUFFER, "MENU_EDIT_CLBUFFER" },
1141     { ID_EDIT_CANCELSELECT, "MENU_EDIT_CANCELSELECT" },
1142     { ID_EDIT_SELECTSCREEN, "MENU_EDIT_SELECTSCREEN" },
1143     { ID_EDIT_SELECTALL, "MENU_EDIT_SELECTALL" },
1144     };
1145     static const DlgTextInfo SetupMenuTextInfo[] = {
1146     { ID_SETUP_TERMINAL, "MENU_SETUP_TERMINAL" },
1147     { ID_SETUP_WINDOW, "MENU_SETUP_WINDOW" },
1148     { ID_SETUP_FONT, "MENU_SETUP_FONT" },
1149     { ID_SETUP_DLG_FONT, "MENU_SETUP_DIALOG_FONT" },
1150     { 2, "MENU_SETUP_FONT_SUBMENU" },
1151     { ID_SETUP_KEYBOARD, "MENU_SETUP_KEYBOARD" },
1152     { ID_SETUP_SERIALPORT, "MENU_SETUP_SERIALPORT" },
1153     { ID_SETUP_TCPIP, "MENU_SETUP_TCPIP" },
1154     { ID_SETUP_GENERAL, "MENU_SETUP_GENERAL" },
1155     { ID_SETUP_ADDITIONALSETTINGS, "MENU_SETUP_ADDITION" },
1156     { ID_SETUP_SAVE, "MENU_SETUP_SAVE" },
1157     { ID_SETUP_RESTORE, "MENU_SETUP_RESTORE" },
1158     { ID_OPEN_SETUP, "MENU_SETUP_OPENSETUP" },
1159     { ID_SETUP_LOADKEYMAP, "MENU_SETUP_LOADKEYMAP" },
1160     };
1161     static const DlgTextInfo ControlMenuTextInfo[] = {
1162     { ID_CONTROL_RESETTERMINAL, "MENU_CONTROL_RESET" },
1163     { ID_CONTROL_RESETREMOTETITLE, "MENU_CONTROL_RESETTITLE" },
1164     { ID_CONTROL_AREYOUTHERE, "MENU_CONTROL_AREYOUTHERE" },
1165     { ID_CONTROL_SENDBREAK, "MENU_CONTROL_SENDBREAK" },
1166     { ID_CONTROL_RESETPORT, "MENU_CONTROL_RESETPORT" },
1167     { ID_CONTROL_BROADCASTCOMMAND, "MENU_CONTROL_BROADCAST" },
1168     { ID_CONTROL_OPENTEK, "MENU_CONTROL_OPENTEK" },
1169     { ID_CONTROL_CLOSETEK, "MENU_CONTROL_CLOSETEK" },
1170     { ID_CONTROL_MACRO, "MENU_CONTROL_MACRO" },
1171     { ID_CONTROL_SHOW_MACRO, "MENU_CONTROL_SHOW_MACRO" },
1172     };
1173     static const DlgTextInfo HelpMenuTextInfo[] = {
1174     { ID_HELP_INDEX2, "MENU_HELP_INDEX" },
1175     { ID_HELP_ABOUT, "MENU_HELP_ABOUT" },
1176     };
1177 maya 3227
1178 doda 8445 HMENU hMenu = LoadMenu(m_hInst, MAKEINTRESOURCE(IDR_MENU));
1179     *Menu = hMenu;
1180    
1181     FileMenu = GetSubMenu(hMenu,ID_FILE);
1182 maya 3227 TransMenu = GetSubMenu(FileMenu,ID_TRANSFER);
1183 doda 8445 EditMenu = GetSubMenu(hMenu,ID_EDIT);
1184     SetupMenu = GetSubMenu(hMenu,ID_SETUP);
1185     ControlMenu = GetSubMenu(hMenu,ID_CONTROL);
1186     HelpMenu = GetSubMenu(hMenu,ID_HELPMENU);
1187 maya 3227
1188 doda 8445 SetDlgMenuTexts(hMenu, MenuTextInfo, _countof(MenuTextInfo), ts.UILanguageFile);
1189    
1190 maya 3227 /* LogMeTT ���������m�F�������j���[���������� */
1191     if (isLogMeTTExist()) {
1192     ::InsertMenu(FileMenu, ID_FILE_PRINT2, MF_STRING | MF_ENABLED | MF_BYCOMMAND,
1193     ID_FILE_LOGMEIN, LogMeTTMenuString);
1194     ::InsertMenu(FileMenu, ID_FILE_PRINT2, MF_SEPARATOR, NULL, NULL);
1195     }
1196    
1197 doda 8445 SetDlgMenuTexts(FileMenu, FileMenuTextInfo, _countof(FileMenuTextInfo), ts.UILanguageFile);
1198     SetDlgMenuTexts(EditMenu, EditMenuTextInfo, _countof(EditMenuTextInfo), ts.UILanguageFile);
1199     SetDlgMenuTexts(SetupMenu, SetupMenuTextInfo, _countof(SetupMenuTextInfo), ts.UILanguageFile);
1200     SetDlgMenuTexts(ControlMenu, ControlMenuTextInfo, _countof(ControlMenuTextInfo), ts.UILanguageFile);
1201     SetDlgMenuTexts(HelpMenu, HelpMenuTextInfo, _countof(HelpMenuTextInfo), ts.UILanguageFile);
1202 maya 3227
1203     if ((ts.MenuFlag & MF_SHOWWINMENU) !=0) {
1204 doda 8445 TCHAR uimsg[MAX_UIMSG];
1205 maya 3227 WinMenu = CreatePopupMenu();
1206 doda 8445 get_lang_msgT("MENU_WINDOW", uimsg, _countof(uimsg),
1207     _T("&Window"), ts.UILanguageFile);
1208     ::InsertMenu(hMenu, ID_HELPMENU,
1209     MF_STRING | MF_ENABLED | MF_POPUP | MF_BYPOSITION,
1210     (UINT_PTR)WinMenu, uimsg);
1211 maya 3227 }
1212    
1213 doda 8445 TTXModifyMenu(hMenu); /* TTPLUG */
1214 maya 3227 }
1215    
1216     void CVTWindow::InitMenuPopup(HMENU SubMenu)
1217     {
1218     if ( SubMenu == FileMenu )
1219     {
1220 maya 3966 if (ts.DisableMenuNewConnection) {
1221     if ( Connecting || cv.Open ) {
1222 maya 3965 EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_GRAYED);
1223     }
1224     else {
1225     EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_ENABLED);
1226     }
1227 maya 3227 }
1228 maya 3966 else {
1229     if ( Connecting ) {
1230     EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_GRAYED);
1231     }
1232     else {
1233     EnableMenuItem(FileMenu,ID_FILE_NEWCONNECTION,MF_BYCOMMAND | MF_ENABLED);
1234     }
1235     }
1236 maya 3227
1237     if ( (! cv.Ready) || (SendVar!=NULL) ||
1238     (FileVar!=NULL) || (cv.PortType==IdFile) ) {
1239     EnableMenuItem(FileMenu,ID_FILE_SENDFILE,MF_BYCOMMAND | MF_GRAYED);
1240     EnableMenuItem(FileMenu,ID_TRANSFER,MF_BYPOSITION | MF_GRAYED); /* Transfer */
1241     EnableMenuItem(FileMenu,ID_FILE_CHANGEDIR,MF_BYCOMMAND | MF_GRAYED);
1242     EnableMenuItem(FileMenu,ID_FILE_DISCONNECT,MF_BYCOMMAND | MF_GRAYED);
1243     EnableMenuItem(FileMenu,ID_FILE_DUPLICATESESSION,MF_BYCOMMAND | MF_GRAYED);
1244     }
1245     else {
1246     EnableMenuItem(FileMenu,ID_FILE_SENDFILE,MF_BYCOMMAND | MF_ENABLED);
1247     EnableMenuItem(FileMenu,ID_TRANSFER,MF_BYPOSITION | MF_ENABLED); /* Transfer */
1248     EnableMenuItem(FileMenu,ID_FILE_CHANGEDIR,MF_BYCOMMAND | MF_ENABLED);
1249     EnableMenuItem(FileMenu,ID_FILE_DISCONNECT,MF_BYCOMMAND | MF_ENABLED);
1250 maya 3964 if (ts.DisableMenuDuplicateSession) {
1251     EnableMenuItem(FileMenu,ID_FILE_DUPLICATESESSION,MF_BYCOMMAND | MF_GRAYED);
1252     }
1253     else {
1254     EnableMenuItem(FileMenu,ID_FILE_DUPLICATESESSION,MF_BYCOMMAND | MF_ENABLED);
1255     }
1256 maya 3227 }
1257    
1258     // �V�K���j���[������ (2004.12.5 yutaka)
1259     EnableMenuItem(FileMenu,ID_FILE_CYGWINCONNECTION,MF_BYCOMMAND | MF_ENABLED);
1260     EnableMenuItem(FileMenu,ID_FILE_TERATERMMENU,MF_BYCOMMAND | MF_ENABLED);
1261     EnableMenuItem(FileMenu,ID_FILE_LOGMEIN,MF_BYCOMMAND | MF_ENABLED);
1262    
1263     // XXX: �������u�����������Alog���O���C�����������B (2005.2.1 yutaka)
1264     if (LogVar!=NULL) { // ���O�������[�h������
1265     EnableMenuItem(FileMenu,ID_FILE_LOG,MF_BYCOMMAND | MF_GRAYED);
1266     EnableMenuItem(FileMenu,ID_FILE_COMMENTTOLOG, MF_BYCOMMAND | MF_ENABLED);
1267     EnableMenuItem(FileMenu,ID_FILE_VIEWLOG, MF_BYCOMMAND | MF_ENABLED);
1268 maya 3709 EnableMenuItem(FileMenu,ID_FILE_SHOWLOGDIALOG, MF_BYCOMMAND | MF_ENABLED);
1269 doda 8396 EnableMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_ENABLED);
1270     EnableMenuItem(FileMenu,ID_FILE_STOPLOG, MF_BYCOMMAND | MF_ENABLED);
1271     if (cv.FilePause & OpLog) {
1272     CheckMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_CHECKED);
1273     }
1274     else {
1275     CheckMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_UNCHECKED);
1276     }
1277 maya 3227 } else {
1278     EnableMenuItem(FileMenu,ID_FILE_LOG,MF_BYCOMMAND | MF_ENABLED);
1279     EnableMenuItem(FileMenu,ID_FILE_COMMENTTOLOG, MF_BYCOMMAND | MF_GRAYED);
1280     EnableMenuItem(FileMenu,ID_FILE_VIEWLOG, MF_BYCOMMAND | MF_GRAYED);
1281     EnableMenuItem(FileMenu,ID_FILE_SHOWLOGDIALOG, MF_BYCOMMAND | MF_GRAYED);
1282 doda 8396 EnableMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_GRAYED);
1283     EnableMenuItem(FileMenu,ID_FILE_STOPLOG, MF_BYCOMMAND | MF_GRAYED);
1284    
1285     CheckMenuItem(FileMenu,ID_FILE_PAUSELOG, MF_BYCOMMAND | MF_UNCHECKED);
1286 maya 3227 }
1287    
1288     }
1289     else if ( SubMenu == TransMenu )
1290     {
1291     if ((cv.PortType==IdSerial) &&
1292     ((ts.DataBit==IdDataBit7) || (ts.Flow==IdFlowX))) {
1293     EnableMenuItem(TransMenu,1,MF_BYPOSITION | MF_GRAYED); /* XMODEM */
1294     EnableMenuItem(TransMenu,4,MF_BYPOSITION | MF_GRAYED); /* Quick-VAN */
1295     }
1296     else {
1297     EnableMenuItem(TransMenu,1,MF_BYPOSITION | MF_ENABLED); /* XMODEM */
1298     EnableMenuItem(TransMenu,4,MF_BYPOSITION | MF_ENABLED); /* Quick-VAN */
1299     }
1300     if ((cv.PortType==IdSerial) &&
1301     (ts.DataBit==IdDataBit7)) {
1302     EnableMenuItem(TransMenu,2,MF_BYPOSITION | MF_GRAYED); /* ZMODEM */
1303     EnableMenuItem(TransMenu,3,MF_BYPOSITION | MF_GRAYED); /* B-Plus */
1304     }
1305     else {
1306     EnableMenuItem(TransMenu,2,MF_BYPOSITION | MF_ENABLED); /* ZMODEM */
1307     EnableMenuItem(TransMenu,3,MF_BYPOSITION | MF_ENABLED); /* B-Plus */
1308     }
1309     }
1310     else if (SubMenu == EditMenu)
1311     {
1312     if (Selected) {
1313     EnableMenuItem(EditMenu,ID_EDIT_COPY2,MF_BYCOMMAND | MF_ENABLED);
1314     EnableMenuItem(EditMenu,ID_EDIT_COPYTABLE,MF_BYCOMMAND | MF_ENABLED);
1315     }
1316     else {
1317     EnableMenuItem(EditMenu,ID_EDIT_COPY2,MF_BYCOMMAND | MF_GRAYED);
1318     EnableMenuItem(EditMenu,ID_EDIT_COPYTABLE,MF_BYCOMMAND | MF_GRAYED);
1319     }
1320     if (cv.Ready &&
1321     (SendVar==NULL) && (FileVar==NULL) &&
1322     (cv.PortType!=IdFile) &&
1323     (IsClipboardFormatAvailable(CF_TEXT) ||
1324     IsClipboardFormatAvailable(CF_OEMTEXT))) {
1325     EnableMenuItem(EditMenu,ID_EDIT_PASTE2,MF_BYCOMMAND | MF_ENABLED);
1326     EnableMenuItem(EditMenu,ID_EDIT_PASTECR,MF_BYCOMMAND | MF_ENABLED);
1327     }
1328     else {
1329     EnableMenuItem(EditMenu,ID_EDIT_PASTE2,MF_BYCOMMAND | MF_GRAYED);
1330     EnableMenuItem(EditMenu,ID_EDIT_PASTECR,MF_BYCOMMAND | MF_GRAYED);
1331     }
1332     }
1333     else if (SubMenu == SetupMenu)
1334 yutakapon 8179 /*
1335     * �l�b�g���[�N������(TCP/IP���I������������������)���V���A���|�[�g
1336     * (ID_SETUP_SERIALPORT)�����j���[���I�����������������������������A
1337     * �����K�[�h���O���A�V���A���|�[�g�����_�C�A���O�����V���������������������������B
1338     */
1339     if ((SendVar!=NULL) || (FileVar!=NULL) || Connecting) {
1340     EnableMenuItem(SetupMenu,ID_SETUP_SERIALPORT,MF_BYCOMMAND | MF_GRAYED);
1341 maya 3392 }
1342     else {
1343 yutakapon 8179 EnableMenuItem(SetupMenu,ID_SETUP_SERIALPORT,MF_BYCOMMAND | MF_ENABLED);
1344 maya 3392 }
1345 maya 3227
1346     else if (SubMenu == ControlMenu)
1347     {
1348     if (cv.Ready &&
1349     (SendVar==NULL) && (FileVar==NULL)) {
1350 maya 3283 if (ts.DisableMenuSendBreak) {
1351 maya 3279 EnableMenuItem(ControlMenu,ID_CONTROL_SENDBREAK,MF_BYCOMMAND | MF_GRAYED);
1352     }
1353     else {
1354     EnableMenuItem(ControlMenu,ID_CONTROL_SENDBREAK,MF_BYCOMMAND | MF_ENABLED);
1355     }
1356 maya 3392 if (cv.PortType==IdSerial) {
1357 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_RESETPORT,MF_BYCOMMAND | MF_ENABLED);
1358 maya 3392 }
1359     else {
1360 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_RESETPORT,MF_BYCOMMAND | MF_GRAYED);
1361 maya 3392 }
1362 maya 3227 }
1363     else {
1364     EnableMenuItem(ControlMenu,ID_CONTROL_SENDBREAK,MF_BYCOMMAND | MF_GRAYED);
1365     EnableMenuItem(ControlMenu,ID_CONTROL_RESETPORT,MF_BYCOMMAND | MF_GRAYED);
1366     }
1367    
1368 maya 3392 if (cv.Ready && cv.TelFlag && (FileVar==NULL)) {
1369 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_AREYOUTHERE,MF_BYCOMMAND | MF_ENABLED);
1370 maya 3392 }
1371     else {
1372 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_AREYOUTHERE,MF_BYCOMMAND | MF_GRAYED);
1373 maya 3392 }
1374 maya 3227
1375 maya 3392 if (HTEKWin==0) {
1376 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_CLOSETEK,MF_BYCOMMAND | MF_GRAYED);
1377 maya 3392 }
1378     else {
1379 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_CLOSETEK,MF_BYCOMMAND | MF_ENABLED);
1380 maya 3392 }
1381 maya 3227
1382 maya 3392 if ((ConvH!=0) || (FileVar!=NULL)) {
1383 maya 3227 EnableMenuItem(ControlMenu,ID_CONTROL_MACRO,MF_BYCOMMAND | MF_GRAYED);
1384 maya 3842 EnableMenuItem(ControlMenu,ID_CONTROL_SHOW_MACRO,MF_BYCOMMAND | MF_ENABLED);
1385 maya 3392 }
1386     else {
1387 yutakapon 3837 EnableMenuItem(ControlMenu,ID_CONTROL_MACRO,MF_BYCOMMAND | MF_ENABLED);
1388 maya 3842 EnableMenuItem(ControlMenu,ID_CONTROL_SHOW_MACRO,MF_BYCOMMAND | MF_GRAYED);
1389 maya 3392 }
1390 maya 3227
1391     }
1392     else if (SubMenu == WinMenu)
1393     {
1394 yutakapon 5249 SetWinMenu(WinMenu, ts.UIMsg, sizeof(ts.UIMsg), ts.UILanguageFile, 1);
1395 maya 3227 }
1396    
1397     TTXModifyPopupMenu(SubMenu); /* TTPLUG */
1398     }
1399    
1400     // added ConfirmPasteMouseRButton (2007.3.17 maya)
1401     void CVTWindow::InitPasteMenu(HMENU *Menu)
1402     {
1403 doda 8445 static const DlgTextInfo MenuTextInfo[] = {
1404     { ID_EDIT_PASTE2, "MENU_EDIT_PASTE" },
1405     { ID_EDIT_PASTECR, "MENU_EDIT_PASTECR" },
1406     };
1407 zmatsuo 7916 *Menu = LoadMenu(m_hInst,
1408 maya 3227 MAKEINTRESOURCE(IDR_PASTEMENU));
1409 doda 8445 SetDlgMenuTexts(*Menu, MenuTextInfo, _countof(MenuTextInfo), ts.UILanguageFile);
1410 maya 3227 }
1411    
1412     void CVTWindow::ResetSetup()
1413     {
1414     ChangeFont();
1415     BuffChangeWinSize(WinWidth,WinHeight);
1416     ChangeCaret();
1417    
1418     if (cv.Ready) {
1419     ts.PortType = cv.PortType;
1420     if (cv.PortType==IdSerial) {
1421     /* if serial port, change port parameters */
1422     ts.ComPort = cv.ComPort;
1423     CommResetSerial(&ts, &cv, TRUE);
1424     }
1425     }
1426    
1427     /* setup terminal */
1428     SetupTerm();
1429    
1430     /* background and ANSI color */
1431     #ifdef ALPHABLEND_TYPE2
1432 yutakapon 8106 BGInitialize(FALSE);
1433 maya 3227 BGSetupPrimary(TRUE);
1434     // 2006/03/17 by 337 : Alpha�l���������X
1435     // Layered��������������������������������
1436 yutakapon 6553 //
1437     // AlphaBlend ���������f�����������������B
1438     // (2016.12.24 yutaka)
1439 zmatsuo 7390 SetWindowAlpha(ts.AlphaBlendActive);
1440 maya 3227 #else
1441     DispApplyANSIColor();
1442     #endif
1443     DispSetNearestColors(IdBack, IdFore+8, NULL);
1444    
1445     /* setup window */
1446     ChangeWin();
1447    
1448     /* Language & IME */
1449     ResetIME();
1450    
1451     /* change TEK window */
1452     if (pTEKWin != NULL)
1453     ((CTEKWindow *)pTEKWin)->RestoreSetup();
1454     }
1455    
1456     void CVTWindow::RestoreSetup()
1457     {
1458     char TempDir[MAXPATHLEN];
1459 maya 4031 char TempName[MAX_PATH];
1460 maya 3227
1461 maya 3392 if ( strlen(ts.SetupFName)==0 ) {
1462 maya 3227 return;
1463 maya 3392 }
1464 maya 3227
1465     ExtractFileName(ts.SetupFName,TempName,sizeof(TempName));
1466     ExtractDirName(ts.SetupFName,TempDir);
1467     if (TempDir[0]==0)
1468     strncpy_s(TempDir, sizeof(TempDir),ts.HomeDir, _TRUNCATE);
1469     FitFileName(TempName,sizeof(TempName),".INI");
1470    
1471     strncpy_s(ts.SetupFName, sizeof(ts.SetupFName),TempDir, _TRUNCATE);
1472     AppendSlash(ts.SetupFName,sizeof(ts.SetupFName));
1473 maya 3392 strncat_s(ts.SetupFName,sizeof(ts.SetupFName),TempName,_TRUNCATE);
1474 maya 3227
1475 maya 3392 if (LoadTTSET()) {
1476 maya 3227 (*ReadIniFile)(ts.SetupFName,&ts);
1477 maya 3392 }
1478 maya 3227 FreeTTSET();
1479    
1480     #if 0
1481     ChangeDefaultSet(&ts,NULL);
1482     #endif
1483    
1484     ResetSetup();
1485     }
1486    
1487     /* called by the [Setup] Terminal command */
1488     void CVTWindow::SetupTerm()
1489     {
1490 doda 3407 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
1491 maya 3227 ResetCharSet();
1492 maya 3393 }
1493 maya 3227 cv.CRSend = ts.CRSend;
1494    
1495     // for russian mode
1496     cv.RussHost = ts.RussHost;
1497     cv.RussClient = ts.RussClient;
1498    
1499 doda 3932 if (cv.Ready) {
1500     if (cv.TelFlag && (ts.TelEcho>0)) {
1501     TelChangeEcho();
1502     }
1503     _free_locale(cv.locale);
1504     cv.locale = _create_locale(LC_ALL, cv.Locale);
1505 maya 3392 }
1506 maya 3227
1507     if ((ts.TerminalWidth!=NumOfColumns) ||
1508     (ts.TerminalHeight!=NumOfLines-StatusLine)) {
1509     LockBuffer();
1510     HideStatusLine();
1511     ChangeTerminalSize(ts.TerminalWidth,
1512     ts.TerminalHeight);
1513     UnlockBuffer();
1514     }
1515     else if ((ts.TermIsWin>0) &&
1516     ((ts.TerminalWidth!=WinWidth) ||
1517 maya 3392 (ts.TerminalHeight!=WinHeight-StatusLine))) {
1518 maya 3227 BuffChangeWinSize(ts.TerminalWidth,ts.TerminalHeight+StatusLine);
1519 maya 3392 }
1520 doda 4246
1521     ChangeTerminalID();
1522 maya 3227 }
1523    
1524     void CVTWindow::Startup()
1525     {
1526     /* auto log */
1527     /* OnCommOpen ���J�n�������������������J�n������ (2007.5.14 maya) */
1528    
1529     if ((TopicName[0]==0) && (ts.MacroFN[0]!=0)) {
1530     // start the macro specified in the command line or setup file
1531     RunMacro(ts.MacroFN,TRUE);
1532     ts.MacroFN[0] = 0;
1533     }
1534     else {// start connection
1535 maya 3392 if (TopicName[0]!=0) {
1536 maya 3227 cv.NoMsg=1; /* suppress error messages */
1537 maya 3392 }
1538 maya 3227 ::PostMessage(HVTWin,WM_USER_COMMSTART,0,0);
1539     }
1540     }
1541    
1542     void CVTWindow::OpenTEK()
1543     {
1544     ActiveWin = IdTEK;
1545     if (HTEKWin==NULL) {
1546 zmatsuo 7916 pTEKWin = new CTEKWindow(m_hInst);
1547 maya 3227 }
1548     else {
1549     ::ShowWindow(HTEKWin,SW_SHOWNORMAL);
1550     ::SetFocus(HTEKWin);
1551     }
1552     }
1553    
1554     /////////////////////////////////////////////////////////////////////////////
1555     // CVTWindow message handler
1556    
1557     BOOL CVTWindow::OnCommand(WPARAM wParam, LPARAM lParam)
1558     {
1559     WORD wID = LOWORD(wParam);
1560     WORD wNotifyCode = HIWORD(wParam);
1561    
1562     if (wNotifyCode==1) {
1563     switch (wID) {
1564     case ID_ACC_SENDBREAK:
1565     // added DisableAcceleratorSendBreak (2007.3.17 maya)
1566     if (!ts.DisableAcceleratorSendBreak)
1567     OnControlSendBreak();
1568     return TRUE;
1569     case ID_ACC_AREYOUTHERE:
1570     OnControlAreYouThere();
1571     return TRUE;
1572     }
1573     if (ActiveWin==IdVT) {
1574     switch (wID) {
1575     case ID_ACC_NEWCONNECTION:
1576 maya 5684 if (ts.AcceleratorNewConnection)
1577     OnFileNewConnection();
1578 maya 3227 return TRUE;
1579 maya 5691 case ID_ACC_DUPLICATESESSION:
1580     // added DisableAcceleratorDuplicateSession (2009.4.6 maya)
1581     if (!ts.DisableAcceleratorDuplicateSession)
1582     OnDuplicateSession();
1583     return TRUE;
1584 maya 5684 case ID_ACC_CYGWINCONNECTION:
1585     if (ts.AcceleratorCygwinConnection)
1586     OnCygwinConnection();
1587     return TRUE;
1588 maya 5691 case ID_ACC_DISCONNECT:
1589     Disconnect(TRUE);
1590     return TRUE;
1591 maya 3227 case ID_ACC_COPY:
1592     OnEditCopy();
1593     return TRUE;
1594 doda 6459 case ID_ACC_PASTECR:
1595     OnEditPasteCR();
1596     return TRUE;
1597     case ID_ACC_PASTE:
1598     OnEditPaste();
1599     return TRUE;
1600 maya 3227 case ID_ACC_PRINT:
1601     OnFilePrint();
1602     return TRUE;
1603     case ID_ACC_EXIT:
1604     OnFileExit();
1605     return TRUE;
1606     }
1607     }
1608     else { // transfer accelerator message to TEK win
1609     switch (wID) {
1610     case ID_ACC_COPY:
1611     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKEDIT_COPY,0);
1612     return TRUE;
1613 doda 6459 case ID_ACC_PASTECR:
1614     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKEDIT_PASTECR,0);
1615     return TRUE;
1616     case ID_ACC_PASTE:
1617     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKEDIT_PASTE,0);
1618     return TRUE;
1619 maya 3227 case ID_ACC_PRINT:
1620     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKFILE_PRINT,0);
1621     return TRUE;
1622     case ID_ACC_EXIT:
1623     ::PostMessage(HTEKWin,WM_COMMAND,ID_TEKFILE_EXIT,0);
1624     return TRUE;
1625     }
1626     }
1627     }
1628    
1629     if ((wID>=ID_WINDOW_1) && (wID<ID_WINDOW_1+9)) {
1630     SelectWin(wID-ID_WINDOW_1);
1631     return TRUE;
1632     }
1633     else {
1634 maya 3392 if (TTXProcessCommand(HVTWin, wID)) {
1635 maya 3227 return TRUE;
1636 maya 3392 }
1637     else { /* TTPLUG */
1638 zmatsuo 7784 return TTCFrameWnd::OnCommand(wParam, lParam);
1639 maya 3392 }
1640 maya 3227 }
1641     }
1642    
1643 zmatsuo 7528 void CVTWindow::OnActivate(UINT nState, HWND pWndOther, BOOL bMinimized)
1644 maya 3227 {
1645     DispSetActive(nState!=WA_INACTIVE);
1646 zmatsuo 7390 if (nState == WA_INACTIVE) {
1647     SetWindowAlpha(ts.AlphaBlendInactive);
1648     } else {
1649     SetWindowAlpha(ts.AlphaBlendActive);
1650     }
1651 maya 3227 }
1652    
1653 zmatsuo 8337 void CVTWindow::OnChar(WPARAM nChar, UINT nRepCnt, UINT nFlags)
1654 maya 3227 {
1655     unsigned int i;
1656    
1657 maya 3392 if (!KeybEnabled || (TalkStatus!=IdTalkKeyb)) {
1658 maya 3227 return;
1659 maya 3392 }
1660 maya 3227
1661 doda 4414 if (MetaKey(ts.MetaKey)) {
1662 maya 3227 ::PostMessage(HVTWin,WM_SYSCHAR,nChar,MAKELONG(nRepCnt,nFlags));
1663     return;
1664     }
1665    
1666 doda 8445 #if UNICODE_INTERNAL_BUFF
1667 maya 3227 for (i=1 ; i<=nRepCnt ; i++) {
1668 doda 8445 wchar_t u16 = nChar;
1669     CommTextOutW(&cv,&u16,1);
1670 maya 3392 if (ts.LocalEcho>0) {
1671 doda 8445 CommTextEchoW(&cv,&u16,1);
1672 maya 3392 }
1673 maya 3227 }
1674 doda 8445 #else
1675     {
1676     char Code = nChar;
1677     if ((ts.Language==IdRussian) &&
1678     ((BYTE)Code>=128)) {
1679     Code = (char)RussConv(ts.RussKeyb,ts.RussClient,(BYTE)Code);
1680     }
1681 maya 3227
1682 doda 8445 for (i=1 ; i<=nRepCnt ; i++) {
1683     CommTextOut(&cv,&Code,1);
1684     if (ts.LocalEcho>0) {
1685     CommTextEcho(&cv,&Code,1);
1686     }
1687     }
1688     }
1689     #endif
1690    
1691 doda 6421 // �X�N���[�����u�����Z�b�g
1692     if (WinOrgY != 0) {
1693 maya 3227 DispVScroll(SCROLL_BOTTOM, 0);
1694     }
1695     }
1696    
1697     /* copy from ttset.c*/
1698     static void WriteInt2(PCHAR Sect, PCHAR Key, PCHAR FName, int i1, int i2)
1699     {
1700     char Temp[32];
1701     _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d,%d", i1, i2);
1702     WritePrivateProfileString(Sect, Key, Temp, FName);
1703     }
1704    
1705     static void SaveVTPos()
1706     {
1707     #define Section "Tera Term"
1708     if (ts.SaveVTWinPos) {
1709     /* VT win position */
1710     WriteInt2(Section, "VTPos", ts.SetupFName, ts.VTPos.x, ts.VTPos.y);
1711    
1712     /* VT terminal size */
1713     WriteInt2(Section, "TerminalSize", ts.SetupFName,
1714     ts.TerminalWidth, ts.TerminalHeight);
1715     }
1716     }
1717    
1718     void CVTWindow::OnClose()
1719     {
1720     if ((HTEKWin!=NULL) && ! ::IsWindowEnabled(HTEKWin)) {
1721     MessageBeep(0);
1722     return;
1723     }
1724     get_lang_msg("MSG_DISCONNECT_CONF", ts.UIMsg, sizeof(ts.UIMsg),
1725     "Disconnect?", ts.UILanguageFile);
1726     if (cv.Ready && (cv.PortType==IdTCPIP) &&
1727     ((ts.PortFlag & PF_CONFIRMDISCONN) != 0) &&
1728     ! CloseTT &&
1729     (::MessageBox(HVTWin, ts.UIMsg, "Tera Term",
1730 maya 3392 MB_OKCANCEL | MB_ICONEXCLAMATION | MB_DEFBUTTON2)==IDCANCEL)) {
1731 maya 3227 return;
1732 maya 3392 }
1733 maya 3227
1734     FileTransEnd(0);
1735     ProtoEnd();
1736    
1737     SaveVTPos();
1738     DestroyWindow();
1739     }
1740    
1741 yutakapon 5232 // �STera Term���I�����w������
1742     void CVTWindow::OnAllClose()
1743     {
1744 yutakapon 5351 // ���R�I���������������������A�����������[�U���������������o�������������B
1745     // (2013.8.17 yutaka)
1746     get_lang_msg("MSG_ALL_TERMINATE_CONF", ts.UIMsg, sizeof(ts.UIMsg),
1747     "Terminate ALL Tera Term(s)?", ts.UILanguageFile);
1748     if (::MessageBox(HVTWin, ts.UIMsg, "Tera Term",
1749 doda 6435 MB_OKCANCEL | MB_ICONERROR | MB_DEFBUTTON2)==IDCANCEL)
1750 yutakapon 5351 return;
1751    
1752 yutakapon 5232 BroadcastClosingMessage(HVTWin);
1753     }
1754    
1755     // �I������������������Tera Term���I�������BOnAllClose()���M�p�B
1756 zmatsuo 7896 LRESULT CVTWindow::OnNonConfirmClose(WPARAM wParam, LPARAM lParam)
1757 yutakapon 5232 {
1758     // ������ ts �����e�����}�I���������������A�I�����������Z�[�u�����������������������A�������������B
1759     ts.PortFlag &= ~PF_CONFIRMDISCONN;
1760     OnClose();
1761     return 1;
1762     }
1763    
1764 maya 3227 void CVTWindow::OnDestroy()
1765     {
1766     // remove this window from the window list
1767     UnregWin(HVTWin);
1768    
1769 salarm 6100 // USB�f�o�C�X�������m����
1770     UnRegDeviceNotify(HVTWin);
1771    
1772 maya 3227 EndKeyboard();
1773    
1774     /* Disable drag-drop */
1775     ::DragAcceptFiles(HVTWin,FALSE);
1776 zmatsuo 7148 DropListFree();
1777 maya 3227
1778     EndDDE();
1779    
1780 maya 3392 if (cv.TelFlag) {
1781 maya 3227 EndTelnet();
1782 maya 3392 }
1783 maya 3227 CommClose(&cv);
1784    
1785 yutakapon 5636 OpenHelp(HH_CLOSE_ALL, 0, ts.UILanguageFile);
1786 maya 3227
1787 zmatsuo 7485 FreeIME(HVTWin);
1788 maya 3227 FreeTTSET();
1789 zmatsuo 7515 #if 0 // free�����s��������free��������
1790 maya 3227 do { }
1791 maya 3392 while (FreeTTDLG());
1792 zmatsuo 7515 #endif
1793 maya 3227
1794     do { }
1795 maya 3392 while (FreeTTFILE());
1796 maya 3227
1797 maya 3392 if (HTEKWin != NULL) {
1798 maya 3227 ::DestroyWindow(HTEKWin);
1799 maya 3392 }
1800 maya 3227
1801 doda 3450 EndTerm();
1802 maya 3227 EndDisp();
1803    
1804     FreeBuffer();
1805    
1806 zmatsuo 7784 TTCFrameWnd::OnDestroy();
1807 maya 3227 TTXEnd(); /* TTPLUG */
1808 doda 6662
1809     DeleteNotifyIcon(&cv);
1810 maya 3227 }
1811    
1812 doda 8445 static void EscapeFilename(const wchar_t *src, wchar_t *dest)
1813 maya 3227 {
1814 doda 8445 #define ESCAPE_CHARS L" ;&()$!`'[]{}#^~"
1815     const wchar_t *s = src;
1816     wchar_t *d = dest;
1817 zmatsuo 7148 while (*s) {
1818 doda 8445 wchar_t c = *s++;
1819     if (c == L'\\') {
1820 zmatsuo 7148 // �p�X���������� \ -> / ��
1821     *d = '/';
1822 doda 8445 } else if (wcschr(ESCAPE_CHARS, c) != NULL) {
1823 zmatsuo 7148 // �G�X�P�[�v���K�v������
1824 doda 8445 *d++ = L'\\';
1825 zmatsuo 7148 *d = c;
1826     } else {
1827     *d = c;
1828     }
1829     d++;
1830     }
1831     *d = '\0'; // null-terminate
1832     }
1833 maya 3227
1834 doda 8445 static void PasteString(PComVar cv, const wchar_t *str, bool escape)
1835 zmatsuo 7148 {
1836 doda 8445 wchar_t *ptr = (wchar_t *)str;
1837     wchar_t *tmpbuf;
1838     if (!escape) {
1839     tmpbuf = _wcsdup(str);
1840     }
1841     else {
1842     const size_t len = wcslen(str) * sizeof(wchar_t) * 2;
1843     tmpbuf = (wchar_t *)malloc(len);
1844 zmatsuo 7148 EscapeFilename(str, tmpbuf);
1845     ptr = tmpbuf;
1846     }
1847 yutakapon 4891
1848 doda 8445 SendMemPasteString(tmpbuf);
1849 zmatsuo 7148 }
1850 yutakapon 4891
1851 zmatsuo 7148 /* �������t�@�C������(�t�H���_������������) */
1852 doda 8445 static bool SendScp(wchar_t *Filenames[], int FileCount, const char *SendDir)
1853 zmatsuo 7148 {
1854     typedef int (CALLBACK *PSSH_start_scp)(char *, char *);
1855     static PSSH_start_scp func = NULL;
1856     static HMODULE h = NULL;
1857     char msg[128];
1858 yutakapon 4891
1859 zmatsuo 7148 if (h == NULL) {
1860     if ( ((h = GetModuleHandle("ttxssh.dll")) == NULL) ) {
1861     _snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetModuleHandle(\"ttxssh.dll\")) %d", GetLastError());
1862     scp_send_error:
1863     ::MessageBox(NULL, msg, "Tera Term: scpsend command error", MB_OK | MB_ICONERROR);
1864     return false;
1865     }
1866     }
1867     if (func == NULL) {
1868     func = (PSSH_start_scp)GetProcAddress(h, "TTXScpSendfile");
1869     if (func == NULL) {
1870     _snprintf_s(msg, sizeof(msg), _TRUNCATE, "GetProcAddress(\"TTXScpSendfile\")) %d", GetLastError());
1871     goto scp_send_error;
1872     }
1873     }
1874 yutakapon 4891
1875 zmatsuo 7148 for (int i = 0; i < FileCount; i++) {
1876 doda 8445 char *FileName = ToU8W(Filenames[i]);
1877 zmatsuo 7148 func((char *)FileName, ts.ScpSendDir);
1878 doda 8445 free(FileName);
1879 zmatsuo 7148 }
1880     return true;
1881     }
1882 doda 6620
1883 zmatsuo 7148 void CVTWindow::DropListFree()
1884     {
1885     if (DropListCount > 0) {
1886     for (int i = 0; i < DropListCount; i++) {
1887     free(DropLists[i]);
1888     DropLists[i] = NULL;
1889     }
1890     free(DropLists);
1891     DropLists = NULL;
1892     DropListCount = 0;
1893     }
1894     }
1895 yutakapon 4891
1896 zmatsuo 7896 LRESULT CVTWindow::OnDropNotify(WPARAM ShowDialog, LPARAM lParam)
1897 zmatsuo 7148 {
1898     // ini���������������A�����s��������Tera Term�������L��������
1899     static enum drop_type DefaultDropType = DROP_TYPE_CANCEL;
1900     static unsigned char DefaultDropTypePaste = DROP_TYPE_PASTE_ESCAPE;
1901     static bool DefaultShowDialog = ts.ConfirmFileDragAndDrop ? true : false;
1902 doda 6620
1903 zmatsuo 7148 (void)lParam;
1904     int FileCount = 0;
1905     int DirectoryCount = 0;
1906     for (int i = 0; i < DropListCount; i++) {
1907 doda 8445 const wchar_t *FileName = DropLists[i];
1908     const DWORD attr = _GetFileAttributesW(FileName);
1909 zmatsuo 7650 if (attr == INVALID_FILE_ATTRIBUTES) {
1910 zmatsuo 7536 FileCount++;
1911     } else if (attr & FILE_ATTRIBUTE_DIRECTORY) {
1912 zmatsuo 7148 DirectoryCount++;
1913     } else {
1914     FileCount++;
1915     }
1916     }
1917 yutakapon 4891
1918 zmatsuo 7148 bool DoSameProcess = false;
1919     const bool isSSH = (cv.isSSH == 2);
1920     enum drop_type DropType;
1921     unsigned char DropTypePaste = DROP_TYPE_PASTE_ESCAPE;
1922     if (DefaultDropType == DROP_TYPE_CANCEL) {
1923     // default is not set
1924     if (!ShowDialog) {
1925     if (FileCount == 1 && DirectoryCount == 0) {
1926     if (ts.ConfirmFileDragAndDrop) {
1927     if (isSSH) {
1928     DropType = DROP_TYPE_SCP;
1929     } else {
1930     DropType = DROP_TYPE_SEND_FILE;
1931 yutakapon 4891 }
1932 zmatsuo 7148 DoSameProcess = false;
1933     } else {
1934     DropType = DROP_TYPE_SEND_FILE;
1935     DoSameProcess = DefaultShowDialog ? false : true;
1936     }
1937     } else if (FileCount == 0 && DirectoryCount == 1) {
1938     DropType = DROP_TYPE_PASTE_FILENAME;
1939     DoSameProcess = DefaultShowDialog ? false : true;
1940     } else if (FileCount > 0 && DirectoryCount > 0) {
1941     DropType = DROP_TYPE_PASTE_FILENAME;
1942     DoSameProcess = false;
1943     } else if (FileCount > 0 && DirectoryCount == 0) {
1944     // filename only
1945     if (isSSH) {
1946     DropType = DROP_TYPE_SCP;
1947     } else {
1948     DropType = DROP_TYPE_SEND_FILE;
1949     }
1950     DoSameProcess = false;
1951     } else {
1952     // directory only
1953     DropType = DROP_TYPE_PASTE_FILENAME;
1954     DoSameProcess = ts.ConfirmFileDragAndDrop ? false : true;
1955     }
1956     } else {
1957     // show dialog
1958     if (DirectoryCount > 0) {
1959     DropType = DROP_TYPE_PASTE_FILENAME;
1960     } else {
1961     if (isSSH) {
1962     DropType = DROP_TYPE_SCP;
1963     } else {
1964     DropType = DROP_TYPE_SEND_FILE;
1965     }
1966     }
1967     DoSameProcess = false;
1968     }
1969     } else {
1970     if (DirectoryCount > 0 &&
1971     (DefaultDropType == DROP_TYPE_SEND_FILE ||
1972     DefaultDropType == DROP_TYPE_SEND_FILE_BINARY ||
1973     DefaultDropType == DROP_TYPE_SCP))
1974     { // �f�t�H���g�����������������������g��������
1975     DropType = DROP_TYPE_PASTE_FILENAME;
1976     DropTypePaste = DefaultDropTypePaste;
1977     DoSameProcess = false;
1978     } else {
1979     DropType = DefaultDropType;
1980     DropTypePaste = DefaultDropTypePaste;
1981     DoSameProcess = (ShowDialog || DefaultShowDialog) ? false : true;
1982     }
1983     }
1984 yutakapon 4891
1985 zmatsuo 7148 for (int i = 0; i < DropListCount; i++) {
1986 doda 8445 const wchar_t *FileName = DropLists[i];
1987 yutakapon 4891
1988 zmatsuo 7148 if (!DoSameProcess) {
1989     bool DoSameProcessNextDrop;
1990     bool DoNotShowDialog = !DefaultShowDialog;
1991 zmatsuo 7706 SetDialogFont(ts.DialogFontName, ts.DialogFontPoint, ts.DialogFontCharSet,
1992 zmatsuo 7589 ts.UILanguageFile, "Tera Term", "DLG_SYSTEM_FONT");
1993 zmatsuo 7148 DropType =
1994 zmatsuo 7916 ShowDropDialogBox(m_hInst, HVTWin,
1995 zmatsuo 7148 FileName, DropType,
1996     DropListCount - i,
1997     (DirectoryCount == 0 && isSSH) ? true : false,
1998     DirectoryCount == 0 ? true : false,
1999 zmatsuo 7172 &ts,
2000 zmatsuo 7148 &DropTypePaste,
2001     &DoSameProcess,
2002     &DoSameProcessNextDrop,
2003     &DoNotShowDialog);
2004     if (DropType == DROP_TYPE_CANCEL) {
2005     goto finish;
2006     }
2007     if (DoSameProcessNextDrop) {
2008     DefaultDropType = DropType;
2009     DefaultDropTypePaste = DropTypePaste;
2010     }
2011     if (!ts.ConfirmFileDragAndDrop) {
2012     DefaultShowDialog = !DoNotShowDialog;
2013     }
2014     }
2015 zmatsuo 7322
2016 zmatsuo 7148 switch (DropType) {
2017     case DROP_TYPE_CANCEL:
2018     default:
2019     // cancel
2020     break;
2021     case DROP_TYPE_SEND_FILE:
2022     case DROP_TYPE_SEND_FILE_BINARY:
2023     if (SendVar==NULL && NewFileVar(&SendVar)) {
2024 doda 8445 SendMemSendFile(FileName, DropType == DROP_TYPE_SEND_FILE ? FALSE : TRUE);
2025 yutakapon 4891 }
2026 zmatsuo 7148 break;
2027     case DROP_TYPE_PASTE_FILENAME:
2028     {
2029     const bool escape = (DropTypePaste & DROP_TYPE_PASTE_ESCAPE) ? true : false;
2030 doda 7195
2031     TermSendStartBracket();
2032    
2033 zmatsuo 7148 PasteString(&cv, FileName, escape);
2034     if (DropListCount > 1 && i < DropListCount - 1) {
2035 doda 8445 const wchar_t *separator = (DropTypePaste & DROP_TYPE_PASTE_NEWLINE) ? L"\n" : L" ";
2036 zmatsuo 7148 PasteString(&cv, separator, false);
2037     }
2038 doda 7195
2039     TermSendEndBracket();
2040    
2041 zmatsuo 7148 break;
2042     }
2043     case DROP_TYPE_SCP:
2044     {
2045     // send by scp
2046 doda 8445 wchar_t **FileNames = &DropLists[i];
2047 zmatsuo 7148 int FileCount = DoSameProcess ? DropListCount - i : 1;
2048     if (!SendScp(FileNames, FileCount, ts.ScpSendDir)) {
2049     goto finish;
2050     }
2051     i += FileCount - 1;
2052     break;
2053     }
2054     }
2055     }
2056 yutakapon 4891
2057 zmatsuo 7148 finish:
2058     DropListFree();
2059     return 0;
2060 maya 3227 }
2061    
2062     void CVTWindow::OnDropFiles(HDROP hDropInfo)
2063     {
2064     ::SetForegroundWindow(HVTWin);
2065 zmatsuo 7148 if (cv.Ready && SendVar==NULL)
2066 maya 3227 {
2067 zmatsuo 7148 const UINT ShowDialog =
2068     ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0) ? 1 : 0;
2069 doda 8445 DropListCount = _DragQueryFileW(hDropInfo, -1, NULL, 0);
2070     DropLists = (wchar_t **)malloc(sizeof(wchar_t *) * DropListCount);
2071 maya 3227
2072 zmatsuo 7148 for (int i = 0; i < DropListCount; i++) {
2073 doda 8445 const UINT cch = _DragQueryFileW(hDropInfo, i, NULL, 0);
2074     if (cch == 0) {
2075     continue;
2076     }
2077     wchar_t *FileName = (wchar_t *)malloc(sizeof(wchar_t) * (cch + 1));
2078     _DragQueryFileW(hDropInfo,i,FileName,cch + 1);
2079     FileName[cch] = '\0';
2080 zmatsuo 7148 DropLists[i] = FileName;
2081     }
2082 maya 3227
2083 zmatsuo 7148 ::PostMessage(HVTWin, WM_USER_DROPNOTIFY, ShowDialog, 0);
2084 maya 3227 }
2085     DragFinish(hDropInfo);
2086     }
2087    
2088 doda 6801 void CVTWindow::OnGetMinMaxInfo(MINMAXINFO *lpMMI)
2089 maya 3227 {
2090     #ifndef WINDOW_MAXMIMUM_ENABLED
2091     lpMMI->ptMaxSize.x = 10000;
2092     lpMMI->ptMaxSize.y = 10000;
2093     lpMMI->ptMaxTrackSize.x = 10000;
2094     lpMMI->ptMaxTrackSize.y = 10000;
2095     #endif
2096     }
2097    
2098 zmatsuo 7528 void CVTWindow::OnHScroll(UINT nSBCode, UINT nPos, HWND pScrollBar)
2099 maya 3227 {
2100     int Func;
2101    
2102     switch (nSBCode) {
2103     case SB_BOTTOM:
2104     Func = SCROLL_BOTTOM;
2105     break;
2106     case SB_ENDSCROLL:
2107     return;
2108     case SB_LINEDOWN:
2109     Func = SCROLL_LINEDOWN;
2110     break;
2111     case SB_LINEUP:
2112     Func = SCROLL_LINEUP;
2113     break;
2114     case SB_PAGEDOWN:
2115     Func = SCROLL_PAGEDOWN;
2116     break;
2117 doda 6435 case SB_PAGEUP:
2118 maya 3227 Func = SCROLL_PAGEUP;
2119     break;
2120     case SB_THUMBPOSITION:
2121     case SB_THUMBTRACK:
2122     Func = SCROLL_POS;
2123     break;
2124     case SB_TOP:
2125     Func = SCROLL_TOP;
2126     break;
2127     default:
2128     return;
2129     }
2130     DispHScroll(Func,nPos);
2131     }
2132    
2133 zmatsuo 7528 void CVTWindow::OnInitMenuPopup(HMENU hPopupMenu, UINT nIndex, BOOL bSysMenu)
2134 maya 3227 {
2135 zmatsuo 7528 InitMenuPopup(hPopupMenu);
2136 maya 3227 }
2137    
2138 zmatsuo 8337 void CVTWindow::OnKeyDown(WPARAM nChar, UINT nRepCnt, UINT nFlags)
2139 maya 3227 {
2140     BYTE KeyState[256];
2141     MSG M;
2142    
2143 doda 8445 #if UNICODE_DEBUG
2144     if (UnicodeDebugParam.CodePopupEnable)
2145     {
2146     const DWORD now = GetTickCount();
2147     switch(CtrlKeyState) {
2148     case 0:
2149     if (nChar == UnicodeDebugParam.CodePopupKey1) {
2150     CtrlKeyDownTick = now;
2151     CtrlKeyState = 1;
2152     }
2153     break;
2154     case 2:
2155     if (nChar != UnicodeDebugParam.CodePopupKey2) {
2156     CtrlKeyState = 0;
2157     break;
2158     }
2159     if (now - CtrlKeyDownTick < 500 && TipWinCodeDebug == NULL) {
2160     POINT pos;
2161     GetCursorPos(&pos);
2162     ScreenToClient(m_hWnd, &pos);
2163     CodePopup(pos.x, pos.y);
2164     CtrlKeyState = 3;
2165     } else {
2166     CtrlKeyDownTick = now;
2167     CtrlKeyState = 1;
2168     }
2169     break;
2170     case 3:
2171     break;
2172     default:
2173     CtrlKeyState = 0;
2174     break;
2175     }
2176     }
2177     if (TipWinCodeDebug != NULL && nChar == VK_SHIFT) {
2178     POINT pos;
2179     GetCursorPos(&pos);
2180     ScreenToClient(m_hWnd, &pos);
2181     wchar_t *buf = BuffGetCharInfo(pos.x, pos.y);
2182     CBSetTextW(HVTWin, buf, 0);
2183     free(buf);
2184     }
2185     #endif
2186 maya 3227 switch (KeyDown(HVTWin,nChar,nRepCnt,nFlags & 0x1ff)) {
2187     case KEYDOWN_OTHER:
2188     break;
2189     case KEYDOWN_CONTROL:
2190     return;
2191     case KEYDOWN_COMMOUT:
2192 doda 6421 // �X�N���[�����u�����Z�b�g
2193     if (WinOrgY != 0) {
2194 maya 3227 DispVScroll(SCROLL_BOTTOM, 0);
2195     }
2196     return;
2197     }
2198    
2199 doda 4519 if (MetaKey(ts.MetaKey) && (nFlags & 0x2000) != 0)
2200 doda 4414 {
2201 doda 4712 PeekMessage((LPMSG)&M,HVTWin,WM_CHAR,WM_CHAR,PM_REMOVE);
2202 maya 3227 /* for Ctrl+Alt+Key combination */
2203     GetKeyboardState((PBYTE)KeyState);
2204     KeyState[VK_MENU] = 0;
2205     SetKeyboardState((PBYTE)KeyState);
2206     M.hwnd = HVTWin;
2207     M.message = WM_KEYDOWN;
2208     M.wParam = nChar;
2209     M.lParam = MAKELONG(nRepCnt,nFlags & 0xdfff);
2210     TranslateMessage(&M);
2211     }
2212    
2213     }
2214    
2215 zmatsuo 8337 void CVTWindow::OnKeyUp(WPARAM nChar, UINT nRepCnt, UINT nFlags)
2216 maya 3227 {
2217     KeyUp(nChar);
2218 doda 8445 #if UNICODE_DEBUG
2219     if (CtrlKeyState == 1 && nChar == UnicodeDebugParam.CodePopupKey1) {
2220     CtrlKeyState++;
2221     } else {
2222     CtrlKeyState = 0;
2223     }
2224     if (nChar == UnicodeDebugParam.CodePopupKey2) {
2225     if (TipWinCodeDebug != NULL) {
2226     TipWinDestroy(TipWinCodeDebug);
2227     TipWinCodeDebug = NULL;
2228     CtrlKeyState = 0;
2229     }
2230     }
2231     #endif
2232 maya 3227 }
2233    
2234 zmatsuo 7528 void CVTWindow::OnKillFocus(HWND hNewWnd)
2235 maya 3227 {
2236     DispDestroyCaret();
2237     FocusReport(FALSE);
2238 zmatsuo 7784 // TTCFrameWnd::OnKillFocus(hNewWnd); // TODO
2239 maya 3227
2240 maya 3392 if (IsCaretOn()) {
2241 maya 3227 CaretKillFocus(TRUE);
2242 maya 3392 }
2243 maya 3227 }
2244    
2245 zmatsuo 8337 void CVTWindow::OnLButtonDblClk(WPARAM nFlags, POINTS point)
2246 maya 3227 {
2247 maya 3392 if (LButton || MButton || RButton) {
2248 maya 3227 return;
2249 maya 3392 }
2250 maya 3227
2251     DblClkX = point.x;
2252     DblClkY = point.y;
2253    
2254 doda 3992 if (MouseReport(IdMouseEventBtnDown, IdLeftButton, DblClkX, DblClkY)) {
2255 maya 3227 return;
2256 maya 3392 }
2257 maya 3227
2258 doda 3992 if (BuffUrlDblClk(DblClkX, DblClkY)) { // �u���E�U�����o���������������������B (2005.4.3 yutaka)
2259     return;
2260     }
2261    
2262 maya 3227 BuffDblClk(DblClkX, DblClkY);
2263    
2264     LButton = TRUE;
2265     DblClk = TRUE;
2266     AfterDblClk = TRUE;
2267     ::SetTimer(HVTWin, IdDblClkTimer, GetDoubleClickTime(), NULL);
2268    
2269     /* for AutoScrolling */
2270     ::SetCapture(HVTWin);
2271     ::SetTimer(HVTWin, IdScrollTimer, 100, NULL);
2272     }
2273    
2274 zmatsuo 8337 void CVTWindow::OnLButtonDown(WPARAM nFlags, POINTS point)
2275 maya 3227 {
2276     POINT p;
2277    
2278     p.x = point.x;
2279     p.y = point.y;
2280     ButtonDown(p,IdLeftButton);
2281     }
2282    
2283 zmatsuo 8337 void CVTWindow::OnLButtonUp(WPARAM nFlags, POINTS point)
2284 maya 3227 {
2285 doda 5341 if (IgnoreRelease)
2286     IgnoreRelease = FALSE;
2287 doda 7078 else if (MouseReport(IdMouseEventBtnUp, IdLeftButton, point.x, point.y)) {
2288     ReleaseCapture();
2289     }
2290 maya 3227
2291 maya 3392 if (! LButton) {
2292 maya 3227 return;
2293 maya 3392 }
2294 maya 3227
2295     ButtonUp(FALSE);
2296     }
2297    
2298 zmatsuo 8337 void CVTWindow::OnMButtonDown(WPARAM nFlags, POINTS point)
2299 maya 3227 {
2300     POINT p;
2301    
2302     p.x = point.x;
2303     p.y = point.y;
2304     ButtonDown(p,IdMiddleButton);
2305     }
2306    
2307 zmatsuo 8337 void CVTWindow::OnMButtonUp(WPARAM nFlags, POINTS point)
2308 maya 3227 {
2309 doda 5341 if (IgnoreRelease)
2310     IgnoreRelease = FALSE;
2311 doda 7078 else if (MouseReport(IdMouseEventBtnUp, IdMiddleButton, point.x, point.y)) {
2312     ReleaseCapture();
2313     }
2314 maya 3227
2315 maya 3392 if (! MButton) {
2316 maya 3227 return;
2317 maya 3392 }
2318 maya 3227
2319     // added DisablePasteMouseMButton (2008.3.2 maya)
2320 doda 7078 if (ts.PasteFlag & CPF_DISABLE_MBUTTON) {
2321 maya 3227 ButtonUp(FALSE);
2322 maya 3392 }
2323     else {
2324 maya 3227 ButtonUp(TRUE);
2325 maya 3392 }
2326 maya 3227 }
2327    
2328 zmatsuo 7528 int CVTWindow::OnMouseActivate(HWND pDesktopWnd, UINT nHitTest, UINT message)
2329 maya 3227 {
2330 doda 5341 if ((ts.SelOnActive==0) && (nHitTest==HTCLIENT)) { //disable mouse event for text selection
2331     IgnoreRelease = TRUE;
2332 maya 3227 return MA_ACTIVATEANDEAT; // when window is activated
2333 doda 5341 }
2334     else {
2335 maya 3227 return MA_ACTIVATE;
2336 doda 5341 }
2337 maya 3227 }
2338    
2339 doda 8445
2340     void CVTWindow::CodePopup(int client_x, int client_y)
2341     {
2342     wchar_t *buf = BuffGetCharInfo(client_x, client_y);
2343     if (TipWinCodeDebug == NULL) {
2344     TipWinCodeDebug = TipWinCreate(m_hInst, m_hWnd);
2345     }
2346     POINT pos = { client_x, client_y };
2347     ClientToScreen(m_hWnd, &pos);
2348     TipWinSetPos(TipWinCodeDebug, pos.x, pos.y);
2349     TipWinSetTextW(TipWinCodeDebug, buf);
2350     TipWinSetVisible(TipWinCodeDebug, TRUE);
2351     free(buf);
2352     }
2353    
2354 zmatsuo 8337 void CVTWindow::OnMouseMove(WPARAM nFlags, POINTS point)
2355 maya 3227 {
2356     int i;
2357 doda 3987 BOOL mousereport;
2358 maya 3227
2359 doda 8445 #if UNICODE_DEBUG
2360     if (TipWinCodeDebug != NULL) {
2361     CodePopup(point.x, point.y);
2362     }
2363     #endif
2364    
2365 doda 5341 if (!IgnoreRelease)
2366     mousereport = MouseReport(IdMouseEventMove, 0, point.x, point.y);
2367 doda 3987
2368 maya 3227 if (! (LButton || MButton || RButton)) {
2369 doda 5279 if (BuffCheckMouseOnURL(point.x, point.y))
2370     SetMouseCursor("HAND");
2371     else
2372     SetMouseCursor