Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7545 - (hide annotations) (download) (as text)
Tue Apr 2 16:26:49 2019 UTC (5 years ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/teraterm.cpp
File MIME type: text/x-c++src
File size: 8054 byte(s)
vtwin DPIを見て表示倍率を変更する
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 7545 //SetProcessDPIAware();
113     if (pSetThreadDpiAwarenessContext != NULL) {
114     // Windows 10 Version 1703���~������?
115 zmatsuo 7509 pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
116     }
117     #endif
118     LoadSpecialFont();
119 zmatsuo 7457 }
120    
121 maya 3227 // Tera Term main engine
122 zmatsuo 7528 static BOOL OnIdle(LONG lCount)
123 maya 3227 {
124     static int Busy = 2;
125     int Change, nx, ny;
126     BOOL Size;
127    
128     if (lCount==0) Busy = 2;
129    
130     if (cv.Ready)
131     {
132     /* Sender */
133     CommSend(&cv);
134    
135     /* Parser */
136     if ((cv.HLogBuf!=NULL) && (cv.LogBuf==NULL))
137     cv.LogBuf = (PCHAR)GlobalLock(cv.HLogBuf);
138    
139     if ((cv.HBinBuf!=NULL) && (cv.BinBuf==NULL))
140     cv.BinBuf = (PCHAR)GlobalLock(cv.HBinBuf);
141    
142     if ((TelStatus==TelIdle) && cv.TelMode)
143     TelStatus = TelIAC;
144    
145     if (TelStatus != TelIdle)
146     {
147     ParseTel(&Size,&nx,&ny);
148     if (Size) {
149     LockBuffer();
150     ChangeTerminalSize(nx,ny);
151     UnlockBuffer();
152     }
153     }
154     else {
155     if (cv.ProtoFlag) Change = ProtoDlgParse();
156     else {
157     switch (ActiveWin) {
158 doda 6435 case IdVT:
159     Change = ((CVTWindow*)pVTWin)->Parse();
160 maya 3227 // TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������
161     // ���������b�������B(2006.2.6 yutaka)
162     // �����������������A�R���e�L�X�g�X�C�b�`�����������B(2006.3.20 yutaka)
163     Sleep(0);
164     break;
165    
166     case IdTEK:
167     if (pTEKWin != NULL) {
168     Change = ((CTEKWindow*)pTEKWin)->Parse();
169     // TEK window���A�N�e�B�u���� pause ���g�����ACPU�g�p��100%������
170     // ���������b�������B(2006.2.6 yutaka)
171     Sleep(1);
172     }
173 maya 3392 else {
174 maya 3227 Change = IdVT;
175 maya 3392 }
176 maya 3227 break;
177    
178     default:
179     Change = 0;
180     }
181    
182     switch (Change) {
183 maya 3392 case IdVT:
184     VTActivate();
185     break;
186     case IdTEK:
187     ((CVTWindow*)pVTWin)->OpenTEK();
188     break;
189 maya 3227 }
190     }
191     }
192    
193     if (cv.LogBuf!=NULL)
194     {
195 maya 3392 if (FileLog) {
196     LogToFile();
197     }
198     if (DDELog && AdvFlag) {
199     DDEAdv();
200     }
201 maya 3227 GlobalUnlock(cv.HLogBuf);
202     cv.LogBuf = NULL;
203     }
204    
205     if (cv.BinBuf!=NULL)
206     {
207 maya 3392 if (BinLog) {
208     LogToFile();
209     }
210 maya 3227 GlobalUnlock(cv.HBinBuf);
211     cv.BinBuf = NULL;
212     }
213    
214     /* Talker */
215     switch (TalkStatus) {
216 maya 3392 case IdTalkCB:
217     CBSend();
218     break; /* clip board */
219     case IdTalkFile:
220     FileSend();
221     break; /* file */
222 maya 3227 }
223    
224     /* Receiver */
225     if (DDELog && cv.DCount >0) {
226     // ���O�o�b�t�@������DDE�N���C�A���g�����������������������A
227     // TCP�p�P�b�g�����M���s�������B
228     // �A���������M���s�����A���O�o�b�t�@�����E���h���r�������������M���f�[�^��
229     // �������������������\���������B(2007.6.14 yutaka)
230    
231     } else {
232     CommReceive(&cv);
233     }
234    
235     }
236    
237     if (cv.Ready &&
238 doda 3494 (cv.RRQ || (cv.OutBuffCount>0) || (cv.InBuffCount>0) || (cv.FlushLen>0) || (cv.LCount>0) || (cv.BCount>0) || (cv.DCount>0)) ) {
239 maya 3227 Busy = 2;
240 maya 3392 }
241     else {
242 maya 3227 Busy--;
243 maya 3392 }
244 maya 3227
245     return (Busy>0);
246     }
247    
248 zmatsuo 7528 BOOL CallOnIdle(LONG lCount)
249 maya 3227 {
250 zmatsuo 7528 return OnIdle(lCount);
251     }
252    
253     HINSTANCE GetInstance()
254     {
255     return hInst;
256     }
257    
258     static HWND main_window;
259     HWND GetHWND()
260     {
261     return main_window;
262     }
263    
264     static HWND hModalWnd;
265    
266     void AddModalHandle(HWND hWnd)
267     {
268     hModalWnd = hWnd;
269     }
270    
271     void RemoveModalHandle(HWND hWnd)
272     {
273     hModalWnd = 0;
274     }
275    
276     int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst,
277     LPSTR lpszCmdLine, int nCmdShow)
278     {
279     #ifdef _DEBUG
280     ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
281     #endif
282    
283     LONG lCount = 0;
284     DWORD SleepTick = 1;
285     init();
286     hInst = hInstance;
287     CVTWindow *m_pMainWnd = new CVTWindow();
288     pVTWin = m_pMainWnd;
289     main_window = m_pMainWnd->m_hWnd;
290     // [Tera Term]�Z�N�V������DlgFont=������������
291     // [TTSSH]�Z�N�V�������t�H���g�������g�p����
292     SetDialogFont(ts.SetupFName, ts.UILanguageFile, "TTSSH");
293    
294     MSG msg;
295     while (GetMessage(&msg, NULL, 0, 0)) {
296     if (hModalWnd != 0) {
297     if (IsDialogMessage(hModalWnd, &msg)) {
298     continue;
299     }
300     }
301    
302     bool message_processed = false;
303    
304     if (m_pMainWnd->m_hAccel != NULL) {
305     if (!MetaKey(ts.MetaKey)) {
306     // matakey����������������
307     if (TranslateAccelerator(m_pMainWnd->m_hWnd , m_pMainWnd->m_hAccel, &msg)) {
308     // �A�N�Z�����[�^�[�L�[����������
309     message_processed = true;
310     }
311     }
312     }
313    
314     if (!message_processed) {
315     TranslateMessage(&msg);
316     DispatchMessage(&msg);
317     }
318    
319     while (!PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) {
320     // ���b�Z�[�W������
321     if (!OnIdle(lCount)) {
322     // idle�s�v
323     if (SleepTick < 500) { // ���� 501ms����
324     SleepTick += 2;
325     }
326     lCount = 0;
327     Sleep(SleepTick);
328     } else {
329     // �vidle
330     SleepTick = 0;
331     lCount++;
332     }
333     }
334 maya 3392 }
335 zmatsuo 7528 delete m_pMainWnd;
336     m_pMainWnd = NULL;
337    
338     UnloadSpecialFont();
339     DLLExit();
340    
341     return msg.wParam;
342 maya 3227 }

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