Something that was not really working as it should is showing/hiding the different console sub windows. If you start a process, you get the process information, but nothing about the windows, and to show/hide a window, you need a handle to the main window.
An extra layer of complexity is that Ctrack chains sub programs with proxies:
If in the UI settings we flip the show/hide engine switch, we need to make sure that all relevant consoles are affected, also the proxies. In the case of Proxy3 and 4, the process info is not known by engine, engine will have to do the operation, so we still need a way to inform engine about the action. And as a further extension there is the engine as post processor
- The direct proxies can be accessed with CProxyDevice::getMapProxies.
- The engine can be accessed with m_LiveEngineProcessInformation
- In buffered mode the process information is stored in m_BufferProcessInformation
Sequence of commands when changing visibility from the settings dialog:
- CSettings::SetShowConsole
- Send command CCommandShowConsole
- On engine : OnShowConsole
- ShowHideAllProxyWindows
- DebugPrintShowHideConsole
Hiding - showing form the main program DOES NOT WORK
I give up on having the spawning process control the visibility of the console window of the spawned child process.
Here is a transcript of the ordeal
So the only way remaining to control the visibility state of the console windows is to send a command over the TCP connections and control the visibility on the moment of creation.
Second approach
Need to implement:
- ProcessStart makes the console initial visible or not
- Routine to show/hide the console window of the actual process
- 'x' like the close button: hide the console (h already taken for hardware detection)
- 'o' as in open show the console (s already taken to start live)
- 'q' end the program
- CTrack::Message based commands to do the same on the proxies
void SetConsoleVisible(bool visible)
{
HWND hwnd = GetConsoleWindow();
if (!hwnd && visible)
{
// Allocate a new console
if (AllocConsole())
{
// Redirect standard streams to the new console
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
freopen("CONIN$", "r", stdin);
}
hwnd = GetConsoleWindow(); // Re-fetch after allocation
}
if (!hwnd)
return;
ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE);
// Modify extended window styles to control taskbar visibility
long style = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE,
visible ? (style & ~WS_EX_TOOLWINDOW)
: (style | WS_EX_TOOLWINDOW));
if (visible)
{
SetForegroundWindow(hwnd);
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
}
We need to check update the keyboard handling of
- engine
- proxies
- template
- vicon
- leica
Testing
Engine only
- Start with engine invisible => engine should be invisible
- Settings show console => engine visible
- Close ctrack
- Open ctrack => engine visible
- Settings hide console => engine invisible
- Close ctrack
- Open ctrack => engine invisible again
With proxies
- HardwareConfiguration to open template proxy
- Settings => Hide
- Close all
- Start => all should be invisible
- Settings => Show
- Close all
- Start => engine should be visible
- hardware configuration => template should be visible
And the fucking frustration continues 😤
I think I have spend like a fucking week on hiding console windows, wanna shoot some fucking microschoft engineers right now.
🧪 TL;DR from experience
| Flag / Combo | Does it hide the console? | Can you send input? | Notes |
|---|---|---|---|
| CREATE_NO_WINDOW | ✅ | ❌ | No console exists. Can't send chars. |
| CREATE_NEW_CONSOLE + SW_HIDE | ❌ | ✅ | Console appears briefly. |
| CREATE_NEW_CONSOLE + child hides console | ✅ | ✅ | Only reliable way. |
| No flags (inherits parent console) | ❌ | ✅ if interactive | Only works if parent has a console. |
Bottomline : only a console window can hide / show itself
It does need to be created with CREATE_NEW_CONSOLE to send characters to it
So if you want to start it invisible and be able to send characters, you need to pass a parameter like --hide so that the console window can hide itself
So now I need to :
- pass a --hide parameter at startup for engine and proxies
- handle this --hide parameter in main
- replace send Key characters with the next message
- show
- hide
- quit