Commit MetaInfo
Log Message
pGetConsoleWindow() をcompat_winに追加
- GetConsoleWindow() コンソールウィンドウのハンドルを取得
Change Summary
Incremental Difference
| | @@ -63,7 +63,47 @@ | 63 | 63 | HRESULT (WINAPI *pGetDpiForMonitor)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
| 64 | 64 | HMONITOR (WINAPI *pMonitorFromRect)(LPCRECT lprc, DWORD dwFlags);
| 65 | 65 | BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
| | 66 | +HWND (WINAPI *pGetConsoleWindow)(void);
| 66 | 67 |
| | 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 | +
| 67 | 107 | static const APIInfo Lists_user32[] = {
| 68 | 108 | { "SetLayeredWindowAttributes", (void **)&pSetLayeredWindowAttributes },
| 69 | 109 | { "SetThreadDpiAwarenessContext", (void **)&pSetThreadDpiAwarenessContext },
|
| | @@ -101,6 +141,7 @@ | 101 | 141 | static const APIInfo Lists_kernel32[] = {
| 102 | 142 | { "GetFileAttributesW", (void **)&pGetFileAttributesW },
| 103 | 143 | { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW },
| | 144 | + { "GetConsoleWindow", (void **)&pGetConsoleWindow },
| 104 | 145 | {},
| 105 | 146 | };
| 106 | 147 |
|
| | @@ -143,5 +184,9 @@ | 143 | 184 | pSetDlgItemTextW = NULL;
| 144 | 185 | pGetDlgItemTextW = NULL;
| 145 | 186 | }
| | 187 | +
| | 188 | + // GetConsoleWindow特別処理
| | 189 | + if (pGetConsoleWindow == NULL) {
| | 190 | + pGetConsoleWindow = GetConsoleWindowLocal;
| | 191 | + }
| 146 | 192 | }
| 147 | | -
|
| | @@ -96,6 +96,7 @@ | 96 | 96 | extern int (WINAPI *pAddFontResourceExW)(LPCWSTR name, DWORD fl, PVOID res);
| 97 | 97 | extern BOOL (WINAPI *pRemoveFontResourceExA)(LPCSTR name, DWORD fl, PVOID pdv);
| 98 | 98 | extern BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv);
| | 99 | +extern HWND (WINAPI *pGetConsoleWindow)(void);
| 99 | 100 |
| 100 | 101 | #ifdef UNICODE
| 101 | 102 | #define pAddFontResourceEx pAddFontResourceExW
|
| | @@ -36,6 +36,7 @@ | 36 | 36 | #include "../common/tt_res.h"
| 37 | 37 | #include "unicode_test.h"
| 38 | 38 | #include "dlglib.h"
| | 39 | +#include "compat_win.h"
| 39 | 40 |
| 40 | 41 | CDebugPropPage::CDebugPropPage(HINSTANCE inst, TTCPropertySheet *sheet)
| 41 | 42 | : TTCPropertyPage(inst, IDD_TABSHEET_DEBUG, sheet)
|
| | @@ -59,7 +60,6 @@ | 59 | 60 | // popup
| 60 | 61 | SetCheck(IDC_DEBUG_POPUP_ENABLE, UnicodeDebugParam.CodePopupEnable);
| 61 | 62 | for (int i = 0; i < _countof(key_list); i++) {
| 62 | | - const char *key_str = key_list[i].key_str;
| 63 | 63 | SendDlgItemMessage(IDC_DEBUG_POPUP_KEY1, CB_ADDSTRING, 0, (LPARAM)key_list[i].key_str);
| 64 | 64 | SendDlgItemMessage(IDC_DEBUG_POPUP_KEY2, CB_ADDSTRING, 0, (LPARAM)key_list[i].key_str);
| 65 | 65 | if (UnicodeDebugParam.CodePopupKey1 == key_list[i].key_code) {
|
| | @@ -72,7 +72,7 @@ | 72 | 72 |
| 73 | 73 | // console button
| 74 | 74 | const char *caption;
| 75 | | - HWND hWnd = GetConsoleWindow();
| | 75 | + HWND hWnd = pGetConsoleWindow();
| 76 | 76 | if (hWnd == NULL) {
| 77 | 77 | caption = "Open console window";
| 78 | 78 | } else {
|
| | @@ -85,12 +85,12 @@ | 85 | 85 | SetDlgItemTextA(IDC_DEBUG_CONSOLE_BUTTON, caption);
| 86 | 86 | }
| 87 | 87 |
| 88 | | -BOOL CDebugPropPage::OnCommand(WPARAM wParam, LPARAM lParam)
| | 88 | +BOOL CDebugPropPage::OnCommand(WPARAM wParam, LPARAM)
| 89 | 89 | {
| 90 | 90 | switch (wParam) {
| 91 | 91 | case IDC_DEBUG_CONSOLE_BUTTON | (BN_CLICKED << 16): {
| 92 | 92 | const char *caption;
| 93 | | - HWND hWnd = GetConsoleWindow();
| | 93 | + HWND hWnd = pGetConsoleWindow();
| 94 | 94 | if (hWnd == NULL) {
| 95 | 95 | FILE *fp;
| 96 | 96 | AllocConsole();
|
| | @@ -97,7 +97,7 @@ | 97 | 97 | freopen_s(&fp, "CONOUT$", "w", stdout);
| 98 | 98 | freopen_s(&fp, "CONOUT$", "w", stderr);
| 99 | 99 | caption = "Hide console window";
| 100 | | - HWND hWnd = GetConsoleWindow();
| | 100 | + hWnd = pGetConsoleWindow();
| 101 | 101 | HMENU hmenu = GetSystemMenu(hWnd, FALSE);
| 102 | 102 | RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
| 103 | 103 | }
|
Show on old repository browser
|