AutoHotkey Community

It is currently May 26th, 2012, 12:49 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 83 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject:
PostPosted: February 17th, 2007, 12:39 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
Philho, there's a lot to do on this little project, but I will definitely try out these two solutions -thanks again!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Save as BMP?
PostPosted: April 11th, 2007, 6:30 pm 
Could someone please let me know how I might modify this script to save straight to BMP instead of converting to PNG?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 11th, 2007, 4:36 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
I spotted a small error in the script (I assume the script in the first post is the last version?)
Code:
WinGet, hw_frame, id, "Program Manager"   ; Desktop ?
hdc_frame := DllCall( "GetDC", "uint",  hw_frame )

Because the quote marks (") are interpreted literally for commands, hw_frame is always set to zero (0). It just happens to work because:
MSDN wrote:
If this value is NULL, GetDC retrieves the DC for the entire screen.
So you may as well do:
Code:
hdc_frame := DllCall( "GetDC", "uint",  0 )


Report this post
Top
 Profile  
Reply with quote  
 Post subject: window capture
PostPosted: November 6th, 2007, 8:58 am 
Offline

Joined: November 6th, 2007, 8:53 am
Posts: 1
Hi,

your script is very useful, i'm new to autohotkey, and i want to specifically capture a window, not the wholescreen.

thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2007, 5:24 pm 
could you make it so the GDIPlusHelper file is included into the main file?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2007, 7:04 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
no, thats impossible 8)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2007, 3:11 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I would love to see a function created using the code/concepts in this script that takes a screen shot of x size (or fullscreen), so that this can be used in scripts in a more generic fashion.

Something like:
GDIplus_Capture(pFile,pW="",pH="")

I'm trying to figure out all the DllCalls right now and if I can get it working, I'll create a function like this. Just wondering if anyone might have something similar, or be able to easily create it.

Thanks for this very useful code holomind!

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2007, 1:36 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
think there are a few.

one nice one is SEAN's script ... pretty much complete solution... [search and you'll find it]

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2007, 4:28 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
You're right, I didn't notice this before. Now it's linked to this topic in case someone else makes the same mistake :)

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2008, 12:31 am 
Offline

Joined: December 29th, 2007, 2:52 pm
Posts: 1
hi,

Using this script to save numerous screenshots, i encountred the following problem:

After about 74 screenshots i get this mesage : "Error in GdipSaveImageToFile (2: Invalid Parameter) 0" .

After that i can't take screenshot anymore without killing and reloading the script... it's very boring and despite of my invetigations, i can't resolve that problem by myself, in code. Buffer is too small? Is it possible to enlarge it?... If some of you have an idea.. Thanks a lot!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2008, 12:58 am 
Offline

Joined: March 25th, 2007, 3:47 am
Posts: 43
Location: Earth-Moon L2
I've been trying to use PrintWindow or WM_PRINT to capture a specific window like in LiveWindows but I can't seem to get it right.

Code:
#Include %A_ScriptDir%\Common\GDIPlusHelper.ahk

WinWait, AutoHotkey Help
ShotWindow := WinExist()
WinGetPos,,, ShotWindowW, ShotWindowH, ahk_id %ShotWindow%

hdc_frame := DllCall( "GetDC", "uint", ShotWindow )
hdc_buffer := DllCall( "gdi32.dll\CreateCompatibleDC", "uint", hdc_frame )
hbm_buffer := DllCall( "gdi32.dll\CreateCompatibleBitmap", "uint", hdc_frame, "int", ShotWindowW, "int", ShotWindowH )
DllCall( "gdi32.dll\SelectObject", "uint", hdc_buffer, "uint", hbm_buffer )

; Both PrintWindow and WM_PRINT have the same result.
DllCall( "PrintWindow", UInt, ShotWindow, UInt, hdc_buffer, UInt, 0 )
;SendMessage, 0x317, hdc_buffer, 0,, ahk_id %ShotWindow% ; WM_PRINT

/* WM_PRINT flags
PRF_CHECKVISIBLE    0x00000001
PRF_NONCLIENT       0x00000002
PRF_CLIENT          0x00000004
PRF_ERASEBKGND      0x00000008
PRF_CHILDREN        0x00000010
PRF_OWNED           0x00000020
*/
; Nothing changes if I use PRF_NONCLIENT or PRF_CLIENT.

If (GDIplus_Start() != 0)
   Goto GDIplusError

; Copy BMP from DC
DllCall( "gdi32.dll\BitBlt"
   , "uint", hdc_buffer, "int", 0, "int", 0, "int", ShotWindowW, "int", ShotWindowH
   , "uint", hdc_frame,  "int", 0, "int", 0, "uint", 0x00CC0020 )

DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer, uint, 0, uintp, bitmap )

; Save to PNG

