Author Topic: Handling bitmaps  (Read 341 times)

Vortex

  • Member
  • *****
  • Posts: 1795
Handling bitmaps
« 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 :

Code: [Select]
SaveDesktop.exe test.bmp
The default bit depth is 24.

Any third parameter to set the bit depth to 32 :

Code: [Select]
SaveDesktop.exe test2.bmp 32
« Last Edit: May 30, 2018, 03:06:27 AM by Vortex »

felipe

  • Member
  • ****
  • Posts: 825
  • Eagles are just great!
Re: Handling bitmaps
« Reply #1 on: May 29, 2018, 11:58:19 AM »
 :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:

Felipe.

zedd151

  • Member
  • ****
  • Posts: 583
  • -------------
Re: Handling bitmaps
« Reply #2 on: May 29, 2018, 12:12:17 PM »
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?

__________________________________________________________________
I'll be back to coding soon....

felipe

  • Member
  • ****
  • Posts: 825
  • Eagles are just great!
Re: Handling bitmaps
« Reply #3 on: May 29, 2018, 12:18:55 PM »
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:
Felipe.

zedd151

  • Member
  • ****
  • Posts: 583
  • -------------
Re: Handling bitmaps
« Reply #4 on: May 29, 2018, 12:22:11 PM »
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:

__________________________________________________________________
I'll be back to coding soon....

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5427
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Handling bitmaps
« Reply #5 on: May 29, 2018, 12:31:17 PM »
Trick is with screen capture is to hide the calling app first, grab the screen then show the caller again.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

felipe

  • Member
  • ****
  • Posts: 825
  • Eagles are just great!
Re: Handling bitmaps
« Reply #6 on: May 29, 2018, 12:32:36 PM »
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...
Felipe.

zedd151

  • Member
  • ****
  • Posts: 583
  • -------------
Re: Handling bitmaps
« Reply #7 on: May 29, 2018, 12:36:54 PM »
...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. 




__________________________________________________________________
I'll be back to coding soon....

zedd151

  • Member
  • ****
  • Posts: 583
  • -------------
Re: Handling bitmaps
« Reply #8 on: May 29, 2018, 12:43:56 PM »
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.

__________________________________________________________________
I'll be back to coding soon....

felipe

  • Member
  • ****
  • Posts: 825
  • Eagles are just great!
Re: Handling bitmaps
« Reply #9 on: May 29, 2018, 12:46:31 PM »
@ 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:
Felipe.

zedd151

  • Member
  • ****
  • Posts: 583
  • -------------
Re: Handling bitmaps
« Reply #10 on: May 29, 2018, 12:48:46 PM »
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.

__________________________________________________________________
I'll be back to coding soon....

Vortex

  • Member
  • *****
  • Posts: 1795
Re: Handling bitmaps
« Reply #11 on: May 30, 2018, 03:05:53 AM »
Thanks for the feedback. The console window is now hidden while capturing the screen :

Code: [Select]
invoke  GetConsoleWindow
mov     hwnd,rax
invoke  ShowWindow,rax,SW_HIDE
invoke  Sleep,300
.
.
.
invoke  ShowWindow,hwnd,SW_SHOW
ret

New upload at the top.

felipe

  • Member
  • ****
  • Posts: 825
  • Eagles are just great!
Re: Handling bitmaps
« Reply #12 on: May 30, 2018, 04:10:46 AM »
Thanks again... :t
Felipe.

Vortex

  • Member
  • *****
  • Posts: 1795
Re: Handling bitmaps
« Reply #13 on: May 30, 2018, 04:17:40 AM »
Hi felipe,

About your image : sorry, if you encountered a problem could you please help me to reproduce the issue? Thanks.

felipe

  • Member
  • ****
  • Posts: 825
  • Eagles are just great!
Re: Handling bitmaps
« Reply #14 on: May 30, 2018, 04:41:03 AM »
I don't understand vortex, i have found no problems...You mean in the future?  :idea:
Felipe.