CmdBkg - use bitmap as background to console window

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: CmdBkg - use bitmap as background to console window

#46 Post by misol101 » 15 Jun 2020 08:06

VooDooGuito wrote:
02 Jun 2020 11:02
Hi dudes, there are a way to use transparency 100 without cover the prompt?
No that won’t work, the transparency affects every part of the cmd window, text included.

AgamSol
Posts: 3
Joined: 20 Oct 2020 16:46

Re: CmdBkg - use bitmap as background to console window

#47 Post by AgamSol » 30 Oct 2020 13:31

Hello again, where can i get bmp images ?
i tried to convert png image to bmp image but it says "Cmdbkg error: Unable to load bitmap"

will you add other image formats in future ?

AgamSol
Posts: 3
Joined: 20 Oct 2020 16:46

Re: CmdBkg - use bitmap as background to console window

#48 Post by AgamSol » 30 Oct 2020 16:46

Why does the title change to kill when i load background ? is it possible to remove ?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#49 Post by aGerman » 01 Nov 2020 14:48

i tried to convert png image to bmp image but it says "Cmdbkg error: Unable to load bitmap"
Can be done using Paint (mspaint.exe). Ships with Windows.
For the current version of CmdBkg make sure the file name doesn't contain spaces or other special characters.
Why does the title change to kill when i load background ? is it possible to remove ?
That's hardcoded. The temporary update of the title is required to make the tool work properly.


@misol101
I'm attaching a slightly updated source code. Feel free to use it for an upcoming version.
Mainly it addresses the following:
- a variable with 64000 bytes of stack memory is critical
- string "_secondRun_" should be inserted into the original command line because surrounding quotes are already removed if it gets rearranged out of the arguments
- a combination of whitespaces is used rather than the word "Kill" and the updated title lasts 3*POLL_INTERVAL which should be more than long enough

Steffen
Attachments
cmdbkg_C_source.zip
(3.44 KiB) Downloaded 5851 times

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: CmdBkg - use bitmap as background to console window

#50 Post by misol101 » 01 Nov 2020 18:38

aGerman wrote:
01 Nov 2020 14:48
- a variable with 64000 bytes of stack memory is critical
- string "_secondRun_" should be inserted into the original command line because surrounding quotes are already removed if it gets rearranged out of the arguments
- a combination of whitespaces is used rather than the word "Kill" and the updated title lasts 3*POLL_INTERVAL which should be more than long enough
Thanks Steffen, seems like reasonable changes. By critical I assume you mean safety critical, since 64k is not so much actually, Windows programs are supposed to have a 1Mb stack. Bad form though, I agree, especially since I'm not buffer checking the strcats...oops
Not completely convinced poll*3 is always enough, Windows might be busy with other stuff in the worst case. Anyway, 500ms might not be enough either in extreme cases.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#51 Post by aGerman » 02 Nov 2020 05:21

Windows programs are supposed to have a 1Mb stack.
Yes, thats true. However, I've read recommendations that a stack variable should rather not exceed 1024 bytes to take care of stack frames. Also, Visual Studio complained about this variable when I enabled all warnings.
especially since I'm not buffer checking the strcats...oops
I've not been too concerned about that :lol: But I'm always concerned seeing strcat in general. Especially if it is called repeatedly in a loop. "Shlemiel the painter's algorithm" https://www.joelonsoftware.com/2001/12/ ... to-basics/
Anyway, 500ms might not be enough either in extreme cases.
That was my consideration, too. If everything works well, 2*poll is good enough. I've chosen 3* to have a little more buffer. However as you already wrote in your TODOs, it's rather a workaround right now ... Maybe I find some time to work on it.

Steffen

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#52 Post by aGerman » 02 Nov 2020 18:04

OK, I come up with a possibility to avoid the title update. I still had to work around the broken process chain because eventually the background window has no existing parent process anymore. I just insert another argument token which contains the console HWND.
Now we can try to find the process where the command line contains " _secondRun_ <hwnd>" (<hwnd> = HEX string representing the console window handle). This is quite unique because a window handle doesn't exist twice at the same time. Then I walk along: PID -> main window handle of the process -> sending WM_CLOSE. Certainly more complicated, but you don't have to compare the title all the time in the polling loop, and I think it's more reliable.

Steffen
Attachments
cmdbkg_C_source3.zip
(4.7 KiB) Downloaded 6026 times

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#53 Post by aGerman » 03 Nov 2020 13:07

Found a bug. New file above...

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: CmdBkg - use bitmap as background to console window

#54 Post by misol101 » 04 Nov 2020 12:46

aGerman wrote:
03 Nov 2020 13:07
Found a bug. New file above...
I don't have much time to look at this at the moment but I like the idea of geting rid of the title polling and seems that it should work well.

I Will make a new release eventually

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#55 Post by aGerman » 04 Nov 2020 13:31

I could also offer to extend the supported images formats, at least for for JPEG and GIF. I'm not too experienced with graphics stuff though. That's why I didn't find any working possibility to support PNG yet.

Steffen

//EDIT: Eventually I found a way. Although it's been a mess to figure out how to work with GDI+ in C :lol:
//EDIT2: Read the image file only once. (static variable for the HBITMAP)
Attachments
cmdbkg_C_source6.zip
(5.11 KiB) Downloaded 5755 times

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#56 Post by aGerman » 08 Nov 2020 16:27

Found two regressions:
- if rapidly called subsequently, the prior background process might not have been closed
- the polling loop used more CPU resources as it should
That's been fixed, along with quite a bit of code updates and refactoring.

I don't want to fork the tool. However, for some beta testing you can find the compiled app, files for testing, and the source code in the attached ZIP. Just in case you want to give some feedback of how it works for you. Once Mikael comes up with a new release I'll remove it.
// EDIT Removed as promised.

Steffen

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: CmdBkg - use bitmap as background to console window

#57 Post by misol101 » 09 Nov 2020 12:03

As far as I could tell the new version works as expected.

The archive linked in the first post has now been updated to v1.2.

I did not make any changes to Steffens new version except updated the resource file, updated the credits in code/help (as this is now very much a joint effort), and recompiled.

Pretty neat to have jpg/png/gif support!

List of changes are:

1. In addition to BMP, CmdBkg now also support JPG, PNG, and GIF (non-animated) images.
2. Supports spaces and special characters in file names
3. The window title no longer momentarily changes to "kill" when running CmdBkg
Last edited by misol101 on 09 Nov 2020 15:55, edited 1 time in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#58 Post by aGerman » 09 Nov 2020 14:55

Thanks Mikael!

There's still one thing bothering me. The exit(0) in the message callback will most likely leak. But I didn't get the thing working for subsequent calls without this shortcut. I'm still about to figure out why. If I can fix this we will be able to just use DefWindowProc again. It seems to be related to some weird behavior of how WMI is getting updated.

Steffen

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: CmdBkg - use bitmap as background to console window

#59 Post by aGerman » 09 Nov 2020 19:26

Found it :D
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 8)

I swear I leave it alone for a while now :lol:

Steffen
Attachments
cmdbkg_C_source8.zip
(4.26 KiB) Downloaded 5804 times

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: CmdBkg - use bitmap as background to console window

#60 Post by miskox » 11 Nov 2020 07:09

I really miss that I don't *speak* 'C' something.... Never had a chance to learn it (I used to program in Cobol, Visual Basic, DCL, lately PureBasic and some in disassembler (Z80 and SC61860)). Now I am too old I guess (some might say 'you are never too old').

Saso

Post Reply