| 1 |
doda |
6806 |
/* |
| 2 |
|
|
* Copyright (C) 1994-1998 T. Teranishi |
| 3 |
zmatsuo |
7528 |
* (C) 2006-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 |
|
| 30 |
|
|
/* TERATERM.EXE, main */ |
| 31 |
|
|
|
| 32 |
zmatsuo |
7528 |
#include <crtdbg.h> |
| 33 |
|
|
#include <tchar.h> |
| 34 |
maya |
3227 |
#include "teraterm.h" |
| 35 |
|
|
#include "tttypes.h" |
| 36 |
|
|
#include "commlib.h" |
| 37 |
|
|
#include "ttwinman.h" |
| 38 |
|
|
#include "buffer.h" |
| 39 |
|
|
#include "vtterm.h" |
| 40 |
|
|
#include "vtwin.h" |
| 41 |
|
|
#include "clipboar.h" |
| 42 |
|
|
#include "ttftypes.h" |
| 43 |
|
|
#include "filesys.h" |
| 44 |
|
|
#include "telnet.h" |
| 45 |
|
|
#include "tektypes.h" |
| 46 |
|
|
#include "tekwin.h" |
| 47 |
|
|
#include "ttdde.h" |
| 48 |
doda |
4414 |
#include "keyboard.h" |
| 49 |
zmatsuo |
7457 |
#include "dllutil.h" |
| 50 |
|
|
#include "compat_win.h" |
| 51 |
maya |
3227 |
#include "compat_w95.h" |
| 52 |
zmatsuo |
7509 |
#include "dlglib.h" |
| 53 |
zmatsuo |
7528 |
#include "teraterml.h" |
| 54 |
maya |
3227 |
|
| 55 |
zmatsuo |
7457 |
#if 0 |
| 56 |
|
|
//#ifdef _DEBUG |
| 57 |
|
|
//#define new DEBUG_NEW |
| 58 |
|
|
//#undef THIS_FILE |
| 59 |
|
|
//static char THIS_FILE[] = __FILE__; |
| 60 |
|
|
#define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__) |
| 61 |
maya |
3227 |
#endif |
| 62 |
|
|
|
| 63 |
zmatsuo |
7457 |
static BOOL AddFontFlag; |
| 64 |
|
|
static TCHAR TSpecialFont[MAX_PATH]; |
| 65 |
|
|
|
| 66 |
|
|
static void LoadSpecialFont() |
| 67 |
|
|
{ |
| 68 |
zmatsuo |
7509 |
if (!IsExistFontA("Tera Special", SYMBOL_CHARSET, TRUE)) { |
| 69 |
zmatsuo |
7457 |
int r; |
| 70 |
|
|
|
| 71 |
|
|
if (GetModuleFileName(NULL, TSpecialFont,_countof(TSpecialFont)) == 0) { |
| 72 |
|
|
AddFontFlag = FALSE; |
| 73 |
|
|
return; |
| 74 |
doda |
6793 |
} |
| 75 |
zmatsuo |
7457 |
*_tcsrchr(TSpecialFont, _T('\\')) = 0; |
| 76 |
|
|
_tcscat_s(TSpecialFont, _T("\\TSPECIAL1.TTF")); |
| 77 |
|
|
|
| 78 |
|
|
if (pAddFontResourceEx != NULL) { |
| 79 |
|
|
// teraterm.exe�������L�����t�H���g�������B |
| 80 |
|
|
// remove�����������I��������OS������������ |
| 81 |
|
|
r = pAddFontResourceEx(TSpecialFont, FR_PRIVATE, NULL); |
| 82 |
|
|
} else { |
| 83 |
|
|
// �V�X�e���S�����g�����t�H���g������ |
| 84 |
|
|
// remove��������OS������������������ |
| 85 |
|
|
r = AddFontResource(TSpecialFont); |
| 86 |
doda |
6793 |
} |
| 87 |
zmatsuo |
7457 |
if (r != 0) { |
| 88 |
|
|
AddFontFlag = TRUE; |
| 89 |
|
|
} |
| 90 |
doda |
6793 |
} |
| 91 |
maya |
3227 |
} |
| 92 |
|
|
|
| 93 |
zmatsuo |
7457 |
static void UnloadSpecialFont() |
| 94 |
|
|
{ |
| 95 |
|
|
if (AddFontFlag) { |
| 96 |
|
|
if (pRemoveFontResourceEx != NULL) { |
| 97 |
|
|
pRemoveFontResourceEx(TSpecialFont, FR_PRIVATE, NULL); |
| 98 |
|
|
} else { |
| 99 |
|
|
RemoveFontResource(TSpecialFont); |
| 100 |
|
|
} |
| 101 |
|
|
} |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
zmatsuo |
7509 |
static void init() |
| 105 |
zmatsuo |
7457 |
{ |
| 106 |
|
|
#ifdef _DEBUG |
| 107 |
|
|
::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); |
| 108 |
|
|
#endif |
| 109 |
|
|
DLLInit(); |
| 110 |
|
|
WinCompatInit(); |
| 111 |
zmatsuo |
7510 |
#if defined(DPIAWARENESS) |
| 112 |
zmatsuo |
7509 |
if (pSetThreadDpiAwarenessContext) { |
| 113 |
|
|
pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); |
| 114 |
|
|
} |
| 115 |
|
|
#endif |
| 116 |
|
|
LoadSpecialFont(); |
| 117 |
zmatsuo |
7457 |
} |
| 118 |
|
|
|
| 119 |
maya |
3227 |
// Tera Term main engine |
| 120 |
zmatsuo |
7528 |
static BOOL OnIdle(LONG lCount) |
| 121 |
maya |
3227 |
{ |
| 122 |
|
|
static int Busy = 2; |
| 123 |
|
|
int Change, nx, ny; |
| 124 |
|
|
BOOL Size; |
| 125 |
|
|
|
| 126 |
|
|
if (lCount==0) Busy = 2; |
| 127 |
|
|
|
| 128 |
|
|
if (cv.Ready) |
| 129 |
|
|
{ |
| 130 |
|
|
/* Sender */ |
| 131 |
|
|
CommSend(&cv); |
| 132 |
|
|
|
| 133 |
|
|
/* Parser */ |
| 134 |
|
|
if ((cv.HLogBuf!=NULL) && (cv.LogBuf==NULL)) |
| 135 |
|
|
cv.LogBuf = (PCHAR)GlobalLock(cv.HLogBuf); |
| 136 |
|
|
|
| 137 |
|
|
if ((cv.HBinBuf!=NULL) && (cv.BinBuf==NULL)) |
| 138 |
|
|
cv.BinBuf = (PCHAR)GlobalLock(cv.HBinBuf); |
| 139 |
|
|
|
| 140 |
|
|
if ((TelStatus==TelIdle) && cv.TelMode) |
| 141 |
|
|
TelStatus = TelIAC; |
| 142 |
|
|
|
| 143 |
|
|
if (TelStatus != TelIdle) |
| 144 |
|
|
{ |
| 145 |
|
|
ParseTel(&Size,&nx,&ny); |
| 146 |
|
|
if (Size) { |
| 147 |
|
|
LockBuffer(); |
| 148 |
|
|
ChangeTerminalSize(nx,ny); |
| 149 |
|
|
UnlockBuffer(); |
| 150 |
|
|
} |
| 151 |
|
|
} |
| 152 |
|
|
else { |
| 153 |
|
|
if (cv.ProtoFlag) Change = ProtoDlgParse(); |
| 154 |
|
|
else { |
| 155 |
|
|
switch (ActiveWin) { |
| 156 |
doda |
6435 |
case IdVT: |
| 157 |
|
|
Change = ((CVTWindow*)pVTWin)->Parse(); |
| 158 |
maya |
3227 |
// TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������ |
| 159 |
|
|
// ���������b�������B(2006.2.6 yutaka) |
| 160 |
|
|
// �����������������A�R���e�L�X�g�X�C�b�`�����������B(2006.3.20 yutaka) |
| 161 |
|
|
Sleep(0); |
| 162 |
|
|
break; |
| 163 |
|
|
|
| 164 |
|
|
case IdTEK: |
| 165 |
|
|
if (pTEKWin != NULL) { |
| 166 |
|
|
Change = ((CTEKWindow*)pTEKWin)->Parse(); |
| 167 |
|
|
// TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������ |
| 168 |
|
|
// ���������b�������B(2006.2.6 yutaka) |
| 169 |
|
|
Sleep(1); |
| 170 |
|
|
} |
| 171 |
maya |
3392 |
else { |
| 172 |
maya |
3227 |
Change = IdVT; |
| 173 |
maya |
3392 |
} |
| 174 |
maya |
3227 |
break; |
| 175 |
|
|
|
| 176 |
|
|
default: |
| 177 |
|
|
Change = 0; |
| 178 |
|
|
} |
| 179 |
|
|
|
| 180 |
|
|
switch (Change) { |
| 181 |
maya |
3392 |
case IdVT: |
| 182 |
|
|
VTActivate(); |
| 183 |
|
|
break; |
| 184 |
|
|
case IdTEK: |
| 185 |
|
|
((CVTWindow*)pVTWin)->OpenTEK(); |
| 186 |
|
|
break; |
| 187 |
maya |
3227 |
} |
| 188 |
|
|
} |
| 189 |
|
|
} |
| 190 |
|
|
|
| 191 |
|
|
if (cv.LogBuf!=NULL) |
| 192 |
|
|
{ |
| 193 |
maya |
3392 |
if (FileLog) { |
| 194 |
|
|
LogToFile(); |
| 195 |
|
|
} |
| 196 |
|
|
if (DDELog && AdvFlag) { |
| 197 |
|
|
DDEAdv(); |
| 198 |
|
|
} |
| 199 |
maya |
3227 |
GlobalUnlock(cv.HLogBuf); |
| 200 |
|
|
cv.LogBuf = NULL; |
| 201 |
|
|
} |
| 202 |
|
|
|
| 203 |
|
|
if (cv.BinBuf!=NULL) |
| 204 |
|
|
{ |
| 205 |
maya |
3392 |
if (BinLog) { |
| 206 |
|
|
LogToFile(); |
| 207 |
|
|
} |
| 208 |
maya |
3227 |
GlobalUnlock(cv.HBinBuf); |
| 209 |
|
|
cv.BinBuf = NULL; |
| 210 |
|
|
} |
| 211 |
|
|
|
| 212 |
|
|
/* Talker */ |
| 213 |
|
|
switch (TalkStatus) { |
| 214 |
maya |
3392 |
case IdTalkCB: |
| 215 |
|
|
CBSend(); |
| 216 |
|
|
break; /* clip board */ |
| 217 |
|
|
case IdTalkFile: |
| 218 |
|
|
FileSend(); |
| 219 |
|
|
break; /* file */ |
| 220 |
maya |
3227 |
} |
| 221 |
|
|
|
| 222 |
|
|
/* Receiver */ |
| 223 |
|
|
if (DDELog && cv.DCount >0) { |
| 224 |
|
|
// ���O�o�b�t�@������DDE�N���C�A���g�����������������������A |
| 225 |
|
|
// TCP�p�P�b�g�����M���s�������B |
| 226 |
|
|
// �A���������M���s�����A���O�o�b�t�@�����E���h���r�������������M���f�[�^�� |
| 227 |
|
|
// �������������������\���������B(2007.6.14 yutaka) |
| 228 |
|
|
|
| 229 |
|
|
} else { |
| 230 |
|
|
CommReceive(&cv); |
| 231 |
|
|
} |
| 232 |
|
|
|
| 233 |
|
|
} |
| 234 |
|
|
|
| 235 |
|
|
if (cv.Ready && |
| 236 |
doda |
3494 |
(cv.RRQ || (cv.OutBuffCount>0) || (cv.InBuffCount>0) || (cv.FlushLen>0) || (cv.LCount>0) || (cv.BCount>0) || (cv.DCount>0)) ) { |
| 237 |
maya |
3227 |
Busy = 2; |
| 238 |
maya |
3392 |
} |
| 239 |
|
|
else { |
| 240 |
maya |
3227 |
Busy--; |
| 241 |
maya |
3392 |
} |
| 242 |
maya |
3227 |
|
| 243 |
|
|
return (Busy>0); |
| 244 |
|
|
} |
| 245 |
|
|
|
| 246 |
zmatsuo |
7528 |
BOOL CallOnIdle(LONG lCount) |
| 247 |
maya |
3227 |
{ |
| 248 |
zmatsuo |
7528 |
return OnIdle(lCount); |
| 249 |
|
|
} |
| 250 |
|
|
|
| 251 |
|
|
HINSTANCE GetInstance() |
| 252 |
|
|
{ |
| 253 |
|
|
return hInst; |
| 254 |
|
|
} |
| 255 |
|
|
|
| 256 |
|
|
static HWND main_window; |
| 257 |
|
|
HWND GetHWND() |
| 258 |
|
|
{ |
| 259 |
|
|
return main_window; |
| 260 |
|
|
} |
| 261 |
|
|
|
| 262 |
|
|
static HWND hModalWnd; |
| 263 |
|
|
|
| 264 |
|
|
void AddModalHandle(HWND hWnd) |
| 265 |
|
|
{ |
| 266 |
|
|
hModalWnd = hWnd; |
| 267 |
|
|
} |
| 268 |
|
|
|
| 269 |
|
|
void RemoveModalHandle(HWND hWnd) |
| 270 |
|
|
{ |
| 271 |
|
|
hModalWnd = 0; |
| 272 |
|
|
} |
| 273 |
|
|
|
| 274 |
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, |
| 275 |
|
|
LPSTR lpszCmdLine, int nCmdShow) |
| 276 |
|
|
{ |
| 277 |
|
|
#ifdef _DEBUG |
| 278 |
|
|
::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); |
| 279 |
|
|
#endif |
| 280 |
|
|
|
| 281 |
|
|
LONG lCount = 0; |
| 282 |
|
|
DWORD SleepTick = 1; |
| 283 |
|
|
init(); |
| 284 |
|
|
hInst = hInstance; |
| 285 |
|
|
CVTWindow *m_pMainWnd = new CVTWindow(); |
| 286 |
|
|
pVTWin = m_pMainWnd; |
| 287 |
|
|
main_window = m_pMainWnd->m_hWnd; |
| 288 |
|
|
// [Tera Term]�Z�N�V������DlgFont=������������ |
| 289 |
|
|
// [TTSSH]�Z�N�V�������t�H���g�������g�p���� |
| 290 |
|
|
SetDialogFont(ts.SetupFName, ts.UILanguageFile, "TTSSH"); |
| 291 |
|
|
|
| 292 |
|
|
MSG msg; |
| 293 |
|
|
while (GetMessage(&msg, NULL, 0, 0)) { |
| 294 |
|
|
if (hModalWnd != 0) { |
| 295 |
|
|
if (IsDialogMessage(hModalWnd, &msg)) { |
| 296 |
|
|
continue; |
| 297 |
|
|
} |
| 298 |
|
|
} |
| 299 |
|
|
|
| 300 |
|
|
bool message_processed = false; |
| 301 |
|
|
|
| 302 |
|
|
if (m_pMainWnd->m_hAccel != NULL) { |
| 303 |
|
|
if (!MetaKey(ts.MetaKey)) { |
| 304 |
|
|
// matakey���������������� |
| 305 |
|
|
if (TranslateAccelerator(m_pMainWnd->m_hWnd , m_pMainWnd->m_hAccel, &msg)) { |
| 306 |
|
|
// �A�N�Z�����[�^�[�L�[���������� |
| 307 |
|
|
message_processed = true; |
| 308 |
|
|
} |
| 309 |
|
|
} |
| 310 |
|
|
} |
| 311 |
|
|
|
| 312 |
|
|
if (!message_processed) { |
| 313 |
|
|
TranslateMessage(&msg); |
| 314 |
|
|
DispatchMessage(&msg); |
| 315 |
|
|
} |
| 316 |
|
|
|
| 317 |
|
|
while (!PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) { |
| 318 |
|
|
// ���b�Z�[�W������ |
| 319 |
|
|
if (!OnIdle(lCount)) { |
| 320 |
|
|
// idle�s�v |
| 321 |
|
|
if (SleepTick < 500) { // ���� 501ms���� |
| 322 |
|
|
SleepTick += 2; |
| 323 |
|
|
} |
| 324 |
|
|
lCount = 0; |
| 325 |
|
|
Sleep(SleepTick); |
| 326 |
|
|
} else { |
| 327 |
|
|
// �vidle |
| 328 |
|
|
SleepTick = 0; |
| 329 |
|
|
lCount++; |
| 330 |
|
|
} |
| 331 |
|
|
} |
| 332 |
maya |
3392 |
} |
| 333 |
zmatsuo |
7528 |
delete m_pMainWnd; |
| 334 |
|
|
m_pMainWnd = NULL; |
| 335 |
|
|
|
| 336 |
|
|
UnloadSpecialFont(); |
| 337 |
|
|
DLLExit(); |
| 338 |
|
|
|
| 339 |
|
|
return msg.wParam; |
| 340 |
maya |
3227 |
} |