If (GDIplus_GetEncoderCLSID(pngEncoder, #GDIplus_mimeType_png) != 0)
   Goto GDIplusError

noParams = NONE
If ( GDIplus_SaveImage(bitmap, "shot_" . A_Now . A_MSec . ".png", pngEncoder, noParams) != 0 )
   Goto GDIplusError
Gosub GDIplusStop

exitapp ; ----------------------------


GDIplusError:
GDIplusStop:
   If (#GDIplus_lastError != "")
      MsgBox 16, GDIplus Test, Error in %#GDIplus_lastError%
   GDIplus_Stop()
Return


Cleanup:
DllCall( "gdi32.dll\DeleteObject", "uint", hbm_buffer )
DllCall( "gdi32.dll\DeleteDC"    , "uint", hdc_frame )
DllCall( "gdi32.dll\DeleteDC"    , "uint", hdc_buffer )
GameCleanup()
ExitApp


I get this output:
Image
  1. It starts at the client area, which was not specified in the options.
  2. It captures screen outside of the window and the window covering it.

I've checked the MSDN documentation on each function but found nothing to suggest this behavior.
It must be some stupid mistake on my part but I'm rather lost in all this. :?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2008, 4:29 pm 
Offline

Joined: March 25th, 2007, 3:47 am
Posts: 43
Location: Earth-Moon L2
Disregard that, I figured it out. I had to delete the BitBlt line.
Thanks for the help though. :roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2008, 2:01 pm 
Offline

Joined: July 11th, 2008, 1:53 pm
Posts: 1
Hi all!

I modified this to just take the shot from the window that is under mouse cursor when you press mouse middle key. I use this while playing online poker to take screenshots of game situations for later analysing.

I had to change the raster operation code of BitBlt call to 0x40CC0020 to capture also the player stats from PokerAce HUD that I'm using.

Thanks for holomind for the original code, this has been really valuable for me!

Code:
#Include GDIPlusHelper.ahk
; see: http://www.autohotkey.com/forum/viewtopic.php?t=12012 for orignal

main:
  FileCreateDir, screens

  counter_f:=0
return

MButton::
SaveImage_Full:

  MouseGetPos, ,, winID
  WinGetPos, winX, winY, winWidth, winHeight, ahk_id %winID%
 
  hdc_frame := DllCall( "GetDC", "uint",  NULL )
  hdc_buffer := DllCall( "gdi32.dll\CreateCompatibleDC"     , "uint", hdc_frame )
  hbm_buffer := DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hdc_frame, "int", winWidth, "int", winHeight )
  r          := DllCall( "gdi32.dll\SelectObject"           , "uint", hdc_buffer, "uint", hbm_buffer )

  counter_f := counter_f +1
  FormatTime, myTime, , yyyyMMdd_hhmmss
  fileNameDestP = screens\S_%myTime%_%counter_f%.png


  If (GDIplus_Start() != 0)
     Goto GDIplusError

  ; Copy BMP from DC
  DllCall( "gdi32.dll\BitBlt"
          , "uint", hdc_buffer, "int", 0, "int", 0, "int", winWidth, "int", winHeight
          , "uint", hdc_frame,  "int", winX, "int", winY, "uint", 0x40CC0020 )

  DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer, uint, 0, uintp, bitmap )

  ; Save to PNG

  If (GDIplus_GetEncoderCLSID(pngEncoder, #GDIplus_mimeType_png) != 0)
     Goto GDIplusError

  noParams = NONE
  If (GDIplus_SaveImage(bitmap, fileNameDestP, pngEncoder, noParams) != 0)
     Goto GDIplusError

  DllCall( "gdi32.dll\DeleteObject", "uint", hbm_buffer )
  DllCall( "gdi32.dll\DeleteDC"    , "uint", hdc_frame )
  DllCall( "gdi32.dll\DeleteDC"    , "uint", hdc_buffer )
Return

GDIplusError:
   If (#GDIplus_lastError != "")
      MsgBox 16, GDIplus Test, Error in %#GDIplus_lastError%
   GDIplus_Stop()
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2008, 2:51 pm 
Offline

Joined: March 18th, 2008, 9:21 am
Posts: 8
Excellent script...I can't believe that what I've been looking for would be contained in a simple AHK script! It can handle even shots from DirectX programs, which is a very big plus. The only thing that should be added would probably be the ability to capture individual windows (Alt+PrntScr) as well as an option to show the pointer or not.

Overall, an amazing job.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2009, 3:24 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Thank you, holomind!
This script proved to work fine on my Win98SE system. It misses however a small detail: cannot handle multiple monitors. It always captures the primary monitor, regardless of screen configuration, active window, etc.

It would be wonderful if it would capture the whole desktop (in my case dual-view 1024x768 + 1024x768 = 2048x768) or allow monitor selection.

Active window selection would also be a plus, as requested previously.

Sean's script mentioned somewhere in this thread does capture the whole 2048x768 desktop area but it only saves a black .bmp. :(

_________________
AHK tools by Drugwash (AHK 1.0.48.05 and Win98SE)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 83 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group