• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision8428 (tree)
Zeit2019-12-02 00:07:57
Autorzmatsuo

Log Message

pGetConsoleWindow() をcompat_winに追加

- GetConsoleWindow() コンソールウィンドウのハンドルを取得

Ändern Zusammenfassung

Diff

--- branches/unicode_buf/teraterm/common/compat_win.cpp (revision 8427)
+++ branches/unicode_buf/teraterm/common/compat_win.cpp (revision 8428)
@@ -63,7 +63,47 @@
6363 HRESULT (WINAPI *pGetDpiForMonitor)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
6464 HMONITOR (WINAPI *pMonitorFromRect)(LPCRECT lprc, DWORD dwFlags);
6565 BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
66+HWND (WINAPI *pGetConsoleWindow)(void);
6667
68+/**
69+ * GetConsoleWindow() と同じ動作をする
70+ * https://support.microsoft.com/ja-jp/help/124103/how-to-obtain-a-console-window-handle-hwnd
71+ */
72+static HWND WINAPI GetConsoleWindowLocal(void)
73+{
74+#define MY_BUFSIZE 1024 // Buffer size for console window titles.
75+ HWND hwndFound; // This is what is returned to the caller.
76+ char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated WindowTitle.
77+ char pszOldWindowTitle[MY_BUFSIZE]; // Contains original WindowTitle.
78+
79+ // Fetch current window title.
80+ DWORD size = GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
81+ if (size == 0) {
82+ DWORD err = GetLastError();
83+ if (err == ERROR_INVALID_HANDLE) {
84+ // コンソールが開いていない
85+ return NULL;
86+ }
87+ }
88+
89+ // Format a "unique" NewWindowTitle.
90+ wsprintf(pszNewWindowTitle, "%d/%d", GetTickCount(), GetCurrentProcessId());
91+
92+ // Change current window title.
93+ SetConsoleTitle(pszNewWindowTitle);
94+
95+ // Ensure window title has been updated.
96+ Sleep(40);
97+
98+ // Look for NewWindowTitle.
99+ hwndFound = FindWindow(NULL, pszNewWindowTitle);
100+
101+ // Restore original window title.
102+ SetConsoleTitle(pszOldWindowTitle);
103+
104+ return hwndFound;
105+}
106+
67107 static const APIInfo Lists_user32[] = {
68108 { "SetLayeredWindowAttributes", (void **)&pSetLayeredWindowAttributes },
69109 { "SetThreadDpiAwarenessContext", (void **)&pSetThreadDpiAwarenessContext },
@@ -101,6 +141,7 @@
101141 static const APIInfo Lists_kernel32[] = {
102142 { "GetFileAttributesW", (void **)&pGetFileAttributesW },
103143 { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW },
144+ { "GetConsoleWindow", (void **)&pGetConsoleWindow },
104145 {},
105146 };
106147
@@ -143,5 +184,9 @@
143184 pSetDlgItemTextW = NULL;
144185 pGetDlgItemTextW = NULL;
145186 }
187+
188+ // GetConsoleWindow特別処理
189+ if (pGetConsoleWindow == NULL) {
190+ pGetConsoleWindow = GetConsoleWindowLocal;
191+ }
146192 }
147-
--- branches/unicode_buf/teraterm/common/compat_win.h (revision 8427)
+++ branches/unicode_buf/teraterm/common/compat_win.h (revision 8428)
@@ -96,6 +96,7 @@
9696 extern int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
9797 extern BOOL (WINAPI *pRemoveFontResourceExA)(LPCSTR name, DWORD fl, PVOID pdv);
9898 extern BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv);
99+extern HWND (WINAPI *pGetConsoleWindow)(void);
99100
100101 #ifdef UNICODE
101102 #define pAddFontResourceEx pAddFontResourceExW
--- branches/unicode_buf/teraterm/teraterm/debug_pp.cpp (revision 8427)
+++ branches/unicode_buf/teraterm/teraterm/debug_pp.cpp (revision 8428)
@@ -36,6 +36,7 @@
3636 #include "../common/tt_res.h"
3737 #include "unicode_test.h"
3838 #include "dlglib.h"
39+#include "compat_win.h"
3940
4041 CDebugPropPage::CDebugPropPage(HINSTANCE inst, TTCPropertySheet *sheet)
4142 : TTCPropertyPage(inst, IDD_TABSHEET_DEBUG, sheet)
@@ -59,7 +60,6 @@
5960 // popup
6061 SetCheck(IDC_DEBUG_POPUP_ENABLE, UnicodeDebugParam.CodePopupEnable);
6162 for (int i = 0; i < _countof(key_list); i++) {
62- const char *key_str = key_list[i].key_str;
6363 SendDlgItemMessage(IDC_DEBUG_POPUP_KEY1, CB_ADDSTRING, 0, (LPARAM)key_list[i].key_str);
6464 SendDlgItemMessage(IDC_DEBUG_POPUP_KEY2, CB_ADDSTRING, 0, (LPARAM)key_list[i].key_str);
6565 if (UnicodeDebugParam.CodePopupKey1 == key_list[i].key_code) {
@@ -72,7 +72,7 @@
7272
7373 // console button
7474 const char *caption;
75- HWND hWnd = GetConsoleWindow();
75+ HWND hWnd = pGetConsoleWindow();
7676 if (hWnd == NULL) {
7777 caption = "Open console window";
7878 } else {
@@ -85,12 +85,12 @@
8585 SetDlgItemTextA(IDC_DEBUG_CONSOLE_BUTTON, caption);
8686 }
8787
88-BOOL CDebugPropPage::OnCommand(WPARAM wParam, LPARAM lParam)
88+BOOL CDebugPropPage::OnCommand(WPARAM wParam, LPARAM)
8989 {
9090 switch (wParam) {
9191 case IDC_DEBUG_CONSOLE_BUTTON | (BN_CLICKED << 16): {
9292 const char *caption;
93- HWND hWnd = GetConsoleWindow();
93+ HWND hWnd = pGetConsoleWindow();
9494 if (hWnd == NULL) {
9595 FILE *fp;
9696 AllocConsole();
@@ -97,7 +97,7 @@
9797 freopen_s(&fp, "CONOUT$", "w", stdout);
9898 freopen_s(&fp, "CONOUT$", "w", stderr);
9999 caption = "Hide console window";
100- HWND hWnd = GetConsoleWindow();
100+ hWnd = pGetConsoleWindow();
101101 HMENU hmenu = GetSystemMenu(hWnd, FALSE);
102102 RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
103103 }
Show on old repository browser