| 1 |
/* |
| 2 |
* Copyright (C) S.Hayakawa NTT-IT 1998-2002 |
| 3 |
* (C) 2002- TeraTerm Project |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 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 |
* |
| 18 |
* 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 |
*/ |
| 29 |
|
| 30 |
#define STRICT |
| 31 |
#include "winmisc.h" |
| 32 |
|
| 33 |
|
| 34 |
/* ========================================================================== |
| 35 |
Function Name : (void) SetDlgPos() |
| 36 |
Outline : �_�C�A���O�����u���������� |
| 37 |
Arguments : HWND hWnd (in) �_�C�A���O���E�C���h�E�n���h�� |
| 38 |
: int pos (in) ���������������l |
| 39 |
Return Value : ���� |
| 40 |
Reference : |
| 41 |
Renewal : |
| 42 |
Notes : |
| 43 |
Attention : |
| 44 |
Up Date : |
| 45 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 46 |
void SetDlgPos(HWND hWnd, int pos) |
| 47 |
{ |
| 48 |
int x; |
| 49 |
int y; |
| 50 |
RECT rect; |
| 51 |
|
| 52 |
::GetWindowRect(hWnd, &rect); |
| 53 |
|
| 54 |
int cx = ::GetSystemMetrics(SM_CXFULLSCREEN); |
| 55 |
int cy = ::GetSystemMetrics(SM_CYFULLSCREEN); |
| 56 |
int xsize = rect.right - rect.left; |
| 57 |
int ysize = rect.bottom - rect.top; |
| 58 |
|
| 59 |
switch (pos) { |
| 60 |
case POSITION_LEFTTOP: |
| 61 |
x = 0; |
| 62 |
y = 0; |
| 63 |
break; |
| 64 |
case POSITION_LEFTBOTTOM: |
| 65 |
x = 0; |
| 66 |
y = cy - ysize; |
| 67 |
break; |
| 68 |
case POSITION_RIGHTTOP: |
| 69 |
x = cx - xsize; |
| 70 |
y = 0; |
| 71 |
break; |
| 72 |
case POSITION_RIGHTBOTTOM: |
| 73 |
x = cx - xsize; |
| 74 |
y = cy - ysize; |
| 75 |
break; |
| 76 |
case POSITION_CENTER: |
| 77 |
x = (cx - xsize) / 2; |
| 78 |
y = (cy - ysize) / 2; |
| 79 |
break; |
| 80 |
case POSITION_OUTSIDE: |
| 81 |
x = cx; |
| 82 |
y = cy; |
| 83 |
break; |
| 84 |
} |
| 85 |
|
| 86 |
::MoveWindow(hWnd, x, y, xsize, ysize, TRUE); |
| 87 |
} |
| 88 |
|
| 89 |
/* ========================================================================== |
| 90 |
Function Name : (BOOL) EnableItem() |
| 91 |
Outline : �_�C�A���O�A�C�e�����L���^���������� |
| 92 |
Arguments : HWND hWnd (in) �_�C�A���O���n���h�� |
| 93 |
: int idControl (in) �_�C�A���O�A�C�e���� ID |
| 94 |
: BOOL flag |
| 95 |
Return Value : ���� TRUE |
| 96 |
: ���s FALSE |
| 97 |
Reference : |
| 98 |
Renewal : |
| 99 |
Notes : |
| 100 |
Attention : |
| 101 |
Up Date : |
| 102 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 103 |
BOOL EnableItem(HWND hWnd, int idControl, BOOL flag) |
| 104 |
{ |
| 105 |
HWND hWndItem; |
| 106 |
|
| 107 |
if ((hWndItem = ::GetDlgItem(hWnd, idControl)) == NULL) |
| 108 |
return FALSE; |
| 109 |
|
| 110 |
return ::EnableWindow(hWndItem, flag); |
| 111 |
} |
| 112 |
|
| 113 |
/* ========================================================================== |
| 114 |
Function Name : (void) EncodePassword() |
| 115 |
Outline : �p�X���[�h���G���R�[�h(?)�����B |
| 116 |
Arguments : char cPassword (in) �������������� |
| 117 |
: int cEncodePassword (out) ���������������� |
| 118 |
Return Value : ���� |
| 119 |
Reference : |
| 120 |
Renewal : |
| 121 |
Notes : |
| 122 |
Attention : |
| 123 |
Up Date : |
| 124 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 125 |
void EncodePassword(TCHAR *cPassword, TCHAR *cEncodePassword) |
| 126 |
{ |
| 127 |
DWORD dwCnt; |
| 128 |
DWORD dwPasswordLength = ::lstrlen(cPassword); |
| 129 |
|
| 130 |
for (dwCnt = 0; dwCnt < dwPasswordLength; dwCnt++) |
| 131 |
cEncodePassword[dwPasswordLength - 1 - dwCnt] = cPassword[dwCnt] ^ 0xff; |
| 132 |
|
| 133 |
cEncodePassword[dwPasswordLength] = '\0'; |
| 134 |
} |
| 135 |
|
| 136 |
/* ========================================================================== |
| 137 |
Function Name : (BOOL) SaveFileDlg() |
| 138 |
Outline : �u���O���w�����������v�_�C�A���O���J���A�w���������t�@�C�� |
| 139 |
: �p�X���w���������A�C�e�������� |
| 140 |
Arguments : HWND hWnd (in) �e�E�C���h�E���n���h�� |
| 141 |
: UINT editCtl (in) �A�C�e���� ID |
| 142 |
: char *title (in) �E�C���h�E�^�C�g�� |
| 143 |
: char *filter (in) �\�������t�@�C�����t�B���^ |
| 144 |
: char *defaultDir (in) �f�t�H���g���p�X |
| 145 |
Return Value : ���� TRUE |
| 146 |
: ���s FALSE |
| 147 |
Reference : |
| 148 |
Renewal : |
| 149 |
Notes : |
| 150 |
Attention : |
| 151 |
Up Date : |
| 152 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 153 |
BOOL SaveFileDlg(HWND hWnd, UINT editCtl, TCHAR *title, TCHAR *filter, TCHAR *defaultDir) |
| 154 |
{ |
| 155 |
TCHAR *szDirName; |
| 156 |
TCHAR szFile[MAX_PATH] = _T(""); |
| 157 |
TCHAR szPath[MAX_PATH]; |
| 158 |
OPENFILENAME ofn; |
| 159 |
|
| 160 |
szDirName = (TCHAR *) malloc(MAX_PATH); |
| 161 |
|
| 162 |
if (editCtl == 0xffffffff) { |
| 163 |
::GetDlgItemText(hWnd, editCtl, szDirName, MAX_PATH); |
| 164 |
::lstrcpy(szDirName, defaultDir); |
| 165 |
} |
| 166 |
|
| 167 |
if (*szDirName == '"') |
| 168 |
szDirName++; |
| 169 |
if (szDirName[::lstrlen(szDirName) - 1] == '"') |
| 170 |
szDirName[::lstrlen(szDirName) - 1] = '\0'; |
| 171 |
|
| 172 |
TCHAR *ptr = _tcsrchr(szDirName, '\\'); |
| 173 |
if (ptr == NULL) { |
| 174 |
::lstrcpy(szFile, szDirName); |
| 175 |
if (defaultDir != NULL && *szDirName == 0) |
| 176 |
::lstrcpy(szDirName, defaultDir); |
| 177 |
} else { |
| 178 |
*ptr = 0; |
| 179 |
::lstrcpy(szFile, ptr + 1); |
| 180 |
} |
| 181 |
|
| 182 |
memset(&ofn, 0, sizeof(ofn)); |
| 183 |
ofn.lStructSize = sizeof(OPENFILENAME); |
| 184 |
ofn.hwndOwner = hWnd; |
| 185 |
ofn.lpstrFilter = filter; |
| 186 |
ofn.nFilterIndex = 1; |
| 187 |
ofn.lpstrFile = szFile; |
| 188 |
ofn.nMaxFile = sizeof(szFile); |
| 189 |
ofn.lpstrTitle = title; |
| 190 |
ofn.lpstrInitialDir = szDirName; |
| 191 |
ofn.Flags = OFN_HIDEREADONLY; |
| 192 |
|
| 193 |
if (::GetSaveFileName(&ofn) == FALSE) { |
| 194 |
free(szDirName); |
| 195 |
return FALSE; |
| 196 |
} |
| 197 |
|
| 198 |
::lstrcpy(szPath, ofn.lpstrFile); |
| 199 |
|
| 200 |
::SetDlgItemText(hWnd, editCtl, szPath); |
| 201 |
::lstrcpy(defaultDir, szPath); |
| 202 |
|
| 203 |
free(szDirName); |
| 204 |
|
| 205 |
return TRUE; |
| 206 |
} |
| 207 |
|
| 208 |
/* ========================================================================== |
| 209 |
Function Name : (BOOL) OpenFileDlg() |
| 210 |
Outline : �u�t�@�C�����J���v�_�C�A���O���J���A�w���������t�@�C�� |
| 211 |
: �p�X���w���������A�C�e�������� |
| 212 |
Arguments : HWND hWnd (in) �e�E�C���h�E���n���h�� |
| 213 |
: UINT editCtl (in) �A�C�e���� ID |
| 214 |
: char *title (in) �E�C���h�E�^�C�g�� |
| 215 |
: char *filter (in) �\�������t�@�C�����t�B���^ |
| 216 |
: char *defaultDir (in) �f�t�H���g���p�X |
| 217 |
Return Value : ���� TRUE |
| 218 |
: ���s FALSE |
| 219 |
Reference : |
| 220 |
Renewal : |
| 221 |
Notes : |
| 222 |
Attention : |
| 223 |
Up Date : |
| 224 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 225 |
BOOL OpenFileDlg(HWND hWnd, UINT editCtl, TCHAR *title, TCHAR *filter, TCHAR *defaultDir) |
| 226 |
{ |
| 227 |
TCHAR *szDirName; |
| 228 |
TCHAR szFile[MAX_PATH] = _T(""); |
| 229 |
TCHAR szPath[MAX_PATH]; |
| 230 |
OPENFILENAME ofn; |
| 231 |
|
| 232 |
szDirName = (TCHAR *) malloc(MAX_PATH); |
| 233 |
|
| 234 |
if (editCtl != 0xffffffff) { |
| 235 |
::GetDlgItemText(hWnd, editCtl, szDirName, MAX_PATH); |
| 236 |
::lstrcpy(szDirName, defaultDir); |
| 237 |
} |
| 238 |
|
| 239 |
if (*szDirName == '"') |
| 240 |
szDirName++; |
| 241 |
if (szDirName[::lstrlen(szDirName) - 1] == '"') |
| 242 |
szDirName[::lstrlen(szDirName) - 1] = '\0'; |
| 243 |
|
| 244 |
TCHAR *ptr = _tcsrchr(szDirName, '\\'); |
| 245 |
if (ptr == NULL) { |
| 246 |
::lstrcpy(szFile, szDirName); |
| 247 |
if (defaultDir != NULL && *szDirName == 0) |
| 248 |
::lstrcpy(szDirName, defaultDir); |
| 249 |
} else { |
| 250 |
*ptr = 0; |
| 251 |
::lstrcpy(szFile, ptr + 1); |
| 252 |
} |
| 253 |
|
| 254 |
memset(&ofn, 0, sizeof(ofn)); |
| 255 |
ofn.lStructSize = sizeof(OPENFILENAME); |
| 256 |
ofn.hwndOwner = hWnd; |
| 257 |
ofn.lpstrFilter = filter; |
| 258 |
ofn.nFilterIndex = 1; |
| 259 |
ofn.lpstrFile = szFile; |
| 260 |
ofn.nMaxFile = sizeof(szFile); |
| 261 |
ofn.lpstrTitle = title; |
| 262 |
ofn.lpstrInitialDir = szDirName; |
| 263 |
ofn.Flags = OFN_HIDEREADONLY | OFN_NODEREFERENCELINKS; |
| 264 |
|
| 265 |
if (::GetOpenFileName(&ofn) == FALSE) { |
| 266 |
free(szDirName); |
| 267 |
return FALSE; |
| 268 |
} |
| 269 |
|
| 270 |
::lstrcpy(szPath, ofn.lpstrFile); |
| 271 |
|
| 272 |
::SetDlgItemText(hWnd, editCtl, szPath); |
| 273 |
::lstrcpy(defaultDir, szPath); |
| 274 |
|
| 275 |
free(szDirName); |
| 276 |
|
| 277 |
return TRUE; |
| 278 |
} |
| 279 |
|
| 280 |
/* ========================================================================== |
| 281 |
Function Name : (int CALLBACK) BrowseCallbackProc() |
| 282 |
Outline : BrowseForFolder()���R�[���o�b�N�����B |
| 283 |
Arguments : HWND hWnd (in) �e�E�C���h�E���n���h�� |
| 284 |
: UINT uMsg (in) �E�C���h�E�^�C�g�� |
| 285 |
: LPARAM lParam (in) LPARAM |
| 286 |
: LPARAM lpData (in) BROWSEINFO �� lParam |
| 287 |
Return Value : |
| 288 |
Reference : |
| 289 |
Renewal : |
| 290 |
Notes : |
| 291 |
Attention : |
| 292 |
Up Date : |
| 293 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 294 |
int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData) |
| 295 |
{ |
| 296 |
switch (uMsg) { |
| 297 |
case BFFM_INITIALIZED: |
| 298 |
::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData); |
| 299 |
break; |
| 300 |
case BFFM_SELCHANGED: |
| 301 |
break; |
| 302 |
} |
| 303 |
|
| 304 |
return 0; |
| 305 |
} |
| 306 |
|
| 307 |
/* ========================================================================== |
| 308 |
Function Name : (BOOL) GetModulePath() |
| 309 |
Outline : �������������s�������W���[�����p�X�����������B |
| 310 |
Arguments : char szPath (out) ���W���[�����p�X |
| 311 |
: DWORD dwMaxPath (in) szPath�������� |
| 312 |
Return Value : ���� TRUE |
| 313 |
: ���s FALSE |
| 314 |
Reference : |
| 315 |
Renewal : |
| 316 |
Notes : |
| 317 |
Attention : |
| 318 |
Up Date : |
| 319 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 320 |
BOOL GetModulePath(TCHAR *szPath, DWORD dwMaxPath) |
| 321 |
{ |
| 322 |
TCHAR *pt; |
| 323 |
|
| 324 |
if (::GetModuleFileName(NULL, szPath, dwMaxPath) == FALSE) |
| 325 |
return FALSE; |
| 326 |
|
| 327 |
pt = _tcsrchr(szPath, '\\'); |
| 328 |
*pt = '\0'; |
| 329 |
|
| 330 |
return TRUE; |
| 331 |
} |
| 332 |
|
| 333 |
/* ========================================================================== |
| 334 |
Function Name : (UINT) GetResourceType() |
| 335 |
Outline : �w���������p�X���h���C�u�������������� |
| 336 |
Arguments : LPCTSTR lpszPath (in) �h���C�u�������m�������p�X |
| 337 |
Return Value : ���\�[�X�^�C�v |
| 338 |
Reference : |
| 339 |
Renewal : |
| 340 |
Notes : |
| 341 |
Attention : |
| 342 |
Up Date : |
| 343 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 344 |
UINT GetResourceType(LPCTSTR lpszPath) |
| 345 |
{ |
| 346 |
UINT ret; |
| 347 |
TCHAR szCurrentPath[MAX_PATH]; |
| 348 |
|
| 349 |
if (::GetCurrentDirectory(MAX_PATH, szCurrentPath) == 0) |
| 350 |
return 0; |
| 351 |
|
| 352 |
if (::SetCurrentDirectory(lpszPath) == FALSE) |
| 353 |
return 0; |
| 354 |
|
| 355 |
ret = ::GetDriveType(NULL); |
| 356 |
|
| 357 |
::SetCurrentDirectory(szCurrentPath); |
| 358 |
|
| 359 |
return ret; |
| 360 |
} |
| 361 |
|
| 362 |
/* ========================================================================== |
| 363 |
Function Name : (char *) pathTok() |
| 364 |
Outline : �p�X�p�� strtok |
| 365 |
Arguments : char *str (in) �g�[�N�����������p�X |
| 366 |
: char *separator (in) �g�[�N�������� |
| 367 |
Return Value : ���� �����o���������� |
| 368 |
: ���s NULL |
| 369 |
Reference : |
| 370 |
Renewal : |
| 371 |
Notes : |
| 372 |
Attention : |
| 373 |
Up Date : |
| 374 |
======1=========2=========3=========4=========5=========6=========7======= */ |
| 375 |
TCHAR *PathTok(TCHAR *str, TCHAR *separator) |
| 376 |
{ |
| 377 |
static TCHAR *sv_str; |
| 378 |
|
| 379 |
if (str != NULL) |
| 380 |
sv_str = str; |
| 381 |
else if (sv_str != NULL) |
| 382 |
str = sv_str; |
| 383 |
else |
| 384 |
return NULL; |
| 385 |
|
| 386 |
while (*str != '\0' && _tcschr(separator, *str) != NULL) |
| 387 |
str++; |
| 388 |
|
| 389 |
if (*str == '\"') { |
| 390 |
for (sv_str = ++str; *sv_str != '\0' && *sv_str != '\"'; sv_str++) |
| 391 |
; |
| 392 |
*sv_str++ = '\0'; |
| 393 |
} else { |
| 394 |
for (sv_str=str ; *sv_str != '\0'; sv_str++) { |
| 395 |
if (_tcschr(separator, *sv_str) != NULL) { |
| 396 |
*sv_str++ = '\0'; |
| 397 |
break; |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
if (sv_str != str) |
| 402 |
return str; |
| 403 |
else |
| 404 |
return sv_str = NULL; |
| 405 |
} |
| 406 |
|
| 407 |
TCHAR *lstrstri(TCHAR *s1, TCHAR *s2) |
| 408 |
{ |
| 409 |
DWORD dwLen1= ::lstrlen(s1); |
| 410 |
DWORD dwLen2= ::lstrlen(s2); |
| 411 |
|
| 412 |
for (DWORD dwCnt = 0; dwCnt <= dwLen1; dwCnt++) { |
| 413 |
// VS2005���r���h�G���[���������� dwCnt2 ���������� (2006.2.18 yutaka) |
| 414 |
DWORD dwCnt2; |
| 415 |
for (dwCnt2 = 0; dwCnt2 <= dwLen2; dwCnt2++) |
| 416 |
if (tolower(s1[dwCnt + dwCnt2]) != tolower(s2[dwCnt2])) |
| 417 |
break; |
| 418 |
if (dwCnt2 > dwLen2) |
| 419 |
return s1 + dwCnt; |
| 420 |
} |
| 421 |
|
| 422 |
return NULL; |
| 423 |
} |
| 424 |
|
| 425 |
BOOL SetForceForegroundWindow(HWND hWnd) |
| 426 |
{ |
| 427 |
#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT |
| 428 |
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000 |
| 429 |
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001 |
| 430 |
#endif |
| 431 |
DWORD foreId, targId, svTmOut; |
| 432 |
|
| 433 |
foreId = ::GetWindowThreadProcessId(::GetForegroundWindow(), NULL); |
| 434 |
targId = ::GetWindowThreadProcessId(hWnd, NULL); |
| 435 |
::AttachThreadInput(targId, foreId, TRUE); |
| 436 |
::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, (void *)&svTmOut, 0); |
| 437 |
::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0, 0); |
| 438 |
BOOL ret = ::SetForegroundWindow(hWnd); |
| 439 |
::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (void *)svTmOut, 0); |
| 440 |
::AttachThreadInput(targId, foreId, FALSE); |
| 441 |
|
| 442 |
return ret; |
| 443 |
} |
| 444 |
|
| 445 |
void UTIL_get_lang_msg(const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile) |
| 446 |
{ |
| 447 |
GetI18nStr("TTMenu", key, buf, buf_len, def, iniFile); |
| 448 |
} |
| 449 |
|
| 450 |
int UTIL_get_lang_font(const char *key, HWND dlg, PLOGFONT logfont, HFONT *font, const char *iniFile) |
| 451 |
{ |
| 452 |
if (GetI18nLogfont("TTMenu", key, logfont, |
| 453 |
GetDeviceCaps(GetDC(dlg),LOGPIXELSY), |
| 454 |
iniFile) == FALSE) { |
| 455 |
return FALSE; |
| 456 |
} |
| 457 |
|
| 458 |
if ((*font = CreateFontIndirect(logfont)) == NULL) { |
| 459 |
return FALSE; |
| 460 |
} |
| 461 |
|
| 462 |
return TRUE; |
| 463 |
} |
| 464 |
|
| 465 |
LRESULT CALLBACK password_wnd_proc(HWND control, UINT msg, |
| 466 |
WPARAM wParam, LPARAM lParam) |
| 467 |
{ |
| 468 |
switch (msg) { |
| 469 |
case WM_CHAR: |
| 470 |
if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) { |
| 471 |
char chars[] = { (char) wParam, 0 }; |
| 472 |
|
| 473 |
SendMessage(control, EM_REPLACESEL, (WPARAM) TRUE, |
| 474 |
(LPARAM) (char *) chars); |
| 475 |
return 0; |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
return CallWindowProc((WNDPROC) GetWindowLongPtr(control, GWLP_USERDATA), |
| 480 |
control, msg, wParam, lParam); |
| 481 |
} |