The MASM Forum
Microsoft 64 bit MASM => Examples => Topic started by: Vortex on May 29, 2018, 04:29:54 AM
-
Here is a console application saving the desktop to a bitmap file. No any COM or GDI+ techniques and just plain API.
Steps to save the desktop to a bitmap :
- Get the width and height of the desktop
- Get the device context ( DC ) of the desktop and create a compatible DC
- Create a compatible bitmap.
- Copy the image to the new DC.
- Fill the BITMAPINFOHEADER and BITMAPFILEHEADER structures.
- Get the bits of the bitmap to be saved to disc.
- Save the bitmap structures and color data to disc.
Usage :
SaveDesktop.exe test.bmp
The default bit depth is 24.
Any third parameter to set the bit depth to 32 :
SaveDesktop.exe test2.bmp 32
-
:greenclp: This is great! I was wishing to have an app to make snapshots of my desktop, but i didn't wanted bloatware! You are a genius, thanks for sharing this! :biggrin:
-
It works well.... however, when I run it from a batch file it captures the command window in front of the intended target.
How would one run the program and avoid such instances?
-
Open a cmd, put it in a corner of the screen and then run the program (using the options needed) :idea:
This program is also very useful to play a little pranks to my girl (who knows little about PCs...) When the .bmp is full sized you can move the mouse above of the image but nothing seems to work when you do clicks on the icons! :badgrin:
-
Here is what it looks like using "run" instead of the cmd prompt. (converted it to .gif to reduce filesize)
Perhaps if you included a timer into the mix to allow closing the command window..... ;)
But other than that I think it's a great little program.
I think if the timer was added, it could be a production-ready, commercially viable program. :biggrin:
-
Trick is with screen capture is to hide the calling app first, grab the screen then show the caller again.
-
This is what i get when i simple resize the command line (cmd.exe). Sorry for the big image Hutch you can delete this later...
-
...hide the calling app first, grab the screen then show the caller again.
Sounds like you've done that before. :t
A slight delay in the capture could also allow the caller to close. A few milliseconds should be plenty. :bgrin:
I might just try to do that myself.... (but 32 bit...)
@ felipe...
but the cmd window still muddies up an otherwise good screen capture. That was my whole point.
-
Or possibly add a little code to check when the calling program closes.
just after closing the command window for instance, the screen capture would take place.
Of course if a timer were use, it could lead to recording an animation of sorts. Possibly for software demo?? :idea:
This topic is bringing so many possibilities to mind.
-
@ felipe...
but the cmd window still muddies up an otherwise good screen capture. That was my whole point.
Well, you know how it is, you can't satisfy to all... ;)
But it surely wholes my needs of screenshots :icon14:. If i will have to choose (actually i already did :biggrin:) between this nice assembly program and some bloatware...guess what... :idea:
-
If i will have to choose (actually i already did :biggrin:) between this nice assembly program and some bloatware...guess what... :idea:
Oh, you are so right about that. :t
Such a simple little program is more than sufficient. Good job, Vortex.
-
Thanks for the feedback. The console window is now hidden while capturing the screen :
invoke GetConsoleWindow
mov hwnd,rax
invoke ShowWindow,rax,SW_HIDE
invoke Sleep,300
.
.
.
invoke ShowWindow,hwnd,SW_SHOW
ret
New upload at the top.
-
Thanks again... :t
-
Hi felipe,
About your image : sorry, if you encountered a problem could you please help me to reproduce the issue? Thanks.
-
I don't understand vortex, i have found no problems...You mean in the future? :idea:
-
Sorry felipe. My apologies. I could not understand the image you posted. What are those symbols? Everything is fine. Sorry again.
-
Thanks for the feedback.....
New upload at the top.
You're the man, Vortex. :t. Thank you very much, your correction is exactly what I had in mind.
I'll check it out. when I get home
-
I'll check it out. when I get home
yup, it works very well now. :bgrin:
attached jpg reduced in size 50%. The full bmp is perfect in every respect.
-
Oh i see Vortex, it's just i didn't wanted to show my desktop (is a mess, you don't want to see it :redface:), so i did a snapshot of a stupid program that i did before (not trying to promete it, really... :idea:). Yes this app is real fantastic, it not only make snapshots of the desktop, it can do snapshots of running apps (as zedd151 show us too)! :greenclp:
-
.... Yes this app is real fantastic, it not only make snapshots of the desktop, it can do snapshots of running apps...
Yes, it is perfect now. H e knew exactly the fixes I was talking about. :t
of a stupid program that i did
Nothing is stupid if you gained experience from it. And besides it was one of the catalysts for hutch opening the Game Development forum
-
@ Vortex.
I made an sfx (self-extracting) executable for your screen capture tool. Now a shortcut for it can be placed on the taskbar. (That is how I use it)
The sfx executable contains your original program and a batch file to run it. The resulting .bmp is placed on the %userprofile%\Desktop.
To use:
Click on the 'VortexScrCap.exe' file and it unzips in your Temp folder, runs the batch file which in turn runs your program to make a screen capture. After the screen capture is done, it automatically deletes the files from the Temp folder. - and places the resulting .bmp on the current users Desktop. 8)
And thans again, this is a very handy tool.
-
Hi zedd,
Thanks but the tool didn't save the captured image in my system. Could I propose some small modifications?
SaveDesktop.exe "%USERPROFILE%\desktop\capture.bmp"
The double quotes should solve the problems in Windows XP. For example :
C:\Documents and Settings\Administrator\Desktop
-
C:\Documents and Settings\Administrator\Desktop
What OS are you runnin? xp?
I only Have Windows 7 and WIndows 10 here. I made the sfx so I could have an easy shortcut on my taskbar. I have no way of testing it on older systems
I could post another with the double quotes lemme see...
Okay here it is, try this one...
-
Hi zedd,
Yes, my operating system is XP but no worries. I can try your SFX archive on Windows 7. Here is another version of my application rebuilt as Windows GUI application. No any annoying console window.
-
Doesn't work for me. Windows 7 Ultimate SP1 :(
I even tried running it from a batch file as in the previous version...
Nope, I take that back it runs from the batch file as the previous. I overlooked specifying the output file name. ::)
No GUI though. Did you post the right version? I'm looking at your source code right now...
-
Must be a mistake on your part...
lea rsi,buffer
invoke ParseCmdLine,rsi
cmp rax,2
jnb @f
invoke StdOut,ADDR message <--- not Window GUI.
ret
:(
-
Here is how I am testing :
H:\coding\savedesktop\savedesktop.exe H:\coding\savedesktop\desktop.bmp
The application is built as GUI but it has no any graphical interface like a dialog box. An easy trick :
Changed from :
\masm32\bin\polink /SUBSYSTEM:CONSOLE /LARGEADDRESSAWARE /ENTRY:start SaveDesktop.obj ParseCmdLine.obj
to
\masm32\bin\polink /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /ENTRY:start SaveDesktop.obj ParseCmdLine.obj
This method avoids the flashing console screen.
-
Hi zedd,
invoke StdOut,ADDR message <--- not Window GUI.
You can omit that line. It has no any meaning for the version without console.
-
Duh! WHen you said GUI, I was expecting a window. :redface:
So it is still a console 'type' program that still needs the CommandLine arg... Now I got it. I know I didn't see CreateWindow anywhere,
I thouhgt you posted the wrong version inadvertantly. You just removed the console window from the mix.
So then it works as advertised. :t
-
I just tried using the new version in an sfx archive. It captures not the command window from your program but now the command window from the batch file. :( I think I like the 'b' version better.
-
Hi zedd,
You can write a simple Visual Basic script to avoid the console window displayed by batch files :
Capture.vbs :
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("H:\masm32\SaveDesktop.exe H:\masm32\capture.bmp")
Set objShell = Nothing
Also, you have to take in account the paths with space characters in the script files. An example :
https://stackoverflow.com/questions/28379207/launch-program-from-vbscript?rq=1