| 1 |
maya |
3227 |
/* Tera Term |
| 2 |
|
|
Copyright(C) 1994-1998 T. Teranishi |
| 3 |
|
|
All rights reserved. */ |
| 4 |
|
|
|
| 5 |
|
|
/* TERATERM.EXE, main */ |
| 6 |
|
|
|
| 7 |
|
|
#include "stdafx.h" |
| 8 |
|
|
#include "teraterm.h" |
| 9 |
|
|
#include "tttypes.h" |
| 10 |
|
|
#include "commlib.h" |
| 11 |
|
|
#include "ttwinman.h" |
| 12 |
|
|
#include "buffer.h" |
| 13 |
|
|
#include "vtterm.h" |
| 14 |
|
|
#include "vtwin.h" |
| 15 |
|
|
#include "clipboar.h" |
| 16 |
|
|
#include "ttftypes.h" |
| 17 |
|
|
#include "filesys.h" |
| 18 |
|
|
#include "telnet.h" |
| 19 |
|
|
#include "tektypes.h" |
| 20 |
|
|
#include "tekwin.h" |
| 21 |
|
|
#include "ttdde.h" |
| 22 |
doda |
4414 |
#include "keyboard.h" |
| 23 |
maya |
3227 |
|
| 24 |
|
|
#include "teraapp.h" |
| 25 |
|
|
|
| 26 |
|
|
#include "compat_w95.h" |
| 27 |
|
|
|
| 28 |
|
|
#ifdef _DEBUG |
| 29 |
|
|
#define new DEBUG_NEW |
| 30 |
|
|
#undef THIS_FILE |
| 31 |
|
|
static char THIS_FILE[] = __FILE__; |
| 32 |
|
|
#endif |
| 33 |
|
|
|
| 34 |
|
|
BEGIN_MESSAGE_MAP(CTeraApp, CWinApp) |
| 35 |
|
|
//{{AFX_MSG_MAP(CTeraApp) |
| 36 |
|
|
//}}AFX_MSG_MAP |
| 37 |
|
|
END_MESSAGE_MAP() |
| 38 |
|
|
|
| 39 |
|
|
CTeraApp::CTeraApp() |
| 40 |
|
|
{ |
| 41 |
doda |
6793 |
typedef BOOL (WINAPI *pSetDllDir)(LPCSTR); |
| 42 |
|
|
typedef BOOL (WINAPI *pSetDefDllDir)(DWORD); |
| 43 |
|
|
|
| 44 |
|
|
HMODULE module; |
| 45 |
|
|
pSetDllDir setDllDir; |
| 46 |
|
|
pSetDefDllDir setDefDllDir; |
| 47 |
|
|
|
| 48 |
|
|
if ((module = GetModuleHandle("kernel32.dll")) != NULL) { |
| 49 |
|
|
if ((setDefDllDir = (pSetDefDllDir)GetProcAddress(module, "SetDefaultDllDirectories")) != NULL) { |
| 50 |
|
|
// SetDefaultDllDirectories() ���g�����������A�����p�X�� %WINDOWS%\system32 �������������� |
| 51 |
|
|
(*setDefDllDir)((DWORD)0x00000800); // LOAD_LIBRARY_SEARCH_SYSTEM32 |
| 52 |
|
|
} |
| 53 |
|
|
else if ((setDllDir = (pSetDllDir)GetProcAddress(module, "SetDllDirectoryA")) != NULL) { |
| 54 |
|
|
// SetDefaultDllDirectories() ���g�����������ASetDllDirectory() ���g���������� |
| 55 |
|
|
// �J�����g�f�B���N�g���������������p�X�����������������B |
| 56 |
|
|
(*setDllDir)(""); |
| 57 |
|
|
} |
| 58 |
|
|
} |
| 59 |
maya |
3227 |
} |
| 60 |
|
|
|
| 61 |
|
|
// CTeraApp instance |
| 62 |
|
|
CTeraApp theApp; |
| 63 |
|
|
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
|
| 67 |
|
|
|
| 68 |
|
|
// CTeraApp initialization |
| 69 |
|
|
BOOL CTeraApp::InitInstance() |
| 70 |
|
|
{ |
| 71 |
maya |
3392 |
hInst = m_hInstance; |
| 72 |
|
|
m_pMainWnd = new CVTWindow(); |
| 73 |
|
|
pVTWin = m_pMainWnd; |
| 74 |
|
|
return TRUE; |
| 75 |
maya |
3227 |
} |
| 76 |
|
|
|
| 77 |
|
|
int CTeraApp::ExitInstance() |
| 78 |
|
|
{ |
| 79 |
maya |
3392 |
return CWinApp::ExitInstance(); |
| 80 |
maya |
3227 |
} |
| 81 |
|
|
|
| 82 |
|
|
// Tera Term main engine |
| 83 |
|
|
BOOL CTeraApp::OnIdle(LONG lCount) |
| 84 |
|
|
{ |
| 85 |
|
|
static int Busy = 2; |
| 86 |
|
|
int Change, nx, ny; |
| 87 |
|
|
BOOL Size; |
| 88 |
|
|
|
| 89 |
|
|
if (lCount==0) Busy = 2; |
| 90 |
|
|
|
| 91 |
|
|
if (cv.Ready) |
| 92 |
|
|
{ |
| 93 |
|
|
/* Sender */ |
| 94 |
|
|
CommSend(&cv); |
| 95 |
|
|
|
| 96 |
|
|
/* Parser */ |
| 97 |
|
|
if ((cv.HLogBuf!=NULL) && (cv.LogBuf==NULL)) |
| 98 |
|
|
cv.LogBuf = (PCHAR)GlobalLock(cv.HLogBuf); |
| 99 |
|
|
|
| 100 |
|
|
if ((cv.HBinBuf!=NULL) && (cv.BinBuf==NULL)) |
| 101 |
|
|
cv.BinBuf = (PCHAR)GlobalLock(cv.HBinBuf); |
| 102 |
|
|
|
| 103 |
|
|
if ((TelStatus==TelIdle) && cv.TelMode) |
| 104 |
|
|
TelStatus = TelIAC; |
| 105 |
|
|
|
| 106 |
|
|
if (TelStatus != TelIdle) |
| 107 |
|
|
{ |
| 108 |
|
|
ParseTel(&Size,&nx,&ny); |
| 109 |
|
|
if (Size) { |
| 110 |
|
|
LockBuffer(); |
| 111 |
|
|
ChangeTerminalSize(nx,ny); |
| 112 |
|
|
UnlockBuffer(); |
| 113 |
|
|
} |
| 114 |
|
|
} |
| 115 |
|
|
else { |
| 116 |
|
|
if (cv.ProtoFlag) Change = ProtoDlgParse(); |
| 117 |
|
|
else { |
| 118 |
|
|
switch (ActiveWin) { |
| 119 |
doda |
6435 |
case IdVT: |
| 120 |
|
|
Change = ((CVTWindow*)pVTWin)->Parse(); |
| 121 |
maya |
3227 |
// TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������ |
| 122 |
|
|
// ���������b�������B(2006.2.6 yutaka) |
| 123 |
|
|
// �����������������A�R���e�L�X�g�X�C�b�`�����������B(2006.3.20 yutaka) |
| 124 |
|
|
Sleep(0); |
| 125 |
|
|
break; |
| 126 |
|
|
|
| 127 |
|
|
case IdTEK: |
| 128 |
|
|
if (pTEKWin != NULL) { |
| 129 |
|
|
Change = ((CTEKWindow*)pTEKWin)->Parse(); |
| 130 |
|
|
// TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������ |
| 131 |
|
|
// ���������b�������B(2006.2.6 yutaka) |
| 132 |
|
|
Sleep(1); |
| 133 |
|
|
} |
| 134 |
maya |
3392 |
else { |
| 135 |
maya |
3227 |
Change = IdVT; |
| 136 |
maya |
3392 |
} |
| 137 |
maya |
3227 |
break; |
| 138 |
|
|
|
| 139 |
|
|
default: |
| 140 |
|
|
Change = 0; |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
switch (Change) { |
| 144 |
maya |
3392 |
case IdVT: |
| 145 |
|
|
VTActivate(); |
| 146 |
|
|
break; |
| 147 |
|
|
case IdTEK: |
| 148 |
|
|
((CVTWindow*)pVTWin)->OpenTEK(); |
| 149 |
|
|
break; |
| 150 |
maya |
3227 |
} |
| 151 |
|
|
} |
| 152 |
|
|
} |
| 153 |
|
|
|
| 154 |
|
|
if (cv.LogBuf!=NULL) |
| 155 |
|
|
{ |
| 156 |
maya |
3392 |
if (FileLog) { |
| 157 |
|
|
LogToFile(); |
| 158 |
|
|
} |
| 159 |
|
|
if (DDELog && AdvFlag) { |
| 160 |
|
|
DDEAdv(); |
| 161 |
|
|
} |
| 162 |
maya |
3227 |
GlobalUnlock(cv.HLogBuf); |
| 163 |
|
|
cv.LogBuf = NULL; |
| 164 |
|
|
} |
| 165 |
|
|
|
| 166 |
|
|
if (cv.BinBuf!=NULL) |
| 167 |
|
|
{ |
| 168 |
maya |
3392 |
if (BinLog) { |
| 169 |
|
|
LogToFile(); |
| 170 |
|
|
} |
| 171 |
maya |
3227 |
GlobalUnlock(cv.HBinBuf); |
| 172 |
|
|
cv.BinBuf = NULL; |
| 173 |
|
|
} |
| 174 |
|
|
|
| 175 |
|
|
/* Talker */ |
| 176 |
|
|
switch (TalkStatus) { |
| 177 |
maya |
3392 |
case IdTalkCB: |
| 178 |
|
|
CBSend(); |
| 179 |
|
|
break; /* clip board */ |
| 180 |
|
|
case IdTalkFile: |
| 181 |
|
|
FileSend(); |
| 182 |
|
|
break; /* file */ |
| 183 |
maya |
3227 |
} |
| 184 |
|
|
|
| 185 |
|
|
/* Receiver */ |
| 186 |
|
|
if (DDELog && cv.DCount >0) { |
| 187 |
|
|
// ���O�o�b�t�@������DDE�N���C�A���g�����������������������A |
| 188 |
|
|
// TCP�p�P�b�g�����M���s�������B |
| 189 |
|
|
// �A���������M���s�����A���O�o�b�t�@�����E���h���r�������������M���f�[�^�� |
| 190 |
|
|
// �������������������\���������B(2007.6.14 yutaka) |
| 191 |
|
|
|
| 192 |
|
|
} else { |
| 193 |
|
|
CommReceive(&cv); |
| 194 |
|
|
} |
| 195 |
|
|
|
| 196 |
|
|
} |
| 197 |
|
|
|
| 198 |
|
|
if (cv.Ready && |
| 199 |
doda |
3494 |
(cv.RRQ || (cv.OutBuffCount>0) || (cv.InBuffCount>0) || (cv.FlushLen>0) || (cv.LCount>0) || (cv.BCount>0) || (cv.DCount>0)) ) { |
| 200 |
maya |
3227 |
Busy = 2; |
| 201 |
maya |
3392 |
} |
| 202 |
|
|
else { |
| 203 |
maya |
3227 |
Busy--; |
| 204 |
maya |
3392 |
} |
| 205 |
maya |
3227 |
|
| 206 |
|
|
return (Busy>0); |
| 207 |
|
|
} |
| 208 |
|
|
|
| 209 |
|
|
BOOL CTeraApp::PreTranslateMessage(MSG* pMsg) |
| 210 |
|
|
{ |
| 211 |
doda |
4414 |
if (MetaKey(ts.MetaKey)) { |
| 212 |
maya |
3392 |
return FALSE; /* ignore accelerator keys */ |
| 213 |
|
|
} |
| 214 |
|
|
else { |
| 215 |
|
|
return CWinApp::PreTranslateMessage(pMsg); |
| 216 |
|
|
} |
| 217 |
maya |
3227 |
} |