By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!I don't really care. I was just surprised to see it, and curious.To monitor whether the console window has been attached to or detached from a TCMD tab window.
Why do you care?
Still curious ... what does TCC do with that information?To monitor whether the console window has been attached to or detached from a TCMD tab window.
I don't know about Rex's needs, but for yours, Charles, what's below, meant only as a test, works pretty well to tell if TCC has been attached/detached. Below, bInTab() expands L"%_TCTAB" and returns TRUE/FALSE accordingly.I recall doing something similar in PopupFix: start a timer, check the console window's visible/hidden status every n milliseconds. If it has changed from visible to hidden or vice versa, the console may have been attached or detached to Take Command/Console2/ConEmu, so do further checks for all of those and update internal variables....
VOID CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject,
LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
if ( hwnd == global.hWndConsole )
Printf(L"%s a tab!\r\n", bInTab() ? L"In" : L"Not in");
}
// In InitializePlugin
HWINEVENTHOOK hWinEvent = SetWinEventHook(EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE,
global.hThisModule, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
Older TCCs and other apps fare pretty well in TCMD v19 tabs. What will fail without the polling?Required for interprocess communication with TCMD.
Older TCCs and other apps fare pretty well in TCMD v19 tabs. What will fail without the polling?
I don't know about Rex's needs, but for yours, Charles, what's below, meant only as a test, works pretty well to tell if TCC has been attached/detached. Below, bInTab() expands L"%_TCTAB" and returns TRUE/FALSE accordingly.
A P.S. on that. If you could figure out TCC's instance of conhost.exe, you could target that PID with the Win event hook rather than all processes (0). I tested that by watching a CMD be attached/detached using a Win event hook which targeted CMD's conhost. EVENT_OBJECT_SHOW and EVENT_OBJECT_HIDE are generated by the conhost process. I don't know how to get the PID of TCC's conhost ... Rex? ... Charles?Thanks for that.
// This hook targets CONHOST and only receives SHOW/HIDE (0x8002, 0x8003) events.
VOID CALLBACK ShowHideMonitorProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd,
LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
if ( hwnd == global.hWndConsole )
{
// just to see it work
Printf(L"%s\r\n", (event == EVENT_OBJECT_HIDE) ? L"HIDE" : L"SHOW");
}
}
// After getting CONHOST's PID, this hook unhooks itself and sets
// a more appropriate one to watch for console hide or show.
VOID CALLBACK ConHostDiscoveryProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd,
LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
if ( hwnd == global.hWndConsole && global.dwConHostPid == 0 )
{
HANDLE hEventThread = OpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, dwEventThread);
global.dwConHostPid = GetProcessIdOfThread(hEventThread);
CloseHandle(hEventThread);
UnhookWinEvent(hWinEventHook);
SetWinEventHook(EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE, global.hThisModule,
ShowHideMonitorProc, global.dwConHostPid, 0, WINEVENT_OUTOFCONTEXT);
}
}
// in InitializePlugin()
if ( global.hWndConsole != NULL ) // not for detached instances
{
// After getting the PID of CONHOST.EXE, this hook unhooks itself and sets another hook targeting
// only CONHOST, the console window, and the events EVENT_OBJECT_SHOW and EVENT_OBJECT_HIDE.
// Do this only in a thread that pumps messages. Doing it here, in InitializePlugin(), works.
SetWinEventHook(EVENT_MIN, EVENT_MAX, global.hThisModule, ConHostDiscoveryProc, 0, 0, WINEVENT_OUTOFCONTEXT);
}
VOID CALLBACK ShowHideMonitorProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd,
LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
if ( hwnd == global.hWndConsole )
{
// just to see it work
Printf(L"%s\r\n", (event == EVENT_OBJECT_HIDE) ? L"HIDE" : L"SHOW");
}
}
if ( global.hWndConsole != NULL ) // not for detached instances
{
SetWinEventHook(EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE, global.hThisModule,
ShowHideMonitorProc, 0, 0, WINEVENT_OUTOFCONTEXT);
}