• R/O
  • SSH
  • HTTPS

ttssh2:


File Info

Rev. 7509
Size 96,279 bytes
Time 2019-03-25 22:47:32
Author zmatsuo
Log Message

クリップボード内容表示ダイアログをHiDPI化
dlglib.c,h ANSI/UNICODE対応,IsExistFont(),SetDialogFont()(ダイアログフォントの初期化) 追加
dlglib_cpp.cpp 追加、ダイアログAPIラッパ
dlg_tmpl.cpp 追加、ダイアログテンプレート操作
i18n.c,h ANSI/UNICODE対応,SetI18DlgStrs(),SetI18MenuStrs()追加
ttlib.c,h ANSI/UNICODE対応

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