• R/O
  • SSH
  • HTTPS

ttssh2:


File Info

Rev. 6793
Size 96,259 bytes
Time 2017-06-09 23:32:37
Author doda
Log Message

SetDllDirectory(), SetDefaultDllDirectories() が使える場合は呼ぶようにした。

DLL Hijacking 対策。
現行 OS 向け。古い OS では効果ないけれど。

DLL 検索パスからプログラムディレクトリを外したが、それでもプログラムディレクトリはセキュアである必要がある。
なぜなら、TTXなんちゃら.DLL という DLL を作成されたら……

Content

  1. /* ==========================================================================
  2. Project Name : TeraTerm Menu
  3. Outline : TeraTerm Menu Function
  4. Version : 0.94
  5. Create : 1998-11-22(Sun)
  6. Update : 2002-10-02(Wed)
  7. Reference : Copyright (C) S.Hayakawa 1997-2002
  8. ======1=========2=========3=========4=========5=========6=========7======= */
  9. #define STRICT
  10. #include <windows.h>
  11. #include <commctrl.h>
  12. #include <windowsx.h> // for GET_X_LPARAM(), GET_Y_LPARAM()
  13. #include "ttpmenu.h"
  14. #include "registry.h"
  15. #include "winmisc.h"
  16. #include "resource.h"
  17. #include "compat_w95.h"
  18. // UTF-8 TeraTermでは、デフォルトインストール先を下記に変更した。(2004.12.2 yutaka)
  19. // さらに、デフォルトインストール先はカレントディレクトリに変更。(2004.12.14 yutaka)
  20. #define DEFAULT_PATH "."
  21. // グローバル変数
  22. HWND g_hWnd; // メインのハンドル
  23. HWND g_hWndMenu = NULL; // 設定ダイアログのハンドル
  24. HWND g_hWndTip; // 設定ダイアログ内ツールチップのハンドル
  25. HICON g_hIcon; // アプリケーションアイコンのハンドル
  26. HICON g_hIconSmall; // アプリケーションアイコン(16x16)のハンドル
  27. HMENU g_hMenu; // メニュー(非表示)のハンドル
  28. HMENU g_hSubMenu; // ポップアップメニューのハンドル
  29. HMENU g_hListMenu; // 設定一覧ポップアップメニューのハンドル
  30. HMENU g_hConfigMenu; // 表示設定ポップアップメニューのハンドル
  31. HHOOK g_hHook = NULL; // ツールチップ関連フックのハンドル
  32. HINSTANCE g_hI; // アプリケーションインスタンス
  33. JobInfo g_JobInfo; // カレントの設定情報構造体(設定ダイアログ)
  34. MenuData g_MenuData; // TeraTerm Menuの表示設定等の構造体
  35. char UILanguageFile[MAX_PATH];
  36. HFONT g_AboutFont;
  37. HFONT g_ConfigFont;
  38. HFONT g_DetailFont;
  39. // ttdlg.c と同じ内容
  40. // 実行ファイルからバージョン情報を得る (2005.2.28 yutaka)
  41. void get_file_version(char *exefile, int *major, int *minor, int *release, int *build)
  42. {
  43. typedef struct {
  44. WORD wLanguage;
  45. WORD wCodePage;
  46. } LANGANDCODEPAGE, *LPLANGANDCODEPAGE;
  47. LPLANGANDCODEPAGE lplgcode;
  48. UINT unLen;
  49. DWORD size;
  50. char *buf = NULL;
  51. BOOL ret;
  52. int i;
  53. char fmt[80];
  54. char *pbuf;
  55. size = GetFileVersionInfoSize(exefile, NULL);
  56. if (size == 0) {
  57. goto error;
  58. }
  59. buf = (char *)malloc(size);
  60. ZeroMemory(buf, size);
  61. if (GetFileVersionInfo(exefile, 0, size, buf) == FALSE) {
  62. goto error;
  63. }
  64. ret = VerQueryValue(buf,
  65. "\\VarFileInfo\\Translation",
  66. (LPVOID *)&lplgcode, &unLen);
  67. if (ret == FALSE)
  68. goto error;
  69. for (i = 0 ; i < (int)(unLen / sizeof(LANGANDCODEPAGE)) ; i++) {
  70. _snprintf(fmt, sizeof(fmt), "\\StringFileInfo\\%04x%04x\\FileVersion",
  71. lplgcode[i].wLanguage, lplgcode[i].wCodePage);
  72. VerQueryValue(buf, fmt, (LPVOID *)&pbuf, &unLen);
  73. if (unLen > 0) { // get success
  74. int n, a, b, c, d;
  75. n = sscanf(pbuf, "%d, %d, %d, %d", &a, &b, &c, &d);
  76. if (n == 4) { // convert success
  77. *major = a;
  78. *minor = b;
  79. *release = c;
  80. *build = d;
  81. break;
  82. }
  83. }
  84. }
  85. free(buf);
  86. return;
  87. error:
  88. free(buf);
  89. *major = *minor = *release = *build = 0;
  90. }
  91. /* ==========================================================================
  92. Function Name : (BOOL) ExecStartup()
  93. Outline : スタートアップ設定のジョブを実行する。
  94. Arguments : HWND hWnd (In) ダイアログのハンドル
  95. Return Value : 成功 TRUE
  96. Reference :
  97. Renewal :
  98. Notes :
  99. Attention :
  100. Up Date :
  101. ======1=========2=========3=========4=========5=========6=========7======= */
  102. BOOL ExecStartup(HWND hWnd)
  103. {
  104. char szEntryName[MAX_PATH];
  105. char szJobName[MAXJOBNUM][MAX_PATH];
  106. HKEY hKey;
  107. DWORD dwCnt;
  108. DWORD dwIndex = 0;
  109. DWORD dwSize = MAX_PATH;
  110. if ((hKey = RegOpen(HKEY_CURRENT_USER, TTERM_KEY)) != INVALID_HANDLE_VALUE) {
  111. while (RegEnumEx(hKey, dwIndex, szEntryName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
  112. ::lstrcpy(szJobName[dwIndex++], szEntryName);
  113. dwSize = MAX_PATH;
  114. }
  115. ::lstrcpy(szJobName[dwIndex], "");
  116. RegClose(hKey);
  117. for (dwCnt = 0; dwCnt < dwIndex; dwCnt++)
  118. ConnectHost(hWnd, 0, szJobName[dwCnt]);
  119. }
  120. return TRUE;
  121. }
  122. /* ==========================================================================
  123. Function Name : (BOOL) ErrorMessage()
  124. Outline : 指定メッセージ+システムのエラーメッセージを表示する。
  125. Arguments : HWND hWnd (In) 親ウインドウのハンドル
  126. : LPTSTR msg,... (In) 任意メッセージ文字列
  127. Return Value : 成功 TRUE
  128. Reference :
  129. Renewal :
  130. Notes :
  131. Attention :
  132. Up Date :
  133. ======1=========2=========3=========4=========5=========6=========7======= */
  134. BOOL ErrorMessage(HWND hWnd, DWORD dwErr, LPTSTR msg,...)
  135. {
  136. char szBuffer[MAX_PATH] = "";
  137. va_list ap;
  138. va_start(ap, msg);
  139. vsprintf(szBuffer + ::lstrlen(szBuffer), msg, ap);
  140. va_end(ap);
  141. ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  142. NULL,
  143. dwErr,
  144. LANG_NEUTRAL,
  145. szBuffer + ::lstrlen(szBuffer),
  146. MAX_PATH,
  147. NULL);
  148. MessageBox(hWnd, szBuffer, "TeraTerm Menu", MB_ICONSTOP | MB_OK);
  149. return TRUE;
  150. }
  151. /* ==========================================================================
  152. Function Name : (BOOL) SetMenuFont()
  153. Outline : フォント指定ダイアログを表示し、指定されたフォントを
  154. : 設定する。
  155. Arguments : HWND hWnd (In) 親ウインドウのハンドル
  156. Return Value : 成功 TRUE
  157. Reference :
  158. Renewal :
  159. Notes :
  160. Attention :
  161. Up Date :
  162. ======1=========2=========3=========4=========5=========6=========7======= */
  163. BOOL SetMenuFont(HWND hWnd)
  164. {
  165. HWND hFontWnd;
  166. DWORD rgbColors;
  167. LOGFONT lfFont;
  168. CHOOSEFONT chooseFont;
  169. static int open = 0;
  170. if (open == 1) {
  171. while ((hFontWnd = ::FindWindow(NULL, "Font")) != NULL) {
  172. if (hWnd == ::GetParent(hFontWnd)) {
  173. ::SetForceForegroundWindow(hFontWnd);
  174. break;
  175. }
  176. }
  177. return TRUE;
  178. }
  179. open = 1;
  180. lfFont = g_MenuData.lfFont;
  181. rgbColors = g_MenuData.crMenuTxt;
  182. memset((void *) &chooseFont, 0, sizeof(CHOOSEFONT));
  183. chooseFont.lStructSize = sizeof(CHOOSEFONT);
  184. chooseFont.hwndOwner = hWnd;
  185. chooseFont.lpLogFont = &lfFont;
  186. chooseFont.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_EFFECTS;
  187. chooseFont.rgbColors = rgbColors;
  188. chooseFont.nFontType = SCREEN_FONTTYPE;
  189. if (::ChooseFont(&chooseFont) == TRUE) {
  190. if (g_MenuData.hFont != NULL)
  191. ::DeleteObject((HGDIOBJ) g_MenuData.hFont);
  192. g_MenuData.crMenuTxt = chooseFont.rgbColors;
  193. g_MenuData.lfFont = lfFont;
  194. g_MenuData.hFont = ::CreateFontIndirect(&lfFont);
  195. RedrawMenu(hWnd);
  196. }
  197. open = 0;
  198. return TRUE;
  199. }
  200. /* ==========================================================================
  201. Function Name : (BOOL) ExtractAssociatedIconEx()
  202. Outline : アプリケーションに関連付けられたアイコンを取得する。
  203. : 設定する。
  204. Arguments : char *szPath (In) アプリケーション名
  205. : HICON *hLargeIcon (Out) 大きいアイコンのハンドル
  206. : HICON *hSmallIcon (Out) 小さいアイコンのハンドル
  207. Return Value : 成功 TRUE
  208. Reference :
  209. Renewal :
  210. Notes :
  211. Attention :
  212. Up Date :
  213. ======1=========2=========3=========4=========5=========6=========7======= */
  214. BOOL ExtractAssociatedIconEx(char *szPath, HICON *hLargeIcon, HICON *hSmallIcon)
  215. {
  216. SHFILEINFO sfi;
  217. ::SHGetFileInfo(szPath, 0, &sfi, sizeof(sfi), SHGFI_LARGEICON | SHGFI_ICON);
  218. *hLargeIcon = ::CopyIcon(sfi.hIcon);
  219. ::DestroyIcon(sfi.hIcon);
  220. ::SHGetFileInfo(szPath, 0, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_ICON);
  221. *hSmallIcon = ::CopyIcon(sfi.hIcon);
  222. ::DestroyIcon(sfi.hIcon);
  223. return TRUE;
  224. }
  225. /* ==========================================================================
  226. Function Name : (BOOL) GetApplicationFilename()
  227. Outline : レジストリより指定された設定のアプロケーション名を取得
  228. : する。
  229. Arguments : char *szName (In) 設定名
  230. : char *szPath (Out) アプリケーション名
  231. Return Value : 成功 TRUE
  232. Reference :
  233. Renewal :
  234. Notes :
  235. Attention :
  236. Up Date :
  237. ======1=========2=========3=========4=========5=========6=========7======= */
  238. BOOL GetApplicationFilename(char *szName, char *szPath)
  239. {
  240. char szSubKey[MAX_PATH];
  241. char szDefault[MAX_PATH] = DEFAULT_PATH;
  242. char szTTermPath[MAX_PATH];
  243. BOOL bRet;
  244. BOOL bTtssh = FALSE;
  245. HKEY hKey;
  246. ::wsprintf(szSubKey, "%s\\%s", TTERM_KEY, szName);
  247. if ((hKey = RegOpen(HKEY_CURRENT_USER, szSubKey)) == INVALID_HANDLE_VALUE)
  248. return FALSE;
  249. bRet = RegGetStr(hKey, KEY_TERATERM, szPath, MAX_PATH);
  250. if (bRet == FALSE || ::lstrlen(szPath) == 0) {
  251. RegGetDword(hKey, KEY_TTSSH, (LPDWORD) &bTtssh);
  252. ::GetProfileString("Tera Term Pro", "Path", szDefault, szTTermPath, MAX_PATH);
  253. ::wsprintf(szPath, "%s\\%s", szTTermPath, bTtssh ? TTSSH : TERATERM);
  254. }
  255. RegClose(hKey);
  256. return TRUE;
  257. }
  258. /* ==========================================================================
  259. Function Name : (BOOL) AddTooltip()
  260. Outline : 指定されたコントロールにツールチップを関連付ける
  261. Arguments : int idControl (In) コントロールID
  262. Return Value : 成功 TRUE / 失敗 FALSE
  263. Reference :
  264. Renewal :
  265. Notes :
  266. Attention :
  267. Up Date :
  268. ======1=========2=========3=========4=========5=========6=========7======= */
  269. BOOL AddTooltip(int idControl)
  270. {
  271. TOOLINFO ti;
  272. ti.cbSize = sizeof(TOOLINFO);
  273. ti.uFlags = TTF_IDISHWND;
  274. ti.hwnd = g_hWndMenu;
  275. ti.uId = (UINT) ::GetDlgItem(g_hWndMenu, idControl);
  276. ti.hinst = 0;
  277. ti.lpszText = LPSTR_TEXTCALLBACK;
  278. return ::SendMessage(g_hWndTip, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  279. }
  280. /* ==========================================================================
  281. Function Name : (BOOL) LoadConfig()
  282. Outline : レジストリよりTeraTerm Menuの表示設定等を取得する
  283. Arguments : なし
  284. Return Value : 成功 TRUE / 失敗 FALSE
  285. Reference :
  286. Renewal :
  287. Notes :
  288. Attention :
  289. Up Date :
  290. ======1=========2=========3=========4=========5=========6=========7======= */
  291. BOOL LoadConfig(void)
  292. {
  293. HKEY hKey;
  294. char uimsg[MAX_UIMSG];
  295. if ((hKey = RegCreate(HKEY_CURRENT_USER, TTERM_KEY)) == INVALID_HANDLE_VALUE)
  296. return FALSE;
  297. if (RegGetDword(hKey, KEY_ICONMODE, &(g_MenuData.dwIconMode)) == TRUE) {
  298. if (g_MenuData.dwIconMode == MODE_LARGEICON) {
  299. UTIL_get_lang_msg("MENU_ICON", uimsg, sizeof(uimsg), STR_ICONMODE, UILanguageFile);
  300. ::ModifyMenu(g_hConfigMenu, ID_ICON, MF_CHECKED | MF_BYCOMMAND, ID_ICON, uimsg);
  301. }
  302. } else
  303. g_MenuData.dwIconMode = MODE_SMALLICON;
  304. if (RegGetDword(hKey, KEY_LEFTBUTTONPOPUP, (LPDWORD) &(g_MenuData.bLeftButtonPopup)) == FALSE)
  305. g_MenuData.bLeftButtonPopup = TRUE;
  306. if (g_MenuData.bLeftButtonPopup == TRUE) {
  307. UTIL_get_lang_msg("MENU_LEFTPOPUP", uimsg, sizeof(uimsg), STR_LEFTBUTTONPOPUP, UILanguageFile);
  308. ::ModifyMenu(g_hConfigMenu, ID_LEFTPOPUP, MF_CHECKED | MF_BYCOMMAND, ID_LEFTPOPUP, uimsg);
  309. }
  310. if (RegGetDword(hKey, KEY_MENUTEXTCOLOR, &(g_MenuData.crMenuTxt)) == FALSE)
  311. g_MenuData.crMenuTxt = ::GetSysColor(COLOR_MENUTEXT);
  312. if (RegGetDword(hKey, KEY_HOTKEY, (LPDWORD) &(g_MenuData.bHotkey)) == FALSE)
  313. g_MenuData.bHotkey = FALSE;
  314. if (g_MenuData.bHotkey == TRUE) {
  315. UTIL_get_lang_msg("MENU_HOTKEY", uimsg, sizeof(uimsg), STR_HOTKEY, UILanguageFile);
  316. ::ModifyMenu(g_hConfigMenu, ID_HOTKEY, MF_CHECKED | MF_BYCOMMAND, ID_HOTKEY, uimsg);
  317. ::RegisterHotKey(g_hWnd, WM_MENUOPEN, MOD_CONTROL | MOD_ALT, 'M');
  318. }
  319. if (RegGetDword(hKey, KEY_LF_HEIGHT, (DWORD *) &(g_MenuData.lfFont.lfHeight)) == TRUE) {
  320. RegGetDword(hKey, KEY_LF_WIDTH, (DWORD *) &(g_MenuData.lfFont.lfWidth));
  321. RegGetDword(hKey, KEY_LF_ESCAPEMENT, (DWORD *) &(g_MenuData.lfFont.lfEscapement));
  322. RegGetDword(hKey, KEY_LF_ORIENTATION, (DWORD *) &(g_MenuData.lfFont.lfOrientation));
  323. RegGetDword(hKey, KEY_LF_WEIGHT, (DWORD *) &(g_MenuData.lfFont.lfWeight));
  324. RegGetDword(hKey, KEY_LF_ITALIC, (DWORD *) &(g_MenuData.lfFont.lfItalic));
  325. RegGetDword(hKey, KEY_LF_UNDERLINE, (DWORD *) &(g_MenuData.lfFont.lfUnderline));
  326. RegGetDword(hKey, KEY_LF_STRIKEOUT, (DWORD *) &(g_MenuData.lfFont.lfStrikeOut));
  327. RegGetDword(hKey, KEY_LF_CHARSET, (DWORD *) &(g_MenuData.lfFont.lfCharSet));
  328. RegGetDword(hKey, KEY_LF_OUTPRECISION, (DWORD *) &(g_MenuData.lfFont.lfOutPrecision));
  329. RegGetDword(hKey, KEY_LF_CLIPPRECISION, (DWORD *) &(g_MenuData.lfFont.lfClipPrecision));
  330. RegGetDword(hKey, KEY_LF_QUALITY, (DWORD *) &(g_MenuData.lfFont.lfQuality));
  331. RegGetDword(hKey, KEY_LF_PITCHANDFAMILY, (DWORD *) &(g_MenuData.lfFont.lfPitchAndFamily));
  332. RegGetStr(hKey, KEY_LF_FACENAME, g_MenuData.lfFont.lfFaceName, LF_FACESIZE);
  333. } else
  334. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &(g_MenuData.lfFont));
  335. RegClose(hKey);
  336. g_MenuData.crMenuBg = ::GetSysColor(COLOR_MENU);
  337. g_MenuData.crSelMenuBg = ::GetSysColor(COLOR_HIGHLIGHT);
  338. g_MenuData.crSelMenuTxt = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
  339. g_MenuData.hFont = ::CreateFontIndirect(&(g_MenuData.lfFont));
  340. return TRUE;
  341. }
  342. /* ==========================================================================
  343. Function Name : (BOOL) SaveConfig()
  344. Outline : レジストリにTeraTerm Menuの表示設定等を保存する
  345. Arguments : なし
  346. Return Value : 成功 TRUE / 失敗 FALSE
  347. Reference :
  348. Renewal :
  349. Notes :
  350. Attention :
  351. Up Date :
  352. ======1=========2=========3=========4=========5=========6=========7======= */
  353. BOOL SaveConfig(void)
  354. {
  355. HKEY hKey;
  356. if ((hKey = RegOpen(HKEY_CURRENT_USER, TTERM_KEY)) == INVALID_HANDLE_VALUE)
  357. return FALSE;
  358. RegSetDword(hKey, KEY_ICONMODE, g_MenuData.dwIconMode);
  359. RegSetDword(hKey, KEY_LEFTBUTTONPOPUP, g_MenuData.bLeftButtonPopup);
  360. RegSetDword(hKey, KEY_HOTKEY, g_MenuData.bHotkey);
  361. RegSetDword(hKey, KEY_MENUTEXTCOLOR, g_MenuData.crMenuTxt);
  362. RegSetDword(hKey, KEY_LF_HEIGHT, g_MenuData.lfFont.lfHeight);
  363. RegSetDword(hKey, KEY_LF_WIDTH, g_MenuData.lfFont.lfWidth);
  364. RegSetDword(hKey, KEY_LF_ESCAPEMENT, g_MenuData.lfFont.lfEscapement);
  365. RegSetDword(hKey, KEY_LF_ORIENTATION, g_MenuData.lfFont.lfOrientation);
  366. RegSetDword(hKey, KEY_LF_WEIGHT, g_MenuData.lfFont.lfWeight);
  367. RegSetDword(hKey, KEY_LF_ITALIC, g_MenuData.lfFont.lfItalic);
  368. RegSetDword(hKey, KEY_LF_UNDERLINE, g_MenuData.lfFont.lfUnderline);
  369. RegSetDword(hKey, KEY_LF_STRIKEOUT, g_MenuData.lfFont.lfStrikeOut);
  370. RegSetDword(hKey, KEY_LF_CHARSET, g_MenuData.lfFont.lfCharSet);
  371. RegSetDword(hKey, KEY_LF_OUTPRECISION, g_MenuData.lfFont.lfOutPrecision);
  372. RegSetDword(hKey, KEY_LF_CLIPPRECISION, g_MenuData.lfFont.lfClipPrecision);
  373. RegSetDword(hKey, KEY_LF_QUALITY, g_MenuData.lfFont.lfQuality);
  374. RegSetDword(hKey, KEY_LF_PITCHANDFAMILY, g_MenuData.lfFont.lfPitchAndFamily);
  375. RegSetStr(hKey, KEY_LF_FACENAME, g_MenuData.lfFont.lfFaceName);
  376. RegClose(hKey);
  377. return TRUE;
  378. }
  379. /* ==========================================================================
  380. Function Name : (LRESULT CALLBACK) GetMsgProc()
  381. Outline : フック プロシージャ(GetMsgProcのヘルプ参照)
  382. Arguments :
  383. Return Value :
  384. Reference :
  385. Renewal :
  386. Notes :
  387. Attention :
  388. Up Date :
  389. ======1=========2=========3=========4=========5=========6=========7======= */
  390. LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
  391. {
  392. MSG *lpMsg;
  393. lpMsg = (MSG *) lParam;
  394. if (nCode < 0 || !(::IsChild(g_hWndMenu, lpMsg->hwnd)))
  395. return ::CallNextHookEx(g_hHook, nCode, wParam, lParam);
  396. switch (lpMsg->message) {
  397. case WM_MOUSEMOVE:
  398. case WM_LBUTTONDOWN:
  399. case WM_LBUTTONUP:
  400. case WM_RBUTTONDOWN:
  401. case WM_RBUTTONUP:
  402. if (g_hWndTip != NULL) {
  403. MSG msg;
  404. msg.lParam = lpMsg->lParam;
  405. msg.wParam = lpMsg->wParam;
  406. msg.message = lpMsg->message;
  407. msg.hwnd = lpMsg->hwnd;
  408. ::SendMessage(g_hWndTip, TTM_RELAYEVENT, 0, (LPARAM) (LPMSG) &msg);
  409. }
  410. break;
  411. default:
  412. break;
  413. }
  414. return ::CallNextHookEx(g_hHook, nCode, wParam, lParam);
  415. }
  416. /* ==========================================================================
  417. Function Name : (BOOL) CreateTooltip()
  418. Outline : ツールチップを作成する
  419. Arguments : なし
  420. Return Value : 成功 TRUE / 失敗 FALSE
  421. Reference :
  422. Renewal :
  423. Notes :
  424. Attention :
  425. Up Date :
  426. ======1=========2=========3=========4=========5=========6=========7======= */
  427. BOOL CreateTooltip(void)
  428. {
  429. ::InitCommonControls();
  430. g_hWndTip = ::CreateWindowEx(0,
  431. TOOLTIPS_CLASS,
  432. (LPSTR) NULL,
  433. TTS_ALWAYSTIP,
  434. CW_USEDEFAULT,
  435. CW_USEDEFAULT,
  436. CW_USEDEFAULT,
  437. CW_USEDEFAULT,
  438. g_hWndMenu,
  439. (HMENU) NULL,
  440. g_hI,
  441. NULL);
  442. if (g_hWndTip == NULL)
  443. return FALSE;
  444. AddTooltip(BUTTON_SET);
  445. AddTooltip(BUTTON_DELETE);
  446. AddTooltip(BUTTON_ETC);
  447. AddTooltip(CHECK_TTSSH);
  448. g_hHook = ::SetWindowsHookEx(WH_GETMESSAGE,
  449. GetMsgProc,
  450. (HINSTANCE) NULL,
  451. ::GetCurrentThreadId());
  452. if (g_hHook == (HHOOK) NULL)
  453. return FALSE;
  454. return TRUE;
  455. }
  456. /* ==========================================================================
  457. Function Name : (BOOL) ManageWMNotify_Config()
  458. Outline : 設定ダイアログのWM_NOTIFYを処理する
  459. Arguments : LPARAM lParam
  460. Return Value : 処理 TRUE / 未処理 FALSE
  461. Reference :
  462. Renewal :
  463. Notes :
  464. Attention :
  465. Up Date :
  466. ======1=========2=========3=========4=========5=========6=========7======= */
  467. BOOL ManageWMNotify_Config(LPARAM lParam)
  468. {
  469. int idCtrl;
  470. LPTOOLTIPTEXT lpttt;
  471. if ((((LPNMHDR) lParam)->code) == TTN_NEEDTEXT) {
  472. idCtrl = ::GetDlgCtrlID((HWND) ((LPNMHDR) lParam)->idFrom);
  473. lpttt = (LPTOOLTIPTEXT) lParam;
  474. switch (idCtrl) {
  475. case BUTTON_SET:
  476. lpttt->lpszText = "Regist";
  477. return TRUE;
  478. case BUTTON_DELETE:
  479. lpttt->lpszText = "Delete";
  480. return TRUE;
  481. case BUTTON_ETC:
  482. lpttt->lpszText = "Configure";
  483. return TRUE;
  484. case CHECK_TTSSH:
  485. lpttt->lpszText = "use SSH";
  486. return TRUE;
  487. }
  488. }
  489. return FALSE;
  490. }
  491. /* ==========================================================================
  492. Function Name : (void) PopupMenu()
  493. Outline : メインのポップアップメニューを表示する。
  494. Arguments : HWND hWnd (In) 親ウインドウのハンドル
  495. Return Value : なし
  496. Reference :
  497. Renewal :
  498. Notes :
  499. Attention :
  500. Up Date :
  501. ======1=========2=========3=========4=========5=========6=========7======= */
  502. void PopupMenu(HWND hWnd)
  503. {
  504. POINT Point;
  505. GetCursorPos(&Point);
  506. ::SetForceForegroundWindow(hWnd);
  507. // マルチモニタ環境では LOWORD(), HIWORD() を使ってはいけない。(2005.10.13 yutaka)
  508. ::TrackPopupMenu(g_hSubMenu,
  509. TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  510. Point.x,
  511. Point.y,
  512. 0,
  513. hWnd,
  514. NULL);
  515. }
  516. /* ==========================================================================
  517. Function Name : (void) PopupListMenu()
  518. Outline : 設定一覧のポップアップメニューを表示する。
  519. Arguments : HWND hWnd (In) 親ウインドウのハンドル
  520. Return Value : なし
  521. Reference :
  522. Renewal :
  523. Notes :
  524. Attention :
  525. Up Date :
  526. ======1=========2=========3=========4=========5=========6=========7======= */
  527. void PopupListMenu(HWND hWnd)
  528. {
  529. POINT Point;
  530. GetCursorPos(&Point);
  531. ::SetForceForegroundWindow(hWnd);
  532. // マルチモニタ環境では LOWORD(), HIWORD() を使ってはいけない。(2005.10.13 yutaka)
  533. ::TrackPopupMenu(g_hListMenu,
  534. TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  535. Point.x,
  536. Point.y,
  537. 0,
  538. hWnd,
  539. NULL);
  540. }
  541. /* ==========================================================================
  542. Function Name : (BOOL) InitListBox()
  543. Outline : 設定ダイアログ内の設定一覧リストボックスを初期化する。
  544. Arguments : HWND hWnd (In) ダイアログのハンドル
  545. Return Value : 成功 TRUE
  546. Reference :
  547. Renewal :
  548. Notes :
  549. Attention :
  550. Up Date :
  551. ======1=========2=========3=========4=========5=========6=========7======= */
  552. BOOL InitListBox(HWND hWnd)
  553. {
  554. char szPath[MAX_PATH];
  555. DWORD dwCnt = 0;
  556. DWORD dwIndex = 0;
  557. ::SendDlgItemMessage(hWnd, LIST_HOST, LB_RESETCONTENT, 0, 0);
  558. while (::lstrlen(g_MenuData.szName[dwIndex]) != 0) {
  559. if (GetApplicationFilename(g_MenuData.szName[dwIndex], szPath) == TRUE) {
  560. ::SendDlgItemMessage(hWnd, LIST_HOST, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR) g_MenuData.szName[dwIndex]);
  561. ::SendDlgItemMessage(hWnd, LIST_HOST, LB_SETITEMDATA, (WPARAM) dwCnt, (LPARAM) dwIndex);
  562. dwCnt++;
  563. }
  564. dwIndex++;
  565. }
  566. return TRUE;
  567. }
  568. void init_password_control(HWND dlg, int item)
  569. {
  570. HWND passwordControl = GetDlgItem(dlg, item);
  571. SetWindowLong(passwordControl, GWL_USERDATA,
  572. SetWindowLong(passwordControl, GWL_WNDPROC,
  573. (LONG) password_wnd_proc));
  574. }
  575. /* ==========================================================================
  576. Function Name : (BOOL) InitConfigDlg()
  577. Outline : 設定ダイアログを初期化する。
  578. Arguments : HWND hWnd (In) ダイアログのハンドル
  579. Return Value : 成功 TRUE
  580. Reference :
  581. Renewal :
  582. Notes :
  583. Attention :
  584. Up Date :
  585. ======1=========2=========3=========4=========5=========6=========7======= */
  586. BOOL InitConfigDlg(HWND hWnd)
  587. {
  588. HICON g_hIconLeft;
  589. HICON g_hIconRight;
  590. LOGFONT logfont;
  591. HFONT font;
  592. char uimsg[MAX_UIMSG], uitmp[MAX_UIMSG];
  593. font = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
  594. GetObject(font, sizeof(LOGFONT), &logfont);
  595. if (get_lang_font("DLG_TAHOMA_FONT", hWnd, &logfont, &g_ConfigFont, UILanguageFile)) {
  596. SendDlgItemMessage(hWnd, LBL_LIST, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  597. SendDlgItemMessage(hWnd, LIST_HOST, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  598. SendDlgItemMessage(hWnd, GRP_CONFIG, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  599. SendDlgItemMessage(hWnd, LBL_ENTRY, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  600. SendDlgItemMessage(hWnd, EDIT_ENTRY, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  601. SendDlgItemMessage(hWnd, GRP_LAUNCH, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  602. SendDlgItemMessage(hWnd, RADIO_LOGIN, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  603. SendDlgItemMessage(hWnd, LBL_HOST, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  604. SendDlgItemMessage(hWnd, EDIT_HOST, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  605. SendDlgItemMessage(hWnd, CHECK_USER, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  606. SendDlgItemMessage(hWnd, EDIT_USER, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  607. SendDlgItemMessage(hWnd, CHECK_PASSWORD, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  608. SendDlgItemMessage(hWnd, EDIT_PASSWORD, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  609. SendDlgItemMessage(hWnd, RADIO_MACRO, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  610. SendDlgItemMessage(hWnd, EDIT_MACRO, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  611. SendDlgItemMessage(hWnd, BUTTON_MACRO, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  612. SendDlgItemMessage(hWnd, RADIO_DIRECT, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  613. SendDlgItemMessage(hWnd, BUTTON_ETC, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  614. SendDlgItemMessage(hWnd, CHECK_STARTUP, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  615. SendDlgItemMessage(hWnd, CHECK_TTSSH, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  616. SendDlgItemMessage(hWnd, IDC_KEYFILE_LABEL, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  617. SendDlgItemMessage(hWnd, IDC_KEYFILE_PATH, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  618. SendDlgItemMessage(hWnd, IDC_KEYFILE_BUTTON, WM_SETFONT, (WPARAM)g_ConfigFont, MAKELPARAM(TRUE,0));
  619. }
  620. else {
  621. g_ConfigFont = NULL;
  622. }
  623. GetWindowText(hWnd, uitmp, sizeof(uitmp));
  624. UTIL_get_lang_msg("DLG_CONFIG_TITLE", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  625. SetWindowText(hWnd, uimsg);
  626. GetDlgItemText(hWnd, LBL_LIST, uitmp, sizeof(uitmp));
  627. UTIL_get_lang_msg("DLG_CONFIG_ITEM", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  628. SetDlgItemText(hWnd, LBL_LIST, uimsg);
  629. GetDlgItemText(hWnd, GRP_CONFIG, uitmp, sizeof(uitmp));
  630. UTIL_get_lang_msg("DLG_CONFIG_CONFIG", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  631. SetDlgItemText(hWnd, GRP_CONFIG, uimsg);
  632. GetDlgItemText(hWnd, LBL_ENTRY, uitmp, sizeof(uitmp));
  633. UTIL_get_lang_msg("DLG_CONFIG_NAME", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  634. SetDlgItemText(hWnd, LBL_ENTRY, uimsg);
  635. GetDlgItemText(hWnd, GRP_LAUNCH, uitmp, sizeof(uitmp));
  636. UTIL_get_lang_msg("DLG_CONFIG_PATTERN", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  637. SetDlgItemText(hWnd, GRP_LAUNCH, uimsg);
  638. GetDlgItemText(hWnd, RADIO_LOGIN, uitmp, sizeof(uitmp));
  639. UTIL_get_lang_msg("DLG_CONFIG_AUTO", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  640. SetDlgItemText(hWnd, RADIO_LOGIN, uimsg);
  641. GetDlgItemText(hWnd, LBL_HOST, uitmp, sizeof(uitmp));
  642. UTIL_get_lang_msg("DLG_CONFIG_HOST", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  643. SetDlgItemText(hWnd, LBL_HOST, uimsg);
  644. GetDlgItemText(hWnd, CHECK_USER, uitmp, sizeof(uitmp));
  645. UTIL_get_lang_msg("DLG_CONFIG_USER", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  646. SetDlgItemText(hWnd, CHECK_USER, uimsg);
  647. GetDlgItemText(hWnd, CHECK_PASSWORD, uitmp, sizeof(uitmp));
  648. UTIL_get_lang_msg("DLG_CONFIG_PASS", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  649. SetDlgItemText(hWnd, CHECK_PASSWORD, uimsg);
  650. GetDlgItemText(hWnd, RADIO_MACRO, uitmp, sizeof(uitmp));
  651. UTIL_get_lang_msg("DLG_CONFIG_MACRO", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  652. SetDlgItemText(hWnd, RADIO_MACRO, uimsg);
  653. GetDlgItemText(hWnd, RADIO_DIRECT, uitmp, sizeof(uitmp));
  654. UTIL_get_lang_msg("DLG_CONFIG_LAUNCH", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  655. SetDlgItemText(hWnd, RADIO_DIRECT, uimsg);
  656. GetDlgItemText(hWnd, CHECK_STARTUP, uitmp, sizeof(uitmp));
  657. UTIL_get_lang_msg("DLG_CONFIG_STARTUP", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  658. SetDlgItemText(hWnd, CHECK_STARTUP, uimsg);
  659. GetDlgItemText(hWnd, CHECK_TTSSH, uitmp, sizeof(uitmp));
  660. UTIL_get_lang_msg("DLG_CONFIG_SSH", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  661. SetDlgItemText(hWnd, CHECK_TTSSH, uimsg);
  662. GetDlgItemText(hWnd, IDC_KEYFILE_LABEL, uitmp, sizeof(uitmp));
  663. UTIL_get_lang_msg("DLG_CONFIG_KEYFILE", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  664. SetDlgItemText(hWnd, IDC_KEYFILE_LABEL, uimsg);
  665. GetDlgItemText(hWnd, IDC_CHALLENGE_CHECK, uitmp, sizeof(uitmp));
  666. UTIL_get_lang_msg("DLG_CONFIG_CHALLENGE", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  667. SetDlgItemText(hWnd, IDC_CHALLENGE_CHECK, uimsg);
  668. GetDlgItemText(hWnd, IDC_PAGEANT_CHECK, uitmp, sizeof(uitmp));
  669. UTIL_get_lang_msg("DLG_CONFIG_PAGEANT", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  670. SetDlgItemText(hWnd, IDC_PAGEANT_CHECK, uimsg);
  671. GetDlgItemText(hWnd, BUTTON_ETC, uitmp, sizeof(uitmp));
  672. UTIL_get_lang_msg("DLG_CONFIG_DETAIL", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  673. SetDlgItemText(hWnd, BUTTON_ETC, uimsg);
  674. init_password_control(hWnd, EDIT_PASSWORD);
  675. memset(&g_JobInfo, 0, sizeof(JobInfo));
  676. ::DeleteMenu(::GetSystemMenu(hWnd, FALSE), SC_MAXIMIZE, MF_BYCOMMAND);
  677. ::DeleteMenu(::GetSystemMenu(hWnd, FALSE), SC_SIZE, MF_BYCOMMAND);
  678. g_hIconLeft = ::LoadIcon(g_hI, (LPCSTR)ICON_LEFT);
  679. g_hIconRight = ::LoadIcon(g_hI, (LPCSTR)ICON_RIGHT);
  680. ::SendDlgItemMessage(hWnd, BUTTON_SET, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM)(HANDLE) g_hIconLeft);
  681. ::SendDlgItemMessage(hWnd, BUTTON_DELETE, BM_SETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM)(HANDLE) g_hIconRight);
  682. ::CheckRadioButton(hWnd, RADIO_LOGIN, RADIO_MACRO, RADIO_LOGIN);
  683. EnableItem(hWnd, EDIT_MACRO, FALSE);
  684. EnableItem(hWnd, BUTTON_MACRO, FALSE);
  685. ::CheckDlgButton(hWnd, CHECK_USER, 1);
  686. ::CheckDlgButton(hWnd, CHECK_PASSWORD, 1);
  687. ::CheckDlgButton(hWnd, CHECK_INI_FILE, 1);
  688. InitListBox(hWnd);
  689. return TRUE;
  690. }
  691. /* ==========================================================================
  692. Function Name : (BOOL) InitEtcDlg()
  693. Outline : 詳細設定ダイアログを初期化する。
  694. Arguments : HWND hWnd (In) ダイアログのハンドル
  695. Return Value : 成功 TRUE
  696. Reference :
  697. Renewal :
  698. Notes :
  699. Attention :
  700. Up Date :
  701. ======1=========2=========3=========4=========5=========6=========7======= */
  702. BOOL InitEtcDlg(HWND hWnd)
  703. {
  704. char szDefault[MAX_PATH] = DEFAULT_PATH;
  705. char szTTermPath[MAX_PATH];
  706. LOGFONT logfont;
  707. HFONT font;
  708. char uimsg[MAX_UIMSG], uitmp[MAX_UIMSG];
  709. font = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
  710. GetObject(font, sizeof(LOGFONT), &logfont);
  711. if (get_lang_font("DLG_TAHOMA_FONT", hWnd, &logfont, &g_DetailFont, UILanguageFile)) {
  712. SendDlgItemMessage(hWnd, LBL_TTMPATH, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  713. SendDlgItemMessage(hWnd, EDIT_TTMPATH, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  714. SendDlgItemMessage(hWnd, BUTTON_TTMPATH, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  715. SendDlgItemMessage(hWnd, LBL_OPTION, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  716. SendDlgItemMessage(hWnd, EDIT_OPTION, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  717. SendDlgItemMessage(hWnd, GRP_INITFILE, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  718. SendDlgItemMessage(hWnd, EDIT_INITFILE, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  719. SendDlgItemMessage(hWnd, BUTTON_INITFILE, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  720. SendDlgItemMessage(hWnd, GRP_AUTOLOGIN, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  721. SendDlgItemMessage(hWnd, LBL_LOG, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  722. SendDlgItemMessage(hWnd, EDIT_LOG, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  723. SendDlgItemMessage(hWnd, BUTTON_LOG, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  724. SendDlgItemMessage(hWnd, GRP_PROMPT, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  725. SendDlgItemMessage(hWnd, LBL_PROMPT_USER, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  726. SendDlgItemMessage(hWnd, EDIT_PROMPT_USER, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  727. SendDlgItemMessage(hWnd, LBL_PROMPT_PASS, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  728. SendDlgItemMessage(hWnd, EDIT_PROMPT_PASS, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  729. SendDlgItemMessage(hWnd, IDOK, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  730. SendDlgItemMessage(hWnd, BUTTON_DEFAULT, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0));
  731. SendDlgItemMessage(hWnd, IDCANCEL, WM_SETFONT, (WPARAM)g_DetailFont, MAKELPARAM(TRUE,0)); }
  732. else {
  733. g_DetailFont = NULL;
  734. }
  735. GetWindowText(hWnd, uitmp, sizeof(uitmp));
  736. UTIL_get_lang_msg("DLG_ETC_TITLE", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  737. SetWindowText(hWnd, uimsg);
  738. GetDlgItemText(hWnd, LBL_TTMPATH, uitmp, sizeof(uitmp));
  739. UTIL_get_lang_msg("DLG_ETC_APP", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  740. SetDlgItemText(hWnd, LBL_TTMPATH, uimsg);
  741. GetDlgItemText(hWnd, LBL_OPTION, uitmp, sizeof(uitmp));
  742. UTIL_get_lang_msg("DLG_ETC_OPTION", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  743. SetDlgItemText(hWnd, LBL_OPTION, uimsg);
  744. GetDlgItemText(hWnd, GRP_INITFILE, uitmp, sizeof(uitmp));
  745. UTIL_get_lang_msg("DLG_ETC_CONFIG", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  746. SetDlgItemText(hWnd, GRP_INITFILE, uimsg);
  747. GetDlgItemText(hWnd, GRP_AUTOLOGIN, uitmp, sizeof(uitmp));
  748. UTIL_get_lang_msg("DLG_ETC_AUTO", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  749. SetDlgItemText(hWnd, GRP_AUTOLOGIN, uimsg);
  750. GetDlgItemText(hWnd, LBL_LOG, uitmp, sizeof(uitmp));
  751. UTIL_get_lang_msg("DLG_ETC_LOGFILE", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  752. SetDlgItemText(hWnd, LBL_LOG, uimsg);
  753. GetDlgItemText(hWnd, GRP_PROMPT, uitmp, sizeof(uitmp));
  754. UTIL_get_lang_msg("DLG_ETC_PROMPT", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  755. SetDlgItemText(hWnd, GRP_PROMPT, uimsg);
  756. GetDlgItemText(hWnd, LBL_PROMPT_USER, uitmp, sizeof(uitmp));
  757. UTIL_get_lang_msg("DLG_ETC_USER", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  758. SetDlgItemText(hWnd, LBL_PROMPT_USER, uimsg);
  759. GetDlgItemText(hWnd, LBL_PROMPT_PASS, uitmp, sizeof(uitmp));
  760. UTIL_get_lang_msg("DLG_ETC_PASS", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  761. SetDlgItemText(hWnd, LBL_PROMPT_PASS, uimsg);
  762. GetDlgItemText(hWnd, BUTTON_DEFAULT, uitmp, sizeof(uitmp));
  763. UTIL_get_lang_msg("BTN_DEFAULT", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  764. SetDlgItemText(hWnd, BUTTON_DEFAULT, uimsg);
  765. GetDlgItemText(hWnd, IDOK, uitmp, sizeof(uitmp));
  766. UTIL_get_lang_msg("BTN_OK", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  767. SetDlgItemText(hWnd, IDOK, uimsg);
  768. GetDlgItemText(hWnd, IDCANCEL, uitmp, sizeof(uitmp));
  769. UTIL_get_lang_msg("BTN_CANCEL", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  770. SetDlgItemText(hWnd, IDCANCEL, uimsg);
  771. if (::lstrlen(g_JobInfo.szTeraTerm) == 0) {
  772. ::GetProfileString("Tera Term Pro", "Path", szDefault, szTTermPath, MAX_PATH);
  773. ::wsprintf(g_JobInfo.szTeraTerm, "%s\\%s", szTTermPath, g_JobInfo.bTtssh ? TTSSH : TERATERM);
  774. }
  775. if (g_JobInfo.bTtssh == TRUE && lstrstri(g_JobInfo.szTeraTerm, TTSSH) == NULL)
  776. ::wsprintf(g_JobInfo.szTeraTerm, "%s\\%s", szTTermPath, TTSSH);
  777. if (::lstrlen(g_JobInfo.szLoginPrompt) == 0) {
  778. ::lstrcpy(g_JobInfo.szLoginPrompt, LOGIN_PROMPT);
  779. }
  780. if (::lstrlen(g_JobInfo.szPasswdPrompt) == 0) {
  781. ::lstrcpy(g_JobInfo.szPasswdPrompt, PASSWORD_PROMPT);
  782. }
  783. ::SetDlgItemText(hWnd, EDIT_TTMPATH, g_JobInfo.szTeraTerm);
  784. ::SetDlgItemText(hWnd, EDIT_INITFILE, g_JobInfo.szInitFile);
  785. ::SetDlgItemText(hWnd, EDIT_OPTION, g_JobInfo.szOption);
  786. ::SetDlgItemText(hWnd, EDIT_PROMPT_USER, g_JobInfo.szLoginPrompt);
  787. ::SetDlgItemText(hWnd, EDIT_PROMPT_PASS, g_JobInfo.szPasswdPrompt);
  788. ::SetDlgItemText(hWnd, EDIT_LOG, g_JobInfo.szLog);
  789. return TRUE;
  790. }
  791. /* ==========================================================================
  792. Function Name : (BOOL) InitVersionDlg()
  793. Outline : 「バージョン情報」ダイアログを初期化する。
  794. Arguments : HWND hWnd (In) ダイアログのハンドル
  795. Return Value : 成功 TRUE
  796. Reference :
  797. Renewal :
  798. Notes :
  799. Attention :
  800. Up Date :
  801. ======1=========2=========3=========4=========5=========6=========7======= */
  802. BOOL InitVersionDlg(HWND hWnd)
  803. {
  804. int a, b, c, d;
  805. char app[_MAX_PATH], buf[1024], buf2[1024];
  806. LOGFONT logfont;
  807. HFONT font;
  808. char uimsg[MAX_UIMSG], uitmp[MAX_UIMSG];
  809. font = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
  810. GetObject(font, sizeof(LOGFONT), &logfont);
  811. if (get_lang_font("DLG_TAHOMA_FONT", hWnd, &logfont, &g_AboutFont, UILanguageFile)) {
  812. SendDlgItemMessage(hWnd, IDC_VERSION, WM_SETFONT, (WPARAM)g_AboutFont, MAKELPARAM(TRUE,0));
  813. SendDlgItemMessage(hWnd, IDC_INCLUDE, WM_SETFONT, (WPARAM)g_AboutFont, MAKELPARAM(TRUE,0));
  814. }
  815. else {
  816. g_AboutFont = NULL;
  817. }
  818. GetWindowText(hWnd, uitmp, sizeof(uitmp));
  819. UTIL_get_lang_msg("DLG_ABOUT_TITLE", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  820. SetWindowText(hWnd, uimsg);
  821. GetDlgItemText(hWnd, IDOK, uitmp, sizeof(uitmp));
  822. UTIL_get_lang_msg("BTN_OK", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  823. SetDlgItemText(hWnd, IDOK, uimsg);
  824. ::DeleteMenu(::GetSystemMenu(hWnd, FALSE), SC_MAXIMIZE, MF_BYCOMMAND);
  825. ::DeleteMenu(::GetSystemMenu(hWnd, FALSE), SC_SIZE, MF_BYCOMMAND);
  826. ::DeleteMenu(::GetSystemMenu(hWnd, FALSE), SC_MINIMIZE, MF_BYCOMMAND);
  827. ::DeleteMenu(::GetSystemMenu(hWnd, FALSE), SC_RESTORE, MF_BYCOMMAND);
  828. GetModuleFileName(NULL, app, sizeof(app));
  829. get_file_version(app, &a, &b, &c, &d);
  830. UTIL_get_lang_msg("DLG_ABOUT_APPNAME", uimsg, sizeof(uimsg), "launch tool", UILanguageFile);
  831. GetDlgItemText(hWnd, IDC_VERSION, buf, sizeof(buf));
  832. _snprintf(buf2, sizeof(buf2), buf, uimsg, a, b);
  833. SetDlgItemText(hWnd, IDC_VERSION, buf2);
  834. return TRUE;
  835. }
  836. /* ==========================================================================
  837. Function Name : (BOOL) SetDefaultEtcDlg()
  838. Outline : 詳細設定ダイアログの各項目にデフォルト値を設定する。
  839. Arguments : HWND hWnd (In) ダイアログのハンドル
  840. Return Value : 成功 TRUE
  841. Reference :
  842. Renewal :
  843. Notes :
  844. Attention :
  845. Up Date :
  846. ======1=========2=========3=========4=========5=========6=========7======= */
  847. BOOL SetDefaultEtcDlg(HWND hWnd)
  848. {
  849. char szDefault[MAX_PATH] = DEFAULT_PATH;
  850. char szTTermPath[MAX_PATH];
  851. ::GetProfileString("Tera Term Pro", "Path", szDefault, szTTermPath, MAX_PATH);
  852. ::wsprintf(szTTermPath, "%s\\%s", szTTermPath, g_JobInfo.bTtssh ? TTSSH : TERATERM);
  853. ::SetDlgItemText(hWnd, EDIT_TTMPATH, szTTermPath);
  854. ::SetDlgItemText(hWnd, EDIT_INITFILE, "");
  855. // デフォルトオプションに /KT , /KR を追加 (2005.1.25 yutaka)
  856. ::SetDlgItemText(hWnd, EDIT_OPTION, "/KT=UTF8 /KR=UTF8");
  857. // ::SetDlgItemText(hWnd, EDIT_OPTION, "");
  858. ::SetDlgItemText(hWnd, EDIT_PROMPT_USER, LOGIN_PROMPT);
  859. ::SetDlgItemText(hWnd, EDIT_PROMPT_PASS, PASSWORD_PROMPT);
  860. return TRUE;
  861. }
  862. /* ==========================================================================
  863. Function Name : (BOOL) SetTaskTray()
  864. Outline : タスクトレイにアイコンを登録/削除する。
  865. Arguments : HWND hWnd (In) ウインドウのハンドル
  866. : DWORD dwMessage (In) Shell_NotifyIconの第一引数
  867. Return Value : 成功 TRUE
  868. Reference :
  869. Renewal :
  870. Notes :
  871. Attention :
  872. Up Date :
  873. ======1=========2=========3=========4=========5=========6=========7======= */
  874. BOOL SetTaskTray(HWND hWnd, DWORD dwMessage)
  875. {
  876. NOTIFYICONDATA nid;
  877. int i;
  878. BOOL ret;
  879. DWORD ecode;
  880. memset(&nid, 0, sizeof(nid));
  881. nid.cbSize = sizeof(nid);
  882. nid.hWnd = hWnd;
  883. nid.uID = TTERM_ICON;
  884. nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
  885. nid.uCallbackMessage = WM_TMENU_NOTIFY;
  886. nid.hIcon = g_hIconSmall;
  887. lstrcpy(nid.szTip, "TeraTerm Menu");
  888. /* Shell_NotifyIcon関数は、シェルへの登録が4秒以内に完了しないとエラーと見なすため、
  889. * リトライ処理を追加する。
  890. *
  891. * Microsoft公式情報によると、WindowsXP〜7までが当該仕様の模様。Windows8/8.1では、
  892. * リトライは不要と思われるが、共通処置とする。
  893. * cf. http://support.microsoft.com/kb/418138/ja
  894. * (2014.6.21 yutaka)
  895. */
  896. if (dwMessage == NIM_ADD) {
  897. for (i = 0 ; i < 10 ; i++) {
  898. ret = ::Shell_NotifyIcon(dwMessage, &nid);
  899. ecode = GetLastError();
  900. if (ret == FALSE && ecode == ERROR_TIMEOUT) {
  901. Sleep(1000);
  902. ret = ::Shell_NotifyIcon(NIM_MODIFY, &nid);
  903. if (ret == TRUE)
  904. break;
  905. } else {
  906. break;
  907. }
  908. }
  909. } else {
  910. ::Shell_NotifyIcon(dwMessage, &nid);
  911. }
  912. return TRUE;
  913. }
  914. /* ==========================================================================
  915. Function Name : (BOOL) MakeTTL()
  916. Outline : 自動ログイン用マクロファイルを生成する。
  917. Arguments : char *TTLName (In) マクロファイル名
  918. : JobInfo JobInfo (In) 設定情報構造体
  919. Return Value : 成功 TRUE / 失敗 FALSE
  920. Reference :
  921. Renewal :
  922. Notes :
  923. Attention :
  924. Up Date :
  925. ======1=========2=========3=========4=========5=========6=========7======= */
  926. BOOL MakeTTL(char *TTLName, JobInfo *jobInfo)
  927. {
  928. char buf[1024];
  929. DWORD dwWrite;
  930. HANDLE hFile;
  931. hFile = ::CreateFile(TTLName,
  932. GENERIC_WRITE,
  933. FILE_SHARE_WRITE | FILE_SHARE_READ,
  934. NULL,
  935. CREATE_ALWAYS,
  936. FILE_ATTRIBUTE_NORMAL,
  937. NULL);
  938. if (hFile == INVALID_HANDLE_VALUE)
  939. return FALSE;
  940. ::wsprintf(buf, "filedelete '%s'\r\n", TTLName);
  941. ::WriteFile(hFile, buf, ::lstrlen(buf), &dwWrite, NULL);
  942. if (::lstrlen(jobInfo->szLog) != 0) {
  943. ::wsprintf(buf, "logopen '%s' 0 1\r\n", jobInfo->szLog);
  944. ::WriteFile(hFile, buf, ::lstrlen(buf), &dwWrite, NULL);
  945. }
  946. // telnetポート番号を付加する (2004.12.3 yutaka)
  947. ::wsprintf(buf, "connect '%s:23'\r\n", jobInfo->szHostName);
  948. ::WriteFile(hFile, buf, ::lstrlen(buf), &dwWrite, NULL);
  949. if (jobInfo->bUsername == TRUE) {
  950. if (::lstrlen(jobInfo->szLoginPrompt) == 0)
  951. ::lstrcpy(jobInfo->szLoginPrompt, LOGIN_PROMPT);
  952. ::wsprintf(buf, "UsernamePrompt = '%s'\r\nUsername = '%s'\r\n", jobInfo->szLoginPrompt, jobInfo->szUsername);
  953. ::WriteFile(hFile, buf, ::lstrlen(buf), &dwWrite, NULL);
  954. }
  955. if (jobInfo->bPassword == TRUE) {
  956. if (::lstrlen(jobInfo->szPasswdPrompt) == 0)
  957. ::lstrcpy(jobInfo->szPasswdPrompt, PASSWORD_PROMPT);
  958. ::wsprintf(buf, "PasswordPrompt = '%s'\r\nPassword = '%s'\r\n", jobInfo->szPasswdPrompt, jobInfo->szPassword);
  959. ::WriteFile(hFile, buf, ::lstrlen(buf), &dwWrite, NULL);
  960. }
  961. if (jobInfo->bUsername == TRUE) {
  962. ::wsprintf(buf, "wait UsernamePrompt\r\nsendln Username\r\n");
  963. ::WriteFile(hFile, buf, ::lstrlen(buf), &dwWrite, NULL);
  964. }
  965. if (jobInfo->bPassword == TRUE) {
  966. ::wsprintf(buf, "wait PasswordPrompt\r\nsendln Password\r\n");
  967. ::WriteFile(hFile, buf, ::lstrlen(buf), &dwWrite, NULL);
  968. }
  969. ::CloseHandle(hFile);
  970. return TRUE;
  971. }
  972. static void _dquote_string(char *str, char *dst, int dst_len)
  973. {
  974. int i, len, n;
  975. len = strlen(str);
  976. n = 0;
  977. for (i = 0 ; i < len ; i++) {
  978. if (str[i] == '"')
  979. n++;
  980. }
  981. if (dst_len < (len + 2*n + 2 + 1))
  982. return;
  983. *dst++ = '"';
  984. for (i = 0 ; i < len ; i++) {
  985. if (str[i] == '"') {
  986. *dst++ = '"';
  987. *dst++ = '"';
  988. } else {
  989. *dst++ = str[i];
  990. }
  991. }
  992. *dst++ = '"';
  993. *dst = '\0';
  994. }
  995. static void dquote_string(char *str, char *dst, int dst_len)
  996. {
  997. // ",スペース,;,^A-^_ が含まれる場合にはクオートする
  998. if (strchr(str, '"') != NULL ||
  999. strchr(str, ' ') != NULL ||
  1000. strchr(str, ';') != NULL ||
  1001. strchr(str, 0x01) != NULL ||
  1002. strchr(str, 0x02) != NULL ||
  1003. strchr(str, 0x03) != NULL ||
  1004. strchr(str, 0x04) != NULL ||
  1005. strchr(str, 0x05) != NULL ||
  1006. strchr(str, 0x06) != NULL ||
  1007. strchr(str, 0x07) != NULL ||
  1008. strchr(str, 0x08) != NULL ||
  1009. strchr(str, 0x09) != NULL ||
  1010. strchr(str, 0x0a) != NULL ||
  1011. strchr(str, 0x0b) != NULL ||
  1012. strchr(str, 0x0c) != NULL ||
  1013. strchr(str, 0x0d) != NULL ||
  1014. strchr(str, 0x0e) != NULL ||
  1015. strchr(str, 0x0f) != NULL ||
  1016. strchr(str, 0x10) != NULL ||
  1017. strchr(str, 0x11) != NULL ||
  1018. strchr(str, 0x12) != NULL ||
  1019. strchr(str, 0x13) != NULL ||
  1020. strchr(str, 0x14) != NULL ||
  1021. strchr(str, 0x15) != NULL ||
  1022. strchr(str, 0x16) != NULL ||
  1023. strchr(str, 0x17) != NULL ||
  1024. strchr(str, 0x18) != NULL ||
  1025. strchr(str, 0x19) != NULL ||
  1026. strchr(str, 0x1a) != NULL ||
  1027. strchr(str, 0x1b) != NULL ||
  1028. strchr(str, 0x1c) != NULL ||
  1029. strchr(str, 0x1d) != NULL ||
  1030. strchr(str, 0x1e) != NULL ||
  1031. strchr(str, 0x1f) != NULL) {
  1032. _dquote_string(str, dst, dst_len);
  1033. return;
  1034. }
  1035. // そのままコピーして戻る
  1036. strncpy_s(dst, dst_len, str, _TRUNCATE);
  1037. }
  1038. /* ==========================================================================
  1039. Function Name : (BOOL) ConnectHost()
  1040. Outline : 自動ログインまたはアプリケーションの実行をする。
  1041. Arguments : HWND hWnd (In) ウインドウのハンドル
  1042. : UINT idItem (In) 選択されたコントロールID
  1043. : char *szJobName (In) 実行するジョブ
  1044. Return Value : 成功 TRUE / 失敗 FALSE
  1045. Reference :
  1046. Renewal :
  1047. Notes :
  1048. Attention :
  1049. Up Date :
  1050. ======1=========2=========3=========4=========5=========6=========7======= */
  1051. BOOL ConnectHost(HWND hWnd, UINT idItem, char *szJobName)
  1052. {
  1053. char szName[MAX_PATH];
  1054. char szDefault[MAX_PATH] = DEFAULT_PATH;
  1055. char szDirectory[MAX_PATH];
  1056. char szHostName[MAX_PATH];
  1057. char szTempPath[MAX_PATH];
  1058. char szMacroFile[MAX_PATH];
  1059. char szArgment[MAX_PATH] = "";
  1060. char *pHostName;
  1061. TCHAR *pt;
  1062. JobInfo jobInfo;
  1063. char cur[MAX_PATH], modulePath[MAX_PATH], fullpath[MAX_PATH];
  1064. DWORD dwErr;
  1065. char uimsg[MAX_UIMSG];
  1066. ::lstrcpy(szName, (szJobName == NULL) ? g_MenuData.szName[idItem - ID_MENU_MIN] : szJobName);
  1067. if (RegLoadLoginHostInformation(szName, &jobInfo) == FALSE) {
  1068. dwErr = ::GetLastError();
  1069. UTIL_get_lang_msg("MSG_ERROR_MAKETTL", uimsg, sizeof(uimsg),
  1070. "Couldn't read the registry data.\n", UILanguageFile);
  1071. ErrorMessage(hWnd, dwErr, uimsg);
  1072. return FALSE;
  1073. }
  1074. if (szJobName != NULL && jobInfo.bStartup == FALSE)
  1075. return TRUE;
  1076. if (::lstrlen(jobInfo.szTeraTerm) == 0) {
  1077. ::GetProfileString("Tera Term Pro", "Path", szDefault, jobInfo.szTeraTerm, MAX_PATH);
  1078. ::wsprintf(jobInfo.szTeraTerm, "%s\\%s", jobInfo.szTeraTerm, jobInfo.bTtssh ? TTSSH : TERATERM);
  1079. }
  1080. ::lstrcpy(szHostName, jobInfo.szHostName);
  1081. if ((pHostName = _tcstok(szHostName, _T(" ([{'\"|*"))) != NULL)
  1082. pHostName = szHostName;
  1083. if (jobInfo.dwMode != MODE_DIRECT)
  1084. if (::lstrlen(jobInfo.szInitFile) != 0)
  1085. ::wsprintf(szArgment, "/F=\"%s\"", jobInfo.szInitFile);
  1086. switch (jobInfo.dwMode) {
  1087. case MODE_AUTOLOGIN:
  1088. ::GetTempPath(MAX_PATH, szTempPath);
  1089. ::GetTempFileName(szTempPath, "ttm", 0, szMacroFile);
  1090. if (MakeTTL(szMacroFile, &jobInfo) == FALSE) {
  1091. dwErr = ::GetLastError();
  1092. UTIL_get_lang_msg("MSG_ERROR_MAKETTL", uimsg, sizeof(uimsg),
  1093. "Could not make 'ttpmenu.TTL'\n", UILanguageFile);
  1094. ErrorMessage(hWnd, dwErr, uimsg);
  1095. return FALSE;
  1096. }
  1097. break;
  1098. case MODE_MACRO:
  1099. ::lstrcpy(szMacroFile, jobInfo.szMacroFile);
  1100. break;
  1101. }
  1102. // SSH自動ログインの場合はマクロは不要 (2005.1.25 yutaka)
  1103. if (jobInfo.bTtssh != TRUE) {
  1104. if (jobInfo.dwMode != MODE_DIRECT)
  1105. ::wsprintf(szArgment, "%s /M=\"%s\"", szArgment, szMacroFile);
  1106. }
  1107. if (::lstrlen(jobInfo.szOption) != 0)
  1108. ::wsprintf(szArgment, "%s %s", szArgment, jobInfo.szOption);
  1109. // TTSSHが有効の場合は、自動ログインのためのコマンドラインを付加する。(2004.12.3 yutaka)
  1110. // ユーザのパラメータを指定できるようにする (2005.1.25 yutaka)
  1111. // 公開鍵認証をサポート (2005.1.27 yutaka)
  1112. // /challengeをサポート (2007.11.14 yutaka)
  1113. // /pageantをサポート (2008.5.26 maya)
  1114. if (jobInfo.dwMode == MODE_AUTOLOGIN) {
  1115. if (jobInfo.bTtssh == TRUE) {
  1116. char tmp[MAX_PATH];
  1117. char passwd[MAX_PATH], keyfile[MAX_PATH];
  1118. strcpy(tmp, szArgment);
  1119. dquote_string(jobInfo.szPassword, passwd, sizeof(passwd));
  1120. dquote_string(jobInfo.PrivateKeyFile, keyfile, sizeof(keyfile));
  1121. if (jobInfo.bChallenge) { // keyboard-interactive
  1122. _snprintf(szArgment, sizeof(szArgment), "%s:22 /ssh /auth=challenge /user=%s /passwd=%s %s",
  1123. jobInfo.szHostName,
  1124. jobInfo.szUsername,
  1125. passwd,
  1126. tmp
  1127. );
  1128. } else if (jobInfo.bPageant) { // Pageant
  1129. _snprintf(szArgment, sizeof(szArgment), "%s:22 /ssh /auth=pageant /user=%s %s",
  1130. jobInfo.szHostName,
  1131. jobInfo.szUsername,
  1132. tmp
  1133. );
  1134. } else if (jobInfo.PrivateKeyFile[0] == NULL) { // password authentication
  1135. _snprintf(szArgment, sizeof(szArgment), "%s:22 /ssh /auth=password /user=%s /passwd=%s %s",
  1136. jobInfo.szHostName,
  1137. jobInfo.szUsername,
  1138. passwd,
  1139. tmp
  1140. );
  1141. } else { // publickey
  1142. _snprintf(szArgment, sizeof(szArgment), "%s:22 /ssh /auth=publickey /user=%s /passwd=%s /keyfile=%s %s",
  1143. jobInfo.szHostName,
  1144. jobInfo.szUsername,
  1145. passwd,
  1146. keyfile,
  1147. tmp
  1148. );
  1149. }
  1150. } else {
  1151. // SSHを使わない場合、/nossh オプションを付けておく。
  1152. ::wsprintf(szArgment, "%s /nossh", szArgment);
  1153. }
  1154. }
  1155. // フルパス化する
  1156. GetCurrentDirectory(sizeof(cur), cur);
  1157. GetModuleFileName(NULL, modulePath, sizeof(modulePath));
  1158. ExtractDirName(modulePath, modulePath);
  1159. SetCurrentDirectory(modulePath);
  1160. _fullpath(fullpath, jobInfo.szTeraTerm, sizeof(fullpath));
  1161. ::lstrcpy(jobInfo.szTeraTerm, fullpath);
  1162. ::lstrcpy(szDirectory, jobInfo.szTeraTerm);
  1163. if ((::GetFileAttributes(jobInfo.szTeraTerm) & FILE_ATTRIBUTE_DIRECTORY) == 0)
  1164. if ((pt = _tcsrchr(szDirectory, '\\')) != NULL)
  1165. *pt = '\0';
  1166. SHELLEXECUTEINFO ExecInfo;
  1167. memset((void *) &ExecInfo, 0, sizeof(SHELLEXECUTEINFO));
  1168. ExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  1169. ExecInfo.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
  1170. ExecInfo.hwnd = hWnd;
  1171. ExecInfo.lpVerb = (LPCSTR) NULL;
  1172. ExecInfo.lpFile = (LPCSTR) jobInfo.szTeraTerm;
  1173. ExecInfo.lpParameters = (LPCSTR) szArgment;
  1174. ExecInfo.lpDirectory = (LPCSTR) szDirectory;
  1175. ExecInfo.nShow = SW_SHOWNORMAL;
  1176. ExecInfo.hInstApp = g_hI;
  1177. if (::ShellExecuteEx(&ExecInfo) == FALSE) {
  1178. dwErr = ::GetLastError();
  1179. UTIL_get_lang_msg("MSG_ERROR_LAUNCH", uimsg, sizeof(uimsg),
  1180. "Launching the application was failure.\n", UILanguageFile);
  1181. ErrorMessage(hWnd, dwErr, uimsg);
  1182. ::DeleteFile(szTempPath);
  1183. }
  1184. if (::lstrlen(jobInfo.szLog) != 0) {
  1185. Sleep(500);
  1186. HWND hLog = ::FindWindow(NULL, "Tera Term: Log");
  1187. if (hLog != NULL)
  1188. ShowWindow(hLog, SW_HIDE);
  1189. }
  1190. SetCurrentDirectory(cur);
  1191. return TRUE;
  1192. }
  1193. /* ==========================================================================
  1194. Function Name : (BOOL) InitMenu()
  1195. Outline : 各ポップアップメニューを作成する。
  1196. Arguments : なし
  1197. Return Value : 成功 TRUE / 失敗 FALSE
  1198. Reference :
  1199. Renewal :
  1200. Notes :
  1201. Attention :
  1202. Up Date :
  1203. ======1=========2=========3=========4=========5=========6=========7======= */
  1204. BOOL InitMenu(void)
  1205. {
  1206. char uimsg[MAX_UIMSG], uitmp[MAX_UIMSG];
  1207. for (int cnt = 0; cnt < MAXJOBNUM; cnt++) {
  1208. g_MenuData.hLargeIcon[cnt] = NULL;
  1209. g_MenuData.hSmallIcon[cnt] = NULL;
  1210. }
  1211. if (g_hListMenu == NULL) {
  1212. g_hMenu = ::LoadMenu(g_hI, (LPCSTR) TTERM_MENU);
  1213. g_hSubMenu = ::GetSubMenu(g_hMenu, 0);
  1214. g_hListMenu = ::CreateMenu();
  1215. g_hConfigMenu = ::GetSubMenu(g_hSubMenu, 1);
  1216. if (g_hMenu == NULL || g_hSubMenu == NULL || g_hListMenu == NULL)
  1217. return FALSE;
  1218. GetMenuString(g_hSubMenu, ID_TMENU_ADD, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1219. UTIL_get_lang_msg("MENU_LISTCONFIG", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1220. ModifyMenu(g_hSubMenu, ID_TMENU_ADD, MF_BYCOMMAND, ID_TMENU_ADD, uimsg);
  1221. GetMenuString(g_hSubMenu, 1, uitmp, sizeof(uitmp), MF_BYPOSITION);
  1222. UTIL_get_lang_msg("MENU_SETTING", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1223. ModifyMenu(g_hSubMenu, 1, MF_BYPOSITION, 1, uimsg);
  1224. GetMenuString(g_hSubMenu, ID_VERSION, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1225. UTIL_get_lang_msg("MENU_VERSION", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1226. ModifyMenu(g_hSubMenu, ID_VERSION, MF_BYCOMMAND, ID_VERSION, uimsg);
  1227. GetMenuString(g_hSubMenu, ID_EXEC, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1228. UTIL_get_lang_msg("MENU_EXEC", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1229. ModifyMenu(g_hSubMenu, ID_EXEC, MF_BYCOMMAND, ID_EXEC, uimsg);
  1230. GetMenuString(g_hSubMenu, ID_TMENU_CLOSE, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1231. UTIL_get_lang_msg("MENU_CLOSE", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1232. ModifyMenu(g_hSubMenu, ID_TMENU_CLOSE, MF_BYCOMMAND, ID_TMENU_CLOSE, uimsg);
  1233. GetMenuString(g_hConfigMenu, ID_ICON, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1234. UTIL_get_lang_msg("MENU_ICON", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1235. ModifyMenu(g_hConfigMenu, ID_ICON, MF_BYCOMMAND, ID_ICON, uimsg);
  1236. GetMenuString(g_hConfigMenu, ID_FONT, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1237. UTIL_get_lang_msg("MENU_FONT", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1238. ModifyMenu(g_hConfigMenu, ID_FONT, MF_BYCOMMAND, ID_FONT, uimsg);
  1239. GetMenuString(g_hConfigMenu, ID_LEFTPOPUP, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1240. UTIL_get_lang_msg("MENU_LEFTPOPUP", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1241. ModifyMenu(g_hConfigMenu, ID_LEFTPOPUP, MF_BYCOMMAND, ID_LEFTPOPUP, uimsg);
  1242. GetMenuString(g_hConfigMenu, ID_HOTKEY, uitmp, sizeof(uitmp), MF_BYCOMMAND);
  1243. UTIL_get_lang_msg("MENU_HOTKEY", uimsg, sizeof(uimsg), uitmp, UILanguageFile);
  1244. ModifyMenu(g_hConfigMenu, ID_HOTKEY, MF_BYCOMMAND, ID_HOTKEY, uimsg);
  1245. UTIL_get_lang_msg("MENU_EXEC", uimsg, sizeof(uimsg), "Execute", UILanguageFile);
  1246. ::ModifyMenu(g_hSubMenu, ID_EXEC, MF_BYCOMMAND | MF_POPUP, (UINT) g_hListMenu, (LPCTSTR) uimsg);
  1247. }
  1248. return TRUE;
  1249. }
  1250. /* ==========================================================================
  1251. Function Name : (VOID) DeleteListMenuIcons()
  1252. Outline : SHGetFileInfo で取り出したアイコンリソースを開放する。
  1253. ポップアップメニューと一覧表示で使用するため、
  1254. 開放できるのは一覧更新直前とプログラム終了時。
  1255. Arguments :
  1256. Return Value :
  1257. Reference :
  1258. Renewal :
  1259. Notes :
  1260. Attention :
  1261. Up Date :
  1262. ======1=========2=========3=========4=========5=========6=========7======= */
  1263. VOID DeleteListMenuIcons()
  1264. {
  1265. for (int cnt = 0; cnt < MAXJOBNUM; cnt++) {
  1266. memset(g_MenuData.szName, 0, MAX_PATH);
  1267. if (g_MenuData.hLargeIcon[cnt] != NULL) {
  1268. ::DestroyIcon(g_MenuData.hLargeIcon[cnt]);
  1269. g_MenuData.hLargeIcon[cnt] = NULL;
  1270. }
  1271. if (g_MenuData.hSmallIcon[cnt] != NULL) {
  1272. ::DestroyIcon(g_MenuData.hSmallIcon[cnt]);
  1273. g_MenuData.hSmallIcon[cnt] = NULL;
  1274. }
  1275. }
  1276. }
  1277. /* ==========================================================================
  1278. Function Name : (BOOL) InitListMenu()
  1279. Outline : 設定一覧ポップアップメニューを初期化する。
  1280. Arguments : HWND hWnd (In) ウインドウのハンドル
  1281. Return Value : 成功 TRUE
  1282. Reference :
  1283. Renewal :
  1284. Notes :
  1285. Attention :
  1286. Up Date :
  1287. ======1=========2=========3=========4=========5=========6=========7======= */
  1288. BOOL InitListMenu(HWND hWnd)
  1289. {
  1290. char szPath[MAX_PATH];
  1291. char szEntryName[MAX_PATH];
  1292. HKEY hKey;
  1293. DWORD dwCnt;
  1294. DWORD dwIndex = 0;
  1295. DWORD dwSize = MAX_PATH;
  1296. DeleteListMenuIcons();
  1297. if ((hKey = RegOpen(HKEY_CURRENT_USER, TTERM_KEY)) != INVALID_HANDLE_VALUE) {
  1298. while (RegEnumEx(hKey, dwIndex, szEntryName, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
  1299. ::lstrcpy(g_MenuData.szName[dwIndex++], szEntryName);
  1300. dwSize = MAX_PATH;
  1301. }
  1302. ::lstrcpy(g_MenuData.szName[dwIndex], "");
  1303. RegClose(hKey);
  1304. for (dwCnt = 0; dwCnt < dwIndex; dwCnt++)
  1305. if (GetApplicationFilename(g_MenuData.szName[dwCnt], szPath) == TRUE)
  1306. ExtractAssociatedIconEx(szPath, &g_MenuData.hLargeIcon[dwCnt], &g_MenuData.hSmallIcon[dwCnt]);
  1307. }
  1308. RedrawMenu(hWnd);
  1309. return TRUE;
  1310. }
  1311. /* ==========================================================================
  1312. Function Name : (BOOL) RedrawMenu()
  1313. Outline : 設定一覧ポップアップメニューを描画する。
  1314. Arguments : HWND hWnd (In) ウインドウのハンドル
  1315. Return Value : 成功 TRUE
  1316. Reference :
  1317. Renewal :
  1318. Notes :
  1319. Attention :
  1320. Up Date :
  1321. ======1=========2=========3=========4=========5=========6=========7======= */
  1322. BOOL RedrawMenu(HWND hWnd)
  1323. {
  1324. int num;
  1325. char szPath[MAX_PATH];
  1326. HDC hDC;
  1327. HWND hWndItem;
  1328. DWORD itemNum;
  1329. DWORD desktopHeight;
  1330. DWORD dwCnt = 0;
  1331. DWORD dwValidCnt = 0;
  1332. TEXTMETRIC textMetric;
  1333. char uimsg[MAX_UIMSG];
  1334. ::DeleteMenu(g_hListMenu, ID_NOENTRY, MF_BYCOMMAND);
  1335. num = ::GetMenuItemCount(g_hListMenu);
  1336. for (dwCnt = 0; dwCnt < (DWORD) num; dwCnt++)
  1337. if (::DeleteMenu(g_hListMenu, ID_MENU_MIN + dwCnt, MF_BYCOMMAND) == FALSE)
  1338. num++;
  1339. hWndItem = ::GetDlgItem((HWND) g_hListMenu, ID_MENU_MIN);
  1340. hDC = ::GetWindowDC(hWndItem);
  1341. if (g_MenuData.hFont != NULL)
  1342. ::SelectObject(hDC, (HGDIOBJ) g_MenuData.hFont);
  1343. ::GetTextMetrics(hDC, &textMetric);
  1344. if (g_MenuData.dwIconMode == MODE_SMALLICON)
  1345. g_MenuData.dwMenuHeight = (ICONSPACE_SMALL > textMetric.tmHeight) ? ICONSPACE_SMALL : textMetric.tmHeight;
  1346. else
  1347. g_MenuData.dwMenuHeight = (ICONSPACE_LARGE > textMetric.tmHeight) ? ICONSPACE_LARGE : textMetric.tmHeight;
  1348. ReleaseDC(hWndItem, hDC);
  1349. desktopHeight = ::GetSystemMetrics(SM_CYSCREEN);
  1350. itemNum = desktopHeight / g_MenuData.dwMenuHeight;
  1351. dwCnt = 0;
  1352. while (::lstrlen(g_MenuData.szName[dwCnt]) != 0) {
  1353. if (GetApplicationFilename(g_MenuData.szName[dwCnt], szPath) == TRUE) {
  1354. if (dwCnt % itemNum == 0 && dwCnt != 0)
  1355. ::AppendMenu(g_hListMenu, MF_OWNERDRAW | MF_MENUBARBREAK, ID_MENU_MIN + dwCnt, (LPCTSTR) dwCnt);
  1356. else
  1357. ::AppendMenu(g_hListMenu, MF_OWNERDRAW | MF_POPUP, ID_MENU_MIN + dwCnt, (LPCTSTR) dwCnt);
  1358. dwValidCnt++;
  1359. }
  1360. dwCnt++;
  1361. }
  1362. if (dwValidCnt == 0) {
  1363. UTIL_get_lang_msg("MENU_NOTRAY", uimsg, sizeof(uimsg), STR_NOENTRY, UILanguageFile);
  1364. ::AppendMenu(g_hListMenu, MF_STRING | MF_GRAYED, ID_NOENTRY, (LPCTSTR) uimsg);
  1365. }
  1366. return TRUE;
  1367. }
  1368. /* ==========================================================================
  1369. Function Name : (BOOL) RegSaveLoginHostInformation()
  1370. Outline : レジストリに設定情報を保存する。
  1371. Arguments : JobInfo *jobInfo (In) 設定情報構造体
  1372. Return Value : 成功 TRUE / 失敗 FALSE
  1373. Reference :
  1374. Renewal :
  1375. Notes :
  1376. Attention :
  1377. Up Date :
  1378. ======1=========2=========3=========4=========5=========6=========7======= */
  1379. BOOL RegSaveLoginHostInformation(JobInfo *jobInfo)
  1380. {
  1381. HKEY hKey;
  1382. char szSubKey[MAX_PATH];
  1383. char szEncodePassword[MAX_PATH];
  1384. ::wsprintf(szSubKey, "%s\\%s", TTERM_KEY, jobInfo->szName);
  1385. if ((hKey = RegCreate(HKEY_CURRENT_USER, szSubKey)) == INVALID_HANDLE_VALUE)
  1386. return FALSE;
  1387. RegSetStr(hKey, KEY_HOSTNAME, jobInfo->szHostName);
  1388. RegSetDword(hKey, KEY_MODE, jobInfo->dwMode);
  1389. RegSetDword(hKey, KEY_USERFLAG, (DWORD) jobInfo->bUsername);
  1390. RegSetStr(hKey, KEY_USERNAME, jobInfo->szUsername);
  1391. RegSetDword(hKey, KEY_PASSWDFLAG, (DWORD) jobInfo->bPassword);
  1392. EncodePassword(jobInfo->szPassword, szEncodePassword);
  1393. RegSetBinary(hKey, KEY_PASSWORD, szEncodePassword, ::lstrlen(szEncodePassword) + 1);
  1394. RegSetStr(hKey, KEY_TERATERM, jobInfo->szTeraTerm);
  1395. RegSetStr(hKey, KEY_INITFILE, jobInfo->szInitFile);
  1396. RegSetStr(hKey, KEY_OPTION, jobInfo->szOption);
  1397. RegSetStr(hKey, KEY_LOGIN_PROMPT, jobInfo->szLoginPrompt);
  1398. RegSetStr(hKey, KEY_PASSWORD_PROMPT, jobInfo->szPasswdPrompt);
  1399. RegSetStr(hKey, KEY_MACROFILE, jobInfo->szMacroFile);
  1400. RegSetDword(hKey, KEY_TTSSH, (DWORD) jobInfo->bTtssh);
  1401. RegSetDword(hKey, KEY_STARTUP, (DWORD) jobInfo->bStartup);
  1402. RegSetStr(hKey, KEY_LOG, jobInfo->szLog);
  1403. // SSH2
  1404. RegSetStr(hKey, KEY_KEYFILE, jobInfo->PrivateKeyFile);
  1405. RegSetDword(hKey, KEY_CHALLENGE, (DWORD) jobInfo->bChallenge);
  1406. RegSetDword(hKey, KEY_PAGEANT, (DWORD) jobInfo->bPageant);
  1407. RegClose(hKey);
  1408. return TRUE;
  1409. }
  1410. /* ==========================================================================
  1411. Function Name : (BOOL) RegLoadLoginHostInformation()
  1412. Outline : レジストリから設定情報を取得する。
  1413. Arguments : char *szName (In) 設定情報名
  1414. : JobInfo *jobInfo (In) 設定情報構造体
  1415. Return Value : 成功 TRUE / 失敗 FALSE
  1416. Reference :
  1417. Renewal :
  1418. Notes :
  1419. Attention :
  1420. Up Date :
  1421. ======1=========2=========3=========4=========5=========6=========7======= */
  1422. BOOL RegLoadLoginHostInformation(char *szName, JobInfo *job_Info)
  1423. {
  1424. HKEY hKey;
  1425. char szSubKey[MAX_PATH];
  1426. char szEncodePassword[MAX_PATH];
  1427. DWORD dwSize = MAX_PATH;
  1428. JobInfo jobInfo;
  1429. memset(&jobInfo, 0, sizeof(JobInfo));
  1430. ::wsprintf(szSubKey, "%s\\%s", TTERM_KEY, szName);
  1431. if ((hKey = RegOpen(HKEY_CURRENT_USER, szSubKey)) == INVALID_HANDLE_VALUE)
  1432. return FALSE;
  1433. ::lstrcpy(jobInfo.szName, szName);
  1434. RegGetStr(hKey, KEY_HOSTNAME, jobInfo.szHostName, MAX_PATH);
  1435. RegGetDword(hKey, KEY_MODE, &(jobInfo.dwMode));
  1436. RegGetDword(hKey, KEY_USERFLAG, (DWORD *) &(jobInfo.bUsername));
  1437. RegGetStr(hKey, KEY_USERNAME, jobInfo.szUsername, MAX_PATH);
  1438. RegGetDword(hKey, KEY_PASSWDFLAG, (DWORD *) &(jobInfo.bPassword));
  1439. RegGetBinary(hKey, KEY_PASSWORD, szEncodePassword, &dwSize);
  1440. EncodePassword(szEncodePassword, jobInfo.szPassword);
  1441. RegGetStr(hKey, KEY_TERATERM, jobInfo.szTeraTerm, MAX_PATH);
  1442. RegGetStr(hKey, KEY_INITFILE, jobInfo.szInitFile, MAX_PATH);
  1443. RegGetStr(hKey, KEY_OPTION, jobInfo.szOption, MAX_PATH);
  1444. RegGetStr(hKey, KEY_LOGIN_PROMPT, jobInfo.szLoginPrompt, MAX_PATH);
  1445. RegGetStr(hKey, KEY_PASSWORD_PROMPT, jobInfo.szPasswdPrompt, MAX_PATH);
  1446. RegGetStr(hKey, KEY_MACROFILE, jobInfo.szMacroFile, MAX_PATH);
  1447. RegGetDword(hKey, KEY_TTSSH, (LPDWORD) &(jobInfo.bTtssh));
  1448. RegGetDword(hKey, KEY_STARTUP, (LPDWORD) &(jobInfo.bStartup));
  1449. RegGetStr(hKey, KEY_LOG, jobInfo.szLog, MAX_PATH);
  1450. // SSH2
  1451. ZeroMemory(jobInfo.PrivateKeyFile, sizeof(jobInfo.PrivateKeyFile));
  1452. RegGetStr(hKey, KEY_KEYFILE, jobInfo.PrivateKeyFile, MAX_PATH);
  1453. RegGetDword(hKey, KEY_CHALLENGE, (LPDWORD) &(jobInfo.bChallenge));
  1454. RegGetDword(hKey, KEY_PAGEANT, (LPDWORD) &(jobInfo.bPageant));
  1455. RegClose(hKey);
  1456. *job_Info = jobInfo;
  1457. return TRUE;
  1458. }
  1459. /* ==========================================================================
  1460. Function Name : (BOOL) SaveEtcInformation()
  1461. Outline : 詳細設定情報をグローバル変数に保存する。
  1462. Arguments : HWND hWnd (In) ダイアログのハンドル
  1463. Return Value : 成功 TRUE / 失敗 FALSE
  1464. Reference :
  1465. Renewal :
  1466. Notes :
  1467. Attention :
  1468. Up Date :
  1469. ======1=========2=========3=========4=========5=========6=========7======= */
  1470. BOOL SaveEtcInformation(HWND hWnd)
  1471. {
  1472. ::GetDlgItemText(hWnd, EDIT_TTMPATH, g_JobInfo.szTeraTerm, MAX_PATH);
  1473. ::GetDlgItemText(hWnd, EDIT_INITFILE, g_JobInfo.szInitFile, MAX_PATH);
  1474. ::GetDlgItemText(hWnd, EDIT_OPTION, g_JobInfo.szOption, MAX_PATH);
  1475. ::GetDlgItemText(hWnd, EDIT_PROMPT_USER, g_JobInfo.szLoginPrompt, MAX_PATH);
  1476. ::GetDlgItemText(hWnd, EDIT_PROMPT_PASS, g_JobInfo.szPasswdPrompt, MAX_PATH);
  1477. ::GetDlgItemText(hWnd, EDIT_LOG, g_JobInfo.szLog, MAX_PATH);
  1478. return TRUE;
  1479. }
  1480. /* ==========================================================================
  1481. Function Name : (BOOL) SaveLoginHostInformation()
  1482. Outline : 設定情報を保存する。
  1483. Arguments : HWND hWnd (In) ダイアログのハンドル
  1484. Return Value : 成功 TRUE / 失敗 FALSE
  1485. Reference :
  1486. Renewal :
  1487. Notes :
  1488. Attention :
  1489. Up Date :
  1490. ======1=========2=========3=========4=========5=========6=========7======= */
  1491. BOOL SaveLoginHostInformation(HWND hWnd)
  1492. {
  1493. long index;
  1494. char szDefault[MAX_PATH] = DEFAULT_PATH;
  1495. char szTTermPath[MAX_PATH];
  1496. char szName[MAX_PATH];
  1497. DWORD dwErr;
  1498. char uimsg[MAX_UIMSG];
  1499. char cur[MAX_PATH], modulePath[MAX_PATH];
  1500. if (::GetDlgItemText(hWnd, EDIT_ENTRY, g_JobInfo.szName, MAX_PATH) == 0) {
  1501. UTIL_get_lang_msg("MSG_ERROR_NOREGNAME", uimsg, sizeof(uimsg),
  1502. "error: no registry name", UILanguageFile);
  1503. ::MessageBox(hWnd, uimsg, "TeraTerm Menu", MB_ICONSTOP | MB_OK);
  1504. return FALSE;
  1505. }
  1506. if (_tcschr(g_JobInfo.szName, '\\') != NULL) {
  1507. UTIL_get_lang_msg("MSG_ERROR_INVALIDREGNAME", uimsg, sizeof(uimsg),
  1508. "can't use \"\\\" in registry name", UILanguageFile);
  1509. ::MessageBox(hWnd, uimsg, "TeraTerm Menu", MB_ICONSTOP | MB_OK);
  1510. return FALSE;
  1511. }
  1512. if (::IsDlgButtonChecked(hWnd, RADIO_LOGIN) == 1)
  1513. g_JobInfo.dwMode = MODE_AUTOLOGIN;
  1514. if (::IsDlgButtonChecked(hWnd, RADIO_MACRO) == 1)
  1515. g_JobInfo.dwMode = MODE_MACRO;
  1516. if (::IsDlgButtonChecked(hWnd, RADIO_DIRECT) == 1)
  1517. g_JobInfo.dwMode = MODE_DIRECT;
  1518. if (::GetDlgItemText(hWnd, EDIT_HOST, g_JobInfo.szHostName, MAX_PATH) == 0 && g_JobInfo.dwMode == MODE_AUTOLOGIN) {
  1519. UTIL_get_lang_msg("MSG_ERROR_NOHOST", uimsg, sizeof(uimsg),
  1520. "error: no host name", UILanguageFile);
  1521. ::MessageBox(hWnd, uimsg, "TeraTerm Menu", MB_ICONSTOP | MB_OK);
  1522. return FALSE;
  1523. }
  1524. g_JobInfo.bUsername = (BOOL) ::IsDlgButtonChecked(hWnd, CHECK_USER);
  1525. ::GetDlgItemText(hWnd, EDIT_USER, g_JobInfo.szUsername, MAX_PATH);
  1526. g_JobInfo.bPassword = (BOOL) ::IsDlgButtonChecked(hWnd, CHECK_PASSWORD);
  1527. ::GetDlgItemText(hWnd, EDIT_PASSWORD, g_JobInfo.szPassword, MAX_PATH);
  1528. if (::GetDlgItemText(hWnd, EDIT_MACRO, g_JobInfo.szMacroFile, MAX_PATH) == 0 && g_JobInfo.dwMode == MODE_MACRO) {
  1529. UTIL_get_lang_msg("MSG_ERROR_NOMACRO", uimsg, sizeof(uimsg),
  1530. "error: no macro filename", UILanguageFile);
  1531. ::MessageBox(hWnd, uimsg, "TeraTerm Menu", MB_ICONSTOP | MB_OK);
  1532. return FALSE;
  1533. }
  1534. g_JobInfo.bStartup = (BOOL) ::IsDlgButtonChecked(hWnd, CHECK_STARTUP);
  1535. g_JobInfo.bTtssh = (BOOL) ::IsDlgButtonChecked(hWnd, CHECK_TTSSH);
  1536. if (g_JobInfo.bTtssh == TRUE && lstrstri(g_JobInfo.szTeraTerm, TTSSH) == NULL) {
  1537. ::GetProfileString("Tera Term Pro", "Path", szDefault, szTTermPath, MAX_PATH);
  1538. ::wsprintf(g_JobInfo.szTeraTerm, "%s\\%s", szTTermPath, TTSSH);
  1539. } else if (::lstrlen(g_JobInfo.szTeraTerm) == 0) {
  1540. ::GetProfileString("Tera Term Pro", "Path", szDefault, szTTermPath, MAX_PATH);
  1541. ::wsprintf(g_JobInfo.szTeraTerm, "%s\\%s", szTTermPath, g_JobInfo.bTtssh ? TTSSH : TERATERM);
  1542. }
  1543. GetCurrentDirectory(sizeof(cur), cur);
  1544. GetModuleFileName(NULL, modulePath, sizeof(modulePath));
  1545. ExtractDirName(modulePath, modulePath);
  1546. SetCurrentDirectory(modulePath);
  1547. if (::GetFileAttributes(g_JobInfo.szTeraTerm) == 0xFFFFFFFF) {
  1548. dwErr = ::GetLastError();
  1549. if (dwErr == ERROR_FILE_NOT_FOUND || dwErr == ERROR_PATH_NOT_FOUND) {
  1550. UTIL_get_lang_msg("MSG_ERROR_CHECKFILE", uimsg, sizeof(uimsg),
  1551. "checking [%s] file was failure.\n", UILanguageFile);
  1552. ErrorMessage(hWnd, dwErr, uimsg, g_JobInfo.szTeraTerm);
  1553. SetCurrentDirectory(cur);
  1554. return FALSE;
  1555. }
  1556. }
  1557. // 秘密鍵ファイルの追加 (2005.1.28 yutaka)
  1558. if (::GetDlgItemText(hWnd, IDC_KEYFILE_PATH, g_JobInfo.PrivateKeyFile, MAX_PATH) == 0) {
  1559. ZeroMemory(g_JobInfo.PrivateKeyFile, sizeof(g_JobInfo.PrivateKeyFile));
  1560. }
  1561. if (g_JobInfo.bTtssh) {
  1562. g_JobInfo.bChallenge = (BOOL) ::IsDlgButtonChecked(hWnd, IDC_CHALLENGE_CHECK);
  1563. g_JobInfo.bPageant = (BOOL) ::IsDlgButtonChecked(hWnd, IDC_PAGEANT_CHECK);
  1564. }
  1565. if (RegSaveLoginHostInformation(&g_JobInfo) == FALSE) {
  1566. dwErr = ::GetLastError();
  1567. UTIL_get_lang_msg("MSG_ERROR_SAVEREG", uimsg, sizeof(uimsg),
  1568. "error: couldn't save to registry.\n", UILanguageFile);
  1569. ErrorMessage(hWnd, dwErr, uimsg);
  1570. SetCurrentDirectory(cur);
  1571. return FALSE;
  1572. }
  1573. InitListMenu(hWnd);
  1574. InitListBox(hWnd);
  1575. index = 0;
  1576. while ((index = ::SendDlgItemMessage(hWnd, LIST_HOST, LB_SELECTSTRING, index, (LPARAM)(LPCTSTR) g_JobInfo.szName)) != LB_ERR) {
  1577. ::SendDlgItemMessage(hWnd, LIST_HOST, LB_GETTEXT, index, (LPARAM)(LPCTSTR) szName);
  1578. if (::lstrcmpi(g_JobInfo.szName, szName) == 0)
  1579. break;
  1580. }
  1581. SetCurrentDirectory(cur);
  1582. return TRUE;
  1583. }
  1584. /* ==========================================================================
  1585. Function Name : (BOOL) LoadLoginHostInformation()
  1586. Outline : 設定情報を取得する。
  1587. Arguments : HWND hWnd (In) ダイアログのハンドル
  1588. Return Value : 成功 TRUE / 失敗 FALSE
  1589. Reference :
  1590. Renewal :
  1591. Notes :
  1592. Attention :
  1593. Up Date :
  1594. ======1=========2=========3=========4=========5=========6=========7======= */
  1595. BOOL LoadLoginHostInformation(HWND hWnd)
  1596. {
  1597. long index;
  1598. // char *pt;
  1599. char szName[MAX_PATH];
  1600. char uimsg[MAX_UIMSG];
  1601. DWORD dwErr;
  1602. index = ::SendDlgItemMessage(hWnd, LIST_HOST, LB_GETCURSEL, 0, 0);
  1603. ::SendDlgItemMessage(hWnd, LIST_HOST, LB_GETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) szName);
  1604. if (RegLoadLoginHostInformation(szName, &g_JobInfo) == FALSE) {
  1605. dwErr = ::GetLastError();
  1606. UTIL_get_lang_msg("MSG_ERROR_OPENREG", uimsg, sizeof(uimsg),
  1607. "Couldn't open the registry.\n", UILanguageFile);
  1608. ErrorMessage(hWnd, dwErr, uimsg);
  1609. return FALSE;
  1610. }
  1611. switch (g_JobInfo.dwMode) {
  1612. case MODE_AUTOLOGIN:
  1613. ::CheckRadioButton(hWnd, RADIO_LOGIN, RADIO_DIRECT, RADIO_LOGIN);
  1614. EnableItem(hWnd, EDIT_HOST, TRUE);
  1615. EnableItem(hWnd, CHECK_USER, TRUE);
  1616. EnableItem(hWnd, EDIT_USER, g_JobInfo.bUsername);
  1617. EnableItem(hWnd, CHECK_PASSWORD, TRUE);
  1618. EnableItem(hWnd, EDIT_PASSWORD, g_JobInfo.bPassword);
  1619. EnableItem(hWnd, EDIT_MACRO, FALSE);
  1620. EnableItem(hWnd, BUTTON_MACRO, FALSE);
  1621. break;
  1622. case MODE_MACRO:
  1623. ::CheckRadioButton(hWnd, RADIO_LOGIN, RADIO_DIRECT, RADIO_MACRO);
  1624. EnableItem(hWnd, EDIT_HOST, FALSE);
  1625. EnableItem(hWnd, CHECK_USER, FALSE);
  1626. EnableItem(hWnd, EDIT_USER, FALSE);
  1627. EnableItem(hWnd, CHECK_PASSWORD, FALSE);
  1628. EnableItem(hWnd, EDIT_PASSWORD, FALSE);
  1629. EnableItem(hWnd, EDIT_MACRO, TRUE);
  1630. EnableItem(hWnd, BUTTON_MACRO, TRUE);
  1631. break;
  1632. case MODE_DIRECT:
  1633. ::CheckRadioButton(hWnd, RADIO_LOGIN, RADIO_DIRECT, RADIO_DIRECT);
  1634. EnableItem(hWnd, EDIT_HOST, FALSE);
  1635. EnableItem(hWnd, CHECK_USER, FALSE);
  1636. EnableItem(hWnd, EDIT_USER, FALSE);
  1637. EnableItem(hWnd, CHECK_PASSWORD, FALSE);
  1638. EnableItem(hWnd, EDIT_PASSWORD, FALSE);
  1639. EnableItem(hWnd, EDIT_MACRO, FALSE);
  1640. EnableItem(hWnd, BUTTON_MACRO, FALSE);
  1641. break;
  1642. }
  1643. if (::lstrlen(g_JobInfo.szName) == 0)
  1644. ::lstrcpy(g_JobInfo.szName, g_JobInfo.szHostName);
  1645. ::SetDlgItemText(hWnd, EDIT_ENTRY, g_JobInfo.szName);
  1646. ::SetDlgItemText(hWnd, EDIT_HOST, g_JobInfo.szHostName);
  1647. ::SetDlgItemText(hWnd, EDIT_USER, g_JobInfo.szUsername);
  1648. ::SetDlgItemText(hWnd, EDIT_PASSWORD, g_JobInfo.szPassword);
  1649. ::SetDlgItemText(hWnd, EDIT_MACRO, g_JobInfo.szMacroFile);
  1650. ::CheckDlgButton(hWnd, CHECK_USER, g_JobInfo.bUsername);
  1651. ::CheckDlgButton(hWnd, CHECK_PASSWORD, g_JobInfo.bPassword);
  1652. ::CheckDlgButton(hWnd, CHECK_TTSSH, g_JobInfo.bTtssh);
  1653. // 秘密鍵ファイルの追加 (2005.1.28 yutaka)
  1654. ::SetDlgItemText(hWnd, IDC_KEYFILE_PATH, g_JobInfo.PrivateKeyFile);
  1655. if (g_JobInfo.bTtssh == TRUE) {
  1656. EnableWindow(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), TRUE);
  1657. EnableWindow(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), TRUE);
  1658. if (g_JobInfo.bChallenge) {
  1659. SendMessage(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), BM_SETCHECK, BST_CHECKED, 0);
  1660. SendMessage(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), BM_SETCHECK, BST_UNCHECKED, 0);
  1661. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), FALSE);
  1662. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), FALSE);
  1663. EnableWindow(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), FALSE);
  1664. } else if (g_JobInfo.bPageant) {
  1665. SendMessage(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), BM_SETCHECK, BST_CHECKED, 0);
  1666. SendMessage(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), BM_SETCHECK, BST_UNCHECKED, 0);
  1667. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), FALSE);
  1668. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), FALSE);
  1669. EnableWindow(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), FALSE);
  1670. } else {
  1671. SendMessage(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), BM_SETCHECK, BST_UNCHECKED, 0);
  1672. SendMessage(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), BM_SETCHECK, BST_UNCHECKED, 0);
  1673. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), TRUE);
  1674. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), TRUE);
  1675. }
  1676. } else {
  1677. SendMessage(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), BM_SETCHECK, BST_UNCHECKED, 0);
  1678. SendMessage(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), BM_SETCHECK, BST_UNCHECKED, 0);
  1679. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), FALSE);
  1680. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), FALSE);
  1681. EnableWindow(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), FALSE);
  1682. EnableWindow(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), FALSE);
  1683. }
  1684. // ttssh.exeは廃止したので下記チェックは削除する。(2004.12.3 yutaka)
  1685. #if 0
  1686. if ((pt = lstrstri(g_JobInfo.szTeraTerm, TTSSH)) != NULL)
  1687. if (::lstrcmpi(pt, TTSSH) == 0)
  1688. ::CheckDlgButton(hWnd, CHECK_TTSSH, TRUE);
  1689. #endif
  1690. ::CheckDlgButton(hWnd, CHECK_STARTUP, g_JobInfo.bStartup);
  1691. return TRUE;
  1692. }
  1693. /* ==========================================================================
  1694. Function Name : (BOOL) DeleteLoginHostInformation()
  1695. Outline : 設定情報を削除する。
  1696. Arguments : HWND hWnd (In) ダイアログのハンドル
  1697. Return Value : 成功 TRUE / 失敗 FALSE
  1698. Reference :
  1699. Renewal :
  1700. Notes :
  1701. Attention :
  1702. Up Date :
  1703. ======1=========2=========3=========4=========5=========6=========7======= */
  1704. BOOL DeleteLoginHostInformation(HWND hWnd)
  1705. {
  1706. long index;
  1707. char szEntryName[MAX_PATH];
  1708. char szSubKey[MAX_PATH];
  1709. char uimsg[MAX_UIMSG];
  1710. DWORD dwErr;
  1711. if ((index = ::SendDlgItemMessage(hWnd, LIST_HOST, LB_GETCURSEL, 0, 0)) == LB_ERR) {
  1712. UTIL_get_lang_msg("MSG_ERROR_SELECTREG", uimsg, sizeof(uimsg),
  1713. "Select deleted registry name", UILanguageFile);
  1714. ::MessageBox(hWnd, uimsg, "TeraTerm Menu", MB_ICONSTOP | MB_OK);
  1715. return FALSE;
  1716. }
  1717. if (::SendDlgItemMessage(hWnd, LIST_HOST, LB_GETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) szEntryName) == LB_ERR) {
  1718. UTIL_get_lang_msg("MSG_ERROR_GETDELETEREG", uimsg, sizeof(uimsg),
  1719. "Couldn't get the deleting entry", UILanguageFile);
  1720. ::MessageBox(hWnd, uimsg, "TeraTerm Menu", MB_ICONSTOP | MB_OK);
  1721. return FALSE;
  1722. }
  1723. ::wsprintf(szSubKey, "%s\\%s", TTERM_KEY, szEntryName);
  1724. if (RegDelete(HKEY_CURRENT_USER, szSubKey) != ERROR_SUCCESS) {
  1725. dwErr = ::GetLastError();
  1726. UTIL_get_lang_msg("MSG_ERROR_DELETEREG", uimsg, sizeof(uimsg),
  1727. "Couldn't delete the registry.\n", UILanguageFile);
  1728. ErrorMessage(hWnd, dwErr, uimsg);
  1729. return FALSE;
  1730. }
  1731. InitListMenu(hWnd);
  1732. InitListBox(hWnd);
  1733. return TRUE;
  1734. }
  1735. /* ==========================================================================
  1736. Function Name : (BOOL) ManageWMCommand_Config()
  1737. Outline : 設定情報ダイアログのWM_COMMANDを処理する。
  1738. Arguments : HWND hWnd (In) ダイアログのハンドル
  1739. : WPARAM wParam (In)
  1740. Return Value : 処理 TRUE / 未処理 FALSE
  1741. Reference :
  1742. Renewal :
  1743. Notes :
  1744. Attention :
  1745. Up Date :
  1746. ======1=========2=========3=========4=========5=========6=========7======= */
  1747. BOOL ManageWMCommand_Config(HWND hWnd, WPARAM wParam)
  1748. {
  1749. char *pt;
  1750. int ret = 0;
  1751. char title[MAX_UIMSG], filter[MAX_UIMSG];
  1752. // 秘密鍵ファイルのコントロール (2005.1.28 yutaka)
  1753. switch(wParam) {
  1754. case CHECK_TTSSH | (BN_CLICKED << 16) :
  1755. ret = SendMessage(GetDlgItem(hWnd, CHECK_TTSSH), BM_GETCHECK, 0, 0);
  1756. if (ret & BST_CHECKED) {
  1757. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), TRUE);
  1758. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), TRUE);
  1759. EnableWindow(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), TRUE);
  1760. EnableWindow(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), TRUE);
  1761. } else {
  1762. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), FALSE);
  1763. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), FALSE);
  1764. EnableWindow(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), FALSE);
  1765. EnableWindow(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), FALSE);
  1766. }
  1767. return TRUE;
  1768. case IDC_CHALLENGE_CHECK | (BN_CLICKED << 16) :
  1769. // "use Challenge"をチェックした場合は鍵ファイルをdisabledにする。(2007.11.14 yutaka)
  1770. ret = SendMessage(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), BM_GETCHECK, 0, 0);
  1771. if (ret & BST_CHECKED) {
  1772. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), FALSE);
  1773. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), FALSE);
  1774. EnableWindow(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), FALSE);
  1775. } else {
  1776. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), TRUE);
  1777. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), TRUE);
  1778. EnableWindow(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), TRUE);
  1779. }
  1780. return TRUE;
  1781. case IDC_PAGEANT_CHECK | (BN_CLICKED << 16) :
  1782. // "use Pageant"のクリックに対応。(2008.5.26 maya)
  1783. ret = SendMessage(GetDlgItem(hWnd, IDC_PAGEANT_CHECK), BM_GETCHECK, 0, 0);
  1784. if (ret & BST_CHECKED) {
  1785. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), FALSE);
  1786. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), FALSE);
  1787. EnableWindow(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), FALSE);
  1788. } else {
  1789. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_PATH), TRUE);
  1790. EnableWindow(GetDlgItem(hWnd, IDC_KEYFILE_BUTTON), TRUE);
  1791. EnableWindow(GetDlgItem(hWnd, IDC_CHALLENGE_CHECK), TRUE);
  1792. }
  1793. return TRUE;
  1794. default:
  1795. break;
  1796. }
  1797. switch(LOWORD(wParam)) {
  1798. case IDOK:
  1799. case IDCANCEL:
  1800. g_hWndMenu = NULL;
  1801. ::EndDialog(hWnd, TRUE);
  1802. if (g_ConfigFont != NULL) {
  1803. DeleteObject(g_ConfigFont);
  1804. }
  1805. return TRUE;
  1806. case BUTTON_SET:
  1807. SaveLoginHostInformation(hWnd);
  1808. return TRUE;
  1809. case BUTTON_DELETE:
  1810. DeleteLoginHostInformation(hWnd);
  1811. return TRUE;
  1812. case BUTTON_ETC:
  1813. ::GetDlgItemText(hWnd, EDIT_ENTRY, g_JobInfo.szName, MAX_PATH);
  1814. g_JobInfo.bTtssh = ::IsDlgButtonChecked(hWnd, CHECK_TTSSH);
  1815. if (::DialogBox(g_hI, (LPCTSTR) DIALOG_ETC, hWnd, DlgCallBack_Etc) == TRUE) {
  1816. ::CheckDlgButton(hWnd, CHECK_TTSSH, 0);
  1817. if ((pt = lstrstri(g_JobInfo.szTeraTerm, TTSSH)) != NULL)
  1818. if (::lstrcmpi(pt, TTSSH) == 0)
  1819. ::CheckDlgButton(hWnd, CHECK_TTSSH, 1);
  1820. }
  1821. return TRUE;
  1822. case LIST_HOST:
  1823. if (HIWORD(wParam) == LBN_SELCHANGE)
  1824. LoadLoginHostInformation(hWnd);
  1825. return TRUE;
  1826. case CHECK_USER:
  1827. if (IsDlgButtonChecked(hWnd, CHECK_USER) == 1)
  1828. EnableItem(hWnd, EDIT_USER, TRUE);
  1829. else {
  1830. EnableItem(hWnd, EDIT_USER, FALSE);
  1831. ::CheckDlgButton(hWnd, CHECK_PASSWORD, 0);
  1832. ::PostMessage(hWnd, WM_COMMAND, (WPARAM) CHECK_PASSWORD, (LPARAM) 0);
  1833. }
  1834. return TRUE;
  1835. case CHECK_PASSWORD:
  1836. if (IsDlgButtonChecked(hWnd, CHECK_PASSWORD) == 1)
  1837. EnableItem(hWnd, EDIT_PASSWORD, TRUE);
  1838. else
  1839. EnableItem(hWnd, EDIT_PASSWORD, FALSE);
  1840. return TRUE;
  1841. case CHECK_INI_FILE:
  1842. if (IsDlgButtonChecked(hWnd, CHECK_INI_FILE) == 1)
  1843. EnableItem(hWnd, COMBO_INI_FILE, TRUE);
  1844. else
  1845. EnableItem(hWnd, COMBO_INI_FILE, FALSE);
  1846. return TRUE;
  1847. case BUTTON_MACRO:
  1848. ::GetDlgItemText(hWnd, EDIT_MACRO, g_JobInfo.szMacroFile, MAX_PATH);
  1849. UTIL_get_lang_msg("FILEDLG_MACRO_TITLE", title, sizeof(title),
  1850. "specifying macro file", UILanguageFile);
  1851. UTIL_get_lang_msg("FILEDLG_MACRO_FILTER", filter, sizeof(filter),
  1852. "macro file(*.ttl)\\0*.ttl\\0all files(*.*)\\0*.*\\0\\0", UILanguageFile);
  1853. OpenFileDlg(hWnd, EDIT_MACRO, title, filter, g_JobInfo.szMacroFile);
  1854. return TRUE;
  1855. case IDC_KEYFILE_BUTTON:
  1856. ::GetDlgItemText(hWnd, IDC_KEYFILE_PATH, g_JobInfo.PrivateKeyFile, MAX_PATH);
  1857. UTIL_get_lang_msg("FILEDLG_KEY_TITLE", title, sizeof(title),
  1858. "specifying private key file", UILanguageFile);
  1859. UTIL_get_lang_msg("FILEDLG_KEY_FILTER", filter, sizeof(filter),
  1860. "identity files\\0identity;id_rsa;id_dsa\\0identity(RSA1)\\0identity\\0id_rsa(SSH2)\\0id_rsa\\0id_dsa(SSH2)\\0id_dsa\\0all(*.*)\\0*.*\\0\\0", UILanguageFile);
  1861. OpenFileDlg(hWnd, IDC_KEYFILE_PATH, title, filter, g_JobInfo.PrivateKeyFile);
  1862. return TRUE;
  1863. case RADIO_LOGIN:
  1864. EnableItem(hWnd, EDIT_HOST, TRUE);
  1865. EnableItem(hWnd, CHECK_USER, TRUE);
  1866. if (IsDlgButtonChecked(hWnd, CHECK_USER) == 1)
  1867. EnableItem(hWnd, EDIT_USER, TRUE);
  1868. else {
  1869. EnableItem(hWnd, EDIT_USER, FALSE);
  1870. }
  1871. EnableItem(hWnd, CHECK_PASSWORD, TRUE);
  1872. if (IsDlgButtonChecked(hWnd, CHECK_PASSWORD) == 1)
  1873. EnableItem(hWnd, EDIT_PASSWORD, TRUE);
  1874. else
  1875. EnableItem(hWnd, EDIT_PASSWORD, FALSE);
  1876. EnableItem(hWnd, EDIT_MACRO, FALSE);
  1877. EnableItem(hWnd, BUTTON_MACRO, FALSE);
  1878. return TRUE;
  1879. case RADIO_MACRO:
  1880. EnableItem(hWnd, EDIT_HOST, FALSE);
  1881. EnableItem(hWnd, CHECK_USER, FALSE);
  1882. EnableItem(hWnd, EDIT_USER, FALSE);
  1883. EnableItem(hWnd, CHECK_PASSWORD, FALSE);
  1884. EnableItem(hWnd, EDIT_PASSWORD, FALSE);
  1885. EnableItem(hWnd, EDIT_MACRO, TRUE);
  1886. EnableItem(hWnd, BUTTON_MACRO, TRUE);
  1887. return TRUE;
  1888. case RADIO_DIRECT:
  1889. EnableItem(hWnd, EDIT_HOST, FALSE);
  1890. EnableItem(hWnd, CHECK_USER, FALSE);
  1891. EnableItem(hWnd, EDIT_USER, FALSE);
  1892. EnableItem(hWnd, CHECK_PASSWORD, FALSE);
  1893. EnableItem(hWnd, EDIT_PASSWORD, FALSE);
  1894. EnableItem(hWnd, EDIT_MACRO, FALSE);
  1895. EnableItem(hWnd, BUTTON_MACRO, FALSE);
  1896. return TRUE;
  1897. }
  1898. return FALSE;
  1899. }
  1900. /* ==========================================================================
  1901. Function Name : (BOOL) ManageWMCommand_Etc()
  1902. Outline : 詳細設定情報ダイアログのWM_COMMANDを処理する。
  1903. Arguments : HWND hWnd (In) ダイアログのハンドル
  1904. : WPARAM wParam (In)
  1905. Return Value : 処理 TRUE / 未処理 FALSE
  1906. Reference :
  1907. Renewal :
  1908. Notes :
  1909. Attention :
  1910. Up Date :
  1911. ======1=========2=========3=========4=========5=========6=========7======= */
  1912. BOOL ManageWMCommand_Etc(HWND hWnd, WPARAM wParam)
  1913. {
  1914. char szPath[MAX_PATH];
  1915. char title[MAX_UIMSG], filter[MAX_UIMSG];
  1916. switch(LOWORD(wParam)) {
  1917. case IDOK:
  1918. SaveEtcInformation(hWnd);
  1919. ::EndDialog(hWnd, TRUE);
  1920. if (g_DetailFont != NULL) {
  1921. DeleteObject(g_DetailFont);
  1922. }
  1923. return TRUE;
  1924. case IDCANCEL:
  1925. ::EndDialog(hWnd, FALSE);
  1926. if (g_DetailFont != NULL) {
  1927. DeleteObject(g_DetailFont);
  1928. }
  1929. return TRUE;
  1930. case BUTTON_DEFAULT:
  1931. SetDefaultEtcDlg(hWnd);
  1932. return TRUE;
  1933. case BUTTON_TTMPATH:
  1934. ::GetDlgItemText(hWnd, EDIT_TTMPATH, szPath, MAX_PATH);
  1935. UTIL_get_lang_msg("FILEDLG_TERATERM_TITLE", title, sizeof(title),
  1936. "specifying TeraTerm", UILanguageFile);
  1937. UTIL_get_lang_msg("FILEDLG_TERATERM_FILTER", filter, sizeof(filter),
  1938. "execute file(*.exe)\\0*.exe\\0all files(*.*)\\0*.*\\0\\0", UILanguageFile);
  1939. OpenFileDlg(hWnd, EDIT_TTMPATH, title, filter, szPath);
  1940. return TRUE;
  1941. case BUTTON_INITFILE:
  1942. ::GetDlgItemText(hWnd, EDIT_INITFILE, szPath, MAX_PATH);
  1943. UTIL_get_lang_msg("FILEDLG_INI_TITLE", title, sizeof(title),
  1944. "specifying config file", UILanguageFile);
  1945. UTIL_get_lang_msg("FILEDLG_INI_FILTER", filter, sizeof(filter),
  1946. "config file(*.ini)\\0*.ini\\0all files(*.*)\\0*.*\\0\\0", UILanguageFile);
  1947. OpenFileDlg(hWnd, EDIT_INITFILE, title, filter, szPath);
  1948. return TRUE;
  1949. case BUTTON_LOG:
  1950. ::GetDlgItemText(hWnd, EDIT_LOG, szPath, MAX_PATH);
  1951. UTIL_get_lang_msg("FILEDLG_LOG_TITLE", title, sizeof(title),
  1952. "specifying log file", UILanguageFile);
  1953. UTIL_get_lang_msg("FILEDLG_LOG_FILTER", filter, sizeof(filter),
  1954. "log file(*.log)\\0*.log\\0all files(*.*)\\0*.*\\0\\0", UILanguageFile);
  1955. OpenFileDlg(hWnd, EDIT_LOG, title, filter, szPath);
  1956. return TRUE;
  1957. }
  1958. return FALSE;
  1959. }
  1960. /* ==========================================================================
  1961. Function Name : (BOOL) ManageWMCommand_Version()
  1962. Outline : 「バージョン情報」ダイアログのWM_COMMANDを処理する。
  1963. Arguments : HWND hWnd (In) ダイアログのハンドル
  1964. : WPARAM wParam (In)
  1965. Return Value : 処理 TRUE / 未処理 FALSE
  1966. Reference :
  1967. Renewal :
  1968. Notes :
  1969. Attention :
  1970. Up Date :
  1971. ======1=========2=========3=========4=========5=========6=========7======= */
  1972. BOOL ManageWMCommand_Version(HWND hWnd, WPARAM wParam)
  1973. {
  1974. switch(LOWORD(wParam)) {
  1975. case IDOK:
  1976. ::EndDialog(hWnd, TRUE);
  1977. if (g_AboutFont != NULL) {
  1978. DeleteObject(g_AboutFont);
  1979. }
  1980. return TRUE;
  1981. case IDCANCEL:
  1982. ::EndDialog(hWnd, TRUE);
  1983. if (g_AboutFont != NULL) {
  1984. DeleteObject(g_AboutFont);
  1985. }
  1986. return TRUE;
  1987. }
  1988. return FALSE;
  1989. }
  1990. /* ==========================================================================
  1991. Function Name : (BOOL) ManageWMCommand_Menu()
  1992. Outline : メインウインドウのWM_COMMANDを処理する。
  1993. Arguments : HWND hWnd (In) ウインドウのハンドル
  1994. : WPARAM wParam (In)
  1995. Return Value : 処理 TRUE / 未処理 FALSE
  1996. Reference :
  1997. Renewal :
  1998. Notes :
  1999. Attention :
  2000. Up Date :
  2001. ======1=========2=========3=========4=========5=========6=========7======= */
  2002. BOOL ManageWMCommand_Menu(HWND hWnd, WPARAM wParam)
  2003. {
  2004. char uimsg[MAX_UIMSG];
  2005. switch(LOWORD(wParam)) {
  2006. case ID_TMENU_ADD:
  2007. ::DialogBox(g_hI, (LPCTSTR) DIALOG_CONFIG, 0, DlgCallBack_Config);
  2008. return TRUE;
  2009. case ID_TMENU_CLOSE:
  2010. ::DestroyWindow(hWnd);
  2011. return TRUE;
  2012. case ID_VERSION:
  2013. ::DialogBox(g_hI, (LPCTSTR) DIALOG_VERSION, hWnd, DlgCallBack_Version);
  2014. return TRUE;
  2015. case ID_ICON:
  2016. if (GetMenuState(g_hConfigMenu, ID_ICON, MF_BYCOMMAND & MF_CHECKED) != 0) {
  2017. UTIL_get_lang_msg("MENU_ICON", uimsg, sizeof(uimsg), STR_ICONMODE, UILanguageFile);
  2018. ::ModifyMenu(g_hConfigMenu, ID_ICON, MF_BYCOMMAND, ID_ICON, uimsg);
  2019. g_MenuData.dwIconMode = MODE_SMALLICON;
  2020. } else {
  2021. UTIL_get_lang_msg("MENU_ICON", uimsg, sizeof(uimsg), STR_ICONMODE, UILanguageFile);
  2022. ::ModifyMenu(g_hConfigMenu, ID_ICON, MF_CHECKED | MF_BYCOMMAND, ID_ICON, uimsg);
  2023. g_MenuData.dwIconMode = MODE_LARGEICON;
  2024. }
  2025. RedrawMenu(hWnd);
  2026. return TRUE;
  2027. case ID_LEFTPOPUP:
  2028. if (GetMenuState(g_hConfigMenu, ID_LEFTPOPUP, MF_BYCOMMAND & MF_CHECKED) != 0) {
  2029. UTIL_get_lang_msg("MENU_LEFTPOPUP", uimsg, sizeof(uimsg), STR_LEFTBUTTONPOPUP, UILanguageFile);
  2030. ::ModifyMenu(g_hConfigMenu, ID_LEFTPOPUP, MF_BYCOMMAND, ID_LEFTPOPUP, uimsg);
  2031. g_MenuData.bLeftButtonPopup = FALSE;
  2032. } else {
  2033. UTIL_get_lang_msg("MENU_LEFTPOPUP", uimsg, sizeof(uimsg), STR_LEFTBUTTONPOPUP, UILanguageFile);
  2034. ::ModifyMenu(g_hConfigMenu, ID_LEFTPOPUP, MF_CHECKED | MF_BYCOMMAND, ID_LEFTPOPUP, uimsg);
  2035. g_MenuData.bLeftButtonPopup = TRUE;
  2036. }
  2037. return TRUE;
  2038. case ID_HOTKEY:
  2039. if (GetMenuState(g_hConfigMenu, ID_HOTKEY, MF_BYCOMMAND & MF_CHECKED) != 0) {
  2040. UTIL_get_lang_msg("MENU_HOTKEY", uimsg, sizeof(uimsg), STR_HOTKEY, UILanguageFile);
  2041. ::ModifyMenu(g_hConfigMenu, ID_HOTKEY, MF_BYCOMMAND, ID_HOTKEY, uimsg);
  2042. ::UnregisterHotKey(g_hWnd, WM_MENUOPEN);
  2043. g_MenuData.bHotkey = FALSE;
  2044. } else {
  2045. UTIL_get_lang_msg("MENU_HOTKEY", uimsg, sizeof(uimsg), STR_HOTKEY, UILanguageFile);
  2046. ::ModifyMenu(g_hConfigMenu, ID_HOTKEY, MF_CHECKED | MF_BYCOMMAND, ID_HOTKEY, uimsg);
  2047. ::RegisterHotKey(g_hWnd, WM_MENUOPEN, MOD_CONTROL | MOD_ALT, 'M');
  2048. g_MenuData.bHotkey = TRUE;
  2049. }
  2050. return TRUE;
  2051. case ID_FONT:
  2052. SetMenuFont(hWnd);
  2053. break;
  2054. case ID_NOENTRY:
  2055. return TRUE;
  2056. default:
  2057. ConnectHost(hWnd, LOWORD(wParam));
  2058. return TRUE;
  2059. }
  2060. return FALSE;
  2061. }
  2062. /* ==========================================================================
  2063. Function Name : (BOOL CALLBACK) DlgCallBack_Config()
  2064. Outline : 設定ダイアログのコールバック関数
  2065. : (DialogProcのヘルプ参照)
  2066. Arguments :
  2067. :
  2068. Return Value :
  2069. Reference :
  2070. Renewal :
  2071. Notes :
  2072. Attention :
  2073. Up Date :
  2074. ======1=========2=========3=========4=========5=========6=========7======= */
  2075. BOOL CALLBACK DlgCallBack_Config(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2076. {
  2077. TEXTMETRIC textMetric;
  2078. PDRAWITEMSTRUCT lpdis;
  2079. LPMEASUREITEMSTRUCT lpmis;
  2080. static COLORREF crSelText;
  2081. static COLORREF crSelBkgnd;
  2082. static COLORREF crText;
  2083. static COLORREF crBkgnd;
  2084. switch(uMsg) {
  2085. case WM_INITDIALOG:
  2086. if (g_hWndMenu == NULL)
  2087. g_hWndMenu = hWnd;
  2088. else {
  2089. ::SetForceForegroundWindow(g_hWndMenu);
  2090. ::EndDialog(hWnd, FALSE);
  2091. }
  2092. SetDlgPos(hWnd, POSITION_CENTER);
  2093. PostMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)g_hIcon);
  2094. PostMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)g_hIconSmall);
  2095. CreateTooltip();
  2096. crText = ::GetSysColor(COLOR_WINDOWTEXT);
  2097. crBkgnd = ::GetSysColor(COLOR_WINDOW);
  2098. crSelText = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
  2099. crSelBkgnd = ::GetSysColor(COLOR_HIGHLIGHT);
  2100. InitConfigDlg(hWnd);
  2101. return TRUE;
  2102. case WM_COMMAND:
  2103. return ManageWMCommand_Config(hWnd, wParam);
  2104. case WM_NOTIFY:
  2105. return ManageWMNotify_Config(lParam);
  2106. case WM_DESTROY:
  2107. ::UnhookWindowsHookEx(g_hHook);
  2108. return TRUE;
  2109. case WM_MEASUREITEM:
  2110. lpmis = (LPMEASUREITEMSTRUCT) lParam;
  2111. lpmis->itemHeight = LISTBOX_HEIGHT;
  2112. return TRUE;
  2113. case WM_DRAWITEM:
  2114. lpdis = (LPDRAWITEMSTRUCT) lParam;
  2115. if (lpdis->itemID == -1)
  2116. return TRUE;
  2117. if (lpdis->itemState & ODS_SELECTED) {
  2118. ::SetTextColor(lpdis->hDC, crSelText);
  2119. ::SetBkColor(lpdis->hDC, crSelBkgnd);
  2120. } else {
  2121. ::SetTextColor(lpdis->hDC, crText);
  2122. ::SetBkColor(lpdis->hDC, crBkgnd);
  2123. }
  2124. ::GetTextMetrics(lpdis->hDC, &textMetric);
  2125. ::ExtTextOut(lpdis->hDC,
  2126. lpdis->rcItem.left + LISTBOX_WIDTH,
  2127. lpdis->rcItem.top + (ICONSIZE_SMALL - textMetric.tmHeight) / 2,
  2128. ETO_OPAQUE,
  2129. &lpdis->rcItem,
  2130. g_MenuData.szName[lpdis->itemData],
  2131. ::lstrlen(g_MenuData.szName[lpdis->itemData]),
  2132. NULL);
  2133. ::DrawIconEx(lpdis->hDC,
  2134. lpdis->rcItem.left + (LISTBOX_WIDTH - ICONSIZE_SMALL) / 2,
  2135. lpdis->rcItem.top + (LISTBOX_HEIGHT - ICONSIZE_SMALL) / 2,
  2136. g_MenuData.hSmallIcon[lpdis->itemData],
  2137. ICONSIZE_SMALL,
  2138. ICONSIZE_SMALL,
  2139. NULL,
  2140. NULL,
  2141. DI_NORMAL);
  2142. return TRUE;
  2143. }
  2144. return FALSE;
  2145. }
  2146. /* ==========================================================================
  2147. Function Name : (BOOL CALLBACK) DlgCallBack_Config()
  2148. Outline : 詳細設定ダイアログのコールバック関数
  2149. : (DialogProcのヘルプ参照)
  2150. Arguments :
  2151. :
  2152. Return Value :
  2153. Reference :
  2154. Renewal :
  2155. Notes :
  2156. Attention :
  2157. Up Date :
  2158. ======1=========2=========3=========4=========5=========6=========7======= */
  2159. BOOL CALLBACK DlgCallBack_Etc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2160. {
  2161. switch(uMsg) {
  2162. case WM_INITDIALOG:
  2163. SetDlgPos(hWnd, POSITION_CENTER);
  2164. InitEtcDlg(hWnd);
  2165. return TRUE;
  2166. case WM_COMMAND:
  2167. return ManageWMCommand_Etc(hWnd, wParam);
  2168. }
  2169. return FALSE;
  2170. }
  2171. /* ==========================================================================
  2172. Function Name : (BOOL CALLBACK) DlgCallBack_Config()
  2173. Outline : 「バージョン情報」ダイアログのコールバック関数
  2174. : (DialogProcのヘルプ参照)
  2175. Arguments :
  2176. :
  2177. Return Value :
  2178. Reference :
  2179. Renewal :
  2180. Notes :
  2181. Attention :
  2182. Up Date :
  2183. ======1=========2=========3=========4=========5=========6=========7======= */
  2184. BOOL CALLBACK DlgCallBack_Version(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2185. {
  2186. switch(uMsg) {
  2187. case WM_INITDIALOG:
  2188. SetDlgPos(hWnd, POSITION_CENTER);
  2189. PostMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)g_hIcon);
  2190. PostMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)g_hIconSmall);
  2191. SendDlgItemMessage(hWnd, IDC_TTPMENU_ICON, STM_SETICON, (WPARAM)g_hIcon, 0);
  2192. InitVersionDlg(hWnd);
  2193. return TRUE;
  2194. case WM_COMMAND:
  2195. return ManageWMCommand_Version(hWnd, wParam);
  2196. }
  2197. return FALSE;
  2198. }
  2199. /* ==========================================================================
  2200. Function Name : (LRESULT CALLBACK) WinProc()
  2201. Outline : メインウインドウのコールバック関数
  2202. : (WindowProcのヘルプ参照)
  2203. Arguments :
  2204. :
  2205. Return Value :
  2206. Reference :
  2207. Renewal :
  2208. Notes :
  2209. Attention :
  2210. Up Date :
  2211. ======1=========2=========3=========4=========5=========6=========7======= */
  2212. LRESULT CALLBACK WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2213. {
  2214. HDC hDC;
  2215. HWND hWndItem;
  2216. BOOL bRet;
  2217. SIZE size;
  2218. DWORD dwIconSize;
  2219. DWORD dwIconSpace;
  2220. TEXTMETRIC textMetric;
  2221. LPDRAWITEMSTRUCT lpdis;
  2222. LPMEASUREITEMSTRUCT lpmis;
  2223. static UINT WM_TASKBAR_RESTART;
  2224. g_hWnd = hWnd;
  2225. switch(uMsg) {
  2226. case WM_CREATE:
  2227. PostMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)g_hIcon);
  2228. PostMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)g_hIconSmall);
  2229. SetDlgPos(hWnd, POSITION_CENTER);
  2230. ::ShowWindow(hWnd, SW_HIDE);
  2231. SetTaskTray(hWnd, NIM_ADD);
  2232. WM_TASKBAR_RESTART = ::RegisterWindowMessage("TaskbarCreated");
  2233. InitMenu();
  2234. LoadConfig();
  2235. InitListMenu(hWnd);
  2236. ExecStartup(hWnd);
  2237. return TRUE;
  2238. case WM_COMMAND:
  2239. bRet = ManageWMCommand_Menu(hWnd, wParam);
  2240. return bRet;
  2241. case WM_TMENU_NOTIFY:
  2242. ::PostMessage(hWnd, (UINT) lParam, 0, 0);
  2243. return TRUE;
  2244. case WM_DISPLAYCHANGE:
  2245. InitListMenu(hWnd);
  2246. return TRUE;
  2247. case WM_ENDSESSION:
  2248. case WM_DESTROY:
  2249. SaveConfig();
  2250. SetTaskTray(hWnd, NIM_DELETE);
  2251. ::UnregisterHotKey(hWnd, WM_MENUOPEN);
  2252. DeleteListMenuIcons();
  2253. ::DestroyMenu(g_hListMenu);
  2254. ::DestroyMenu(g_hMenu);
  2255. ::PostQuitMessage(0);
  2256. return TRUE;
  2257. case WM_HOTKEY:
  2258. if (g_MenuData.bHotkey == TRUE)
  2259. PopupListMenu(hWnd);
  2260. return TRUE;
  2261. case WM_LBUTTONDOWN:
  2262. case WM_NCLBUTTONDOWN:
  2263. if (g_MenuData.bLeftButtonPopup == TRUE)
  2264. PopupListMenu(hWnd);
  2265. else
  2266. PopupMenu(hWnd);
  2267. return TRUE;
  2268. case WM_RBUTTONDOWN:
  2269. case WM_NCRBUTTONDOWN:
  2270. PopupMenu(hWnd);
  2271. return TRUE;
  2272. case WM_MEASUREITEM:
  2273. lpmis = (LPMEASUREITEMSTRUCT) lParam;
  2274. hWndItem = ::GetDlgItem((HWND) g_hListMenu, (UINT) wParam);
  2275. hDC = ::GetWindowDC(hWndItem);
  2276. if (g_MenuData.hFont != NULL)
  2277. ::SelectObject(hDC, (HGDIOBJ) g_MenuData.hFont);
  2278. ::GetTextExtentPoint32(hDC, g_MenuData.szName[lpmis->itemData], ::lstrlen(g_MenuData.szName[lpmis->itemData]), &size);
  2279. if (g_MenuData.dwIconMode == MODE_SMALLICON) {
  2280. lpmis->itemWidth = ICONSPACE_SMALL + size.cx;
  2281. lpmis->itemHeight = g_MenuData.dwMenuHeight;
  2282. } else {
  2283. lpmis->itemWidth = ICONSPACE_LARGE + size.cx;
  2284. lpmis->itemHeight = g_MenuData.dwMenuHeight;
  2285. }
  2286. ::ReleaseDC(hWndItem, hDC);
  2287. return TRUE;
  2288. case WM_DRAWITEM:
  2289. lpdis = (LPDRAWITEMSTRUCT) lParam;
  2290. if (lpdis->itemID == -1)
  2291. return TRUE;
  2292. if (g_MenuData.hFont != NULL)
  2293. ::SelectObject(lpdis->hDC, (HGDIOBJ) g_MenuData.hFont);
  2294. if (lpdis->itemState & ODS_SELECTED) {
  2295. ::SetTextColor(lpdis->hDC, g_MenuData.crSelMenuTxt);
  2296. ::SetBkColor(lpdis->hDC, g_MenuData.crSelMenuBg);
  2297. } else {
  2298. ::SetTextColor(lpdis->hDC, g_MenuData.crMenuTxt);
  2299. ::SetBkColor(lpdis->hDC, g_MenuData.crMenuBg);
  2300. }
  2301. if (g_MenuData.dwIconMode == MODE_LARGEICON) {
  2302. dwIconSize = ICONSIZE_LARGE;
  2303. dwIconSpace = ICONSPACE_LARGE;
  2304. } else {
  2305. dwIconSize = ICONSIZE_SMALL;
  2306. dwIconSpace = ICONSPACE_SMALL;
  2307. }
  2308. ::GetTextMetrics(lpdis->hDC, &textMetric);
  2309. ::ExtTextOut(lpdis->hDC,
  2310. lpdis->rcItem.left + dwIconSpace,
  2311. lpdis->rcItem.top + (g_MenuData.dwMenuHeight - textMetric.tmHeight) / 2,
  2312. ETO_OPAQUE,
  2313. &lpdis->rcItem,
  2314. g_MenuData.szName[lpdis->itemData],
  2315. ::lstrlen(g_MenuData.szName[lpdis->itemData]),
  2316. NULL);
  2317. ::DrawIconEx(lpdis->hDC,
  2318. lpdis->rcItem.left + (dwIconSpace - dwIconSize) / 2,
  2319. lpdis->rcItem.top + (g_MenuData.dwMenuHeight - dwIconSize) / 2,
  2320. (g_MenuData.dwIconMode == MODE_LARGEICON) ? g_MenuData.hLargeIcon[lpdis->itemData] : g_MenuData.hSmallIcon[lpdis->itemData],
  2321. dwIconSize,
  2322. dwIconSize,
  2323. NULL,
  2324. NULL,
  2325. DI_NORMAL);
  2326. return TRUE;
  2327. }
  2328. if (WM_TASKBAR_RESTART != 0 && uMsg == WM_TASKBAR_RESTART)
  2329. SetTaskTray(hWnd, NIM_ADD);
  2330. return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
  2331. }
  2332. /* ==========================================================================
  2333. Function Name : (int WINAPI) WinMain()
  2334. Outline : メイン関数
  2335. Arguments :
  2336. :
  2337. Return Value :
  2338. Reference :
  2339. Renewal :
  2340. Notes :
  2341. Attention :
  2342. Up Date :
  2343. ======1=========2=========3=========4=========5=========6=========7======= */
  2344. int WINAPI WinMain(HINSTANCE hI, HINSTANCE, LPSTR nCmdLine, int nCmdShow)
  2345. {
  2346. typedef BOOL (WINAPI *pSetDllDir)(LPCSTR);
  2347. typedef BOOL (WINAPI *pSetDefDllDir)(DWORD);
  2348. MSG msg;
  2349. HWND hWnd;
  2350. WNDCLASS winClass;
  2351. char uimsg[MAX_UIMSG];
  2352. DWORD dwErr;
  2353. int fuLoad = LR_DEFAULTCOLOR;
  2354. HMODULE module;
  2355. pSetDllDir setDllDir;
  2356. pSetDefDllDir setDefDllDir;
  2357. if ((module = GetModuleHandle("kernel32.dll")) != NULL) {
  2358. if ((setDefDllDir = (pSetDefDllDir)GetProcAddress(module, "SetDefaultDllDirectories")) != NULL) {
  2359. // SetDefaultDllDirectories() が使える場合は、検索パスを %WINDOWS%\system32 のみに設定する
  2360. (*setDefDllDir)((DWORD)0x00000800); // LOAD_LIBRARY_SEARCH_SYSTEM32
  2361. }
  2362. else if ((setDllDir = (pSetDllDir)GetProcAddress(module, "SetDllDirectoryA")) != NULL) {
  2363. // SetDefaultDllDirectories() が使えなくても、SetDllDirectory() が使える場合は
  2364. // カレントディレクトリだけでも検索パスからはずしておく。
  2365. (*setDllDir)("");
  2366. }
  2367. }
  2368. checkIniFile(); //INIファイル/レジストリ切替
  2369. GetUILanguageFile(UILanguageFile, sizeof(UILanguageFile));
  2370. g_hI = hI;
  2371. if (IsWindowsNT4()){
  2372. fuLoad = LR_VGACOLOR;
  2373. }
  2374. g_hIcon = (HICON)::LoadImage(g_hI, MAKEINTRESOURCE(TTERM_ICON), IMAGE_ICON, 32, 32, fuLoad);
  2375. g_hIconSmall = (HICON)::LoadImage(g_hI, MAKEINTRESOURCE(TTERM_ICON), IMAGE_ICON, 16, 16, fuLoad);
  2376. memset(&winClass, 0, sizeof(winClass));
  2377. winClass.style = (CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_DBLCLKS);
  2378. winClass.lpfnWndProc = WinProc;
  2379. winClass.cbClsExtra = 0;
  2380. winClass.cbWndExtra = 0;
  2381. winClass.hInstance = g_hI;
  2382. winClass.hIcon = NULL;
  2383. winClass.hCursor = NULL;
  2384. winClass.hbrBackground = NULL;
  2385. winClass.lpszMenuName = NULL;
  2386. winClass.lpszClassName = TTPMENU_CLASS;
  2387. if (::FindWindow(TTPMENU_CLASS, NULL) == NULL) {
  2388. if (::RegisterClass(&winClass) == 0) {
  2389. dwErr = ::GetLastError();
  2390. UTIL_get_lang_msg("MSG_ERROR_WINCLASS", uimsg, sizeof(uimsg),
  2391. "Couldn't register the window class.\n", UILanguageFile);
  2392. ErrorMessage(NULL, dwErr, uimsg);
  2393. return FALSE;
  2394. }
  2395. }
  2396. hWnd = ::CreateWindowEx(0,
  2397. TTPMENU_CLASS,
  2398. "Main Window",
  2399. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  2400. CW_USEDEFAULT,
  2401. CW_USEDEFAULT,
  2402. CW_USEDEFAULT,
  2403. CW_USEDEFAULT,
  2404. (HWND) NULL,
  2405. (HMENU) NULL,
  2406. g_hI,
  2407. NULL);
  2408. if (hWnd == NULL)
  2409. return FALSE;
  2410. while (::GetMessage(&msg, NULL, 0, 0)) {
  2411. ::TranslateMessage(&msg);
  2412. ::DispatchMessage(&msg);
  2413. }
  2414. return TRUE;
  2415. }
Show on old repository browser