susam / uncap

Map Caps Lock to Escape or any key to any key
MIT License
1.07k stars 44 forks source link

Add FreeConsole() call to ensure console window always gets hidden #7

Closed navhaxs closed 5 years ago

navhaxs commented 6 years ago

Fix for https://github.com/susam/uncap/issues/6

Steps to reproduce:

  1. Launch a cmder console
  2. Double-click uncap.exe from a File Explorer - rather than launching from a console
  3. Uncap shows an empty console output window

The issue is likely to do with ConEmu's hooking of consoles, but didn't investigate further since this simple fix worked for me

Madsn commented 5 years ago

@susam, maybe this could be merged? :)

susam commented 5 years ago

Thank you, Jeremy (@navhaxs), for creating this pull request and thank you, Mikkel (@Madsn), for reminding me to merge this. Sorry, it took so long to take a look at this pull request. I've not had a Windows laptop with me in the last couple of years, so that's why I it took so long. Finally, today I created a Windows 10 Pro virtual machine on Azure to reproduce this issue and test this pull request.

The root cause of the issue here is that in the presence of Cmder, the FindWindow("ConsoleWindowClass", NULL) call gets a handle to another window (not the window in which Uncap is running), so the ShowWindow(h, SW_HIDE) call later attempts to hide the wrong window instead of the window in which Uncap is running. I will push another fix later that addresses this root cause.

For now, I am merging this pull request as is, so that it remains in the commit history of this project. This pull request resolves the issue by working around the issue with the FreeConsole() call that detaches Uncap from the console regardless of which handle we got with the FindWindow() call.