
Steffen
Moderator: DosItHelp
Well done Steffen!aGerman wrote: ↑09 Nov 2020 19:26Found it![]()
We have to call PostQuitMessage for WM_DESTROY.
My original assumption that WMI could be the culprit made me think about alternatives. And indeed I found a much easier way. Instead of passing the console HWND as additional argument it gets now assigned to the user data of the background window. Less dependencies, smaller code, easier processing, quick executable. It really makes a difference![]()
Time is overI swear I leave it alone for a while ...
That's the default in the new code. Option /s can be passed for stretching the image to fit.1. Allow centered placement of image, no stretching?
I tried to implement it but this didn't work properly because it's been interferred by SetWindowPos. However, after using SetWinEventHook this issue has been mitigated. I refrained from explicit minimizing and restoring without seeing any difference. The background window appeared a little earlier after restoring but that's rather because the console is delayed by fading in. Making the backgroud fading too would add more complexity than being benefitial IMO. Eventually I found it reasonable to setup a timer which elapses approximately at the same time the console finalizes with fading in. I think this looks sound now.2. Background window visible a short time after restoring minimized console window. Minimize background if console window is minimized?
It took me some time to figure out why I couldn't bind the hook to the console process. It turned out that GetWindowThreadProcessId is a liar. Conhost.exe owns console windows instead of the shell process. Finally I decided to filter the events later on in the callback function. Instead of updating the background once in 20ms, we react now to the desired events. The background follows more smoothly if the console is dragged. And it allows to post a WM_CLOSE instead of just dropping out of the message loop while the background window is still alive. (I'm pretty sure this is still leaking in the latest release.) However, we don't get this for free. The drawback is that the events are fired for every update of the window that the OS is able to make out. This might happen thousands of times per second. In the beginning I faced almost 50% CPU utilization while moving of the window. (Coming from ~5% using the 20ms polling loop for this case.) I had to update the hook callback to process only two kinds of events. And I had to carefully refactor the message loop to ensure we only execute indispensable code. E.g. the update of the image is performed only once in a two-times redraw sequence. And I removed the WS_POPUP branch because I didn't get for what purpose this was in. FWIW I also tried to outsource the event handling into an asynchronous thread. This caused all kind of havoc though. Seems that the events have to be posted to the message queue to get them aligned.3. Inelegant polling. Use SetWinEventHook instead?
Code: Select all
Usage: cmdbkg ["file.[bmp|jpg|gif|png]" [/t p] [/c bg] [/b] [/s]]
/t Transparency with p = percentage 0..100 (default 33).
/c Color of the background with bg = hex value format RRGGBB
(default is the color of the console buffer's upper left corner
at the time CmdBkg is called).
/b Borders included.
/s Stretch to fit.
Specify no arguments to remove previous background.
Specify /? as first argument to see this help message.
Well there's still room for improvements. Inserting the image is just super expensive.
Haha, sorry for causing those inconveniences