 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
pajenn
Joined: 07 Feb 2009 Posts: 384
|
Posted: Mon Apr 26, 2010 8:40 pm Post subject: |
|
|
Anyone here using GDIPlusHelper.ahk with Autohotkey_L?
For over a year I've used wushu's Simple Snapshot Script which #includes GDIPlusHelper.ahk. Now I'm trying to transition to Autohotkey_L/COM_L (unicode) and this favorite of mine isn't working anymore. As far as I can tell the conflict involves GDIplus_GetEncoderCLSID and GDIplus_SaveImage functions.
If anyone here can confirm whether or not this is the case, please let me know, and please also post a fix if you've found one? _________________ Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Tue Apr 27, 2010 8:10 am Post subject: |
|
|
GDI+ uses Unicode strings, so those scripts are designed to convert between Unicode and the native format used by standard AHK, ANSI. I presume you're using the Unicode build of AutoHotkey_L, where these "conversions" are unnecessary and will corrupt the data. Try replacing these two functions from DllCallStruct.ahk (untested):
| Code: | GetUnicodeString(ByRef a, b) {
a := b
}
GetAnsiStringFromUnicodePointer(_unicodeStringPt) {
return StrGet(_unicodeStringPt)
}
| A little extra would be needed for it to also work in an ANSI build.
Btw, tic's GDI+ library is a bit more up to date, but the changes required to get it working in a Unicode build aren't as simple. |
|
| Back to top |
|
 |
feel Guest
|
Posted: Mon Jul 04, 2011 12:40 pm Post subject: capture inactive window |
|
|
Hi!
I'm looking for a way to capture an inactive window to the clipboard.
I saw the code below from holomind but I don't really know how to use it. Could somebody give me a hand? Thanks a lot,
Code:
| Code: |
;task_id :=... window_ID
DllCall("PrintWindow", UInt,task_id, UInt,hdc_buffer, UInt,0)
|
|
|
| Back to top |
|
 |
holomind
Joined: 11 Mar 2006 Posts: 341 Location: Munich, Germany
|
Posted: Mon Jul 04, 2011 7:47 pm Post subject: Re: capture inactive window |
|
|
| feel wrote: | Hi!
I'm looking for a way to capture an inactive window to the clipboard.
I saw the code below from holomind but I don't really know how to use it. Could somebody give me a hand? Thanks a lot,
Code:
| Code: |
;task_id :=... window_ID
DllCall("PrintWindow", UInt,task_id, UInt,hdc_buffer, UInt,0)
|
|
Basically you only copy the "inactive" window with id task_id to the hdc_buffer, which is like a variable which can hold the pixels of the image and then you just save the image to jpg etc. with
DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer, uint, 0, uintp, bitmap )
you need to play with hdc_buffer and hdm_buffer just experiment with the script in the firstpost. |
|
| Back to top |
|
 |
feel Guest
|
Posted: Tue Jul 12, 2011 12:09 pm Post subject: Re: capture inactive window |
|
|
| holomind wrote: | | feel wrote: | Hi!
I'm looking for a way to capture an inactive window to the clipboard.
I saw the code below from holomind but I don't really know how to use it. Could somebody give me a hand? Thanks a lot,
Code:
| Code: |
;task_id :=... window_ID
DllCall("PrintWindow", UInt,task_id, UInt,hdc_buffer, UInt,0)
|
|
Basically you only copy the "inactive" window with id task_id to the hdc_buffer, which is like a variable which can hold the pixels of the image and then you just save the image to jpg etc. with
DllCall( "GDIplus\GdipCreateBitmapFromHBITMAP", uint, hbm_buffer, uint, 0, uintp, bitmap )
you need to play with hdc_buffer and hdm_buffer just experiment with the script in the firstpost. |
Thanks a lot holomind.
I'm pretty much a newbie with autohotkeys and have no idea about DllCalls or windows dll's. I'll try my best but I hope you don't mind if I come back to ask for help if I get stuck.
Regards and thanks.
feel |
|
| Back to top |
|
 |
closed
Joined: 07 Feb 2008 Posts: 509
|
Posted: Tue Jul 12, 2011 1:54 pm Post subject: |
|
|
There is a library that makes it simple to create graphics code for most of us ahk users that do not have Holomind's knowledge
Thanks to Tic http://www.autohotkey.com/forum/topic55454.html
If you can get the handle of the window you want to grab it only takes a few codelines using the gdip functions from Tic.
pBitmap:=Gdip_BitmapFromHWND(hwnd)
Gdip_SetBitmapToClipboard(pBitmap)
example (you need gdip.ahk in the same dir as the program)
| Code: | #Include, Gdip.ahk ;Thanks to Tic http://www.autohotkey.com/forum/topic55454.html
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
;the following 4 lines are just to have a window and its handle for demonstration
SetTitleMatchMode, 2
Run, notepad.exe
WinWait, Notepad
WinGet, hwnd,ID,Notepad
pBitmap:=Gdip_BitmapFromHWND(hwnd)
Gdip_SetBitmapToClipboard(pBitmap)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
ExitApp |
|
|
| Back to top |
|
 |
holomind
Joined: 11 Mar 2006 Posts: 341 Location: Munich, Germany
|
Posted: Tue Jul 12, 2011 2:21 pm Post subject: |
|
|
yes its probably much easier with the library, which i think, evolved out of the experiments with this bmp saving-script. but as i understand the "inactive" windows should be captured, which means it would be better to use the printwindow() function as this can get a snapshot of a window even if it is behind others. (it only must not be minimized or moved out of the "monitor area" else the missing parts will be black.
if flashing windows, changing the order of windows dont disturb. then easiest is to move the window to foreground (win_activate win_id ) and after screenshot back to original z-index or into background.
maybe the printwindow() function is also in the gdip.ahk library.
there is a similar ahk-script which is reading a hdc of a window (which is in background) into another hdc. then you can save this hdc. (which even does not need to be visible) you can create an hdc_buffer (or hdm_buffer) which holds the "copy" of the printwindow and save this one. (i think its not possible to save directly with the dll_call(printwindow) but you need to copy it to a hdc (compatible bitmap buffer) first.
http://www.autohotkey.com/forum/topic11588.html
greetings
daniel (holomind)
this creates a "buffer" to hold the image "in memory" .
| Code: |
hdc_buffer := DllCall("gdi32.dll\CreateCompatibleDC", UInt, hdc_frame) ; buffer
hbm_buffer := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt,hdc_frame, Int,A_ScreenWidth, Int,A_ScreenHeight)
DllCall( "gdi32.dll\SelectObject", UInt,hdc_buffer, UInt,hbm_buffer)
; comment this line for speed but less quality
DllCall( "gdi32.dll\SetStretchBltMode", "uint", hdc_frame, "int", 4 ) ; Halftone better quality with stretch
...
DllCall("PrintWindow", UInt,task_id, UInt,hdc_buffer, UInt,0)
...
and the following lines to copy the data into the said hbm_buffer.
|
the data in the hbm_buffer i think can then simply be saved with the gdip.ahk lib functions. |
|
| Back to top |
|
 |
guest3456
Joined: 10 Mar 2011 Posts: 308
|
Posted: Tue Jul 12, 2011 2:42 pm Post subject: |
|
|
| holomind wrote: | | but as i understand the "inactive" windows should be captured, which means it would be better to use the printwindow() function as this can get a snapshot of a window even if it is behind others. (it only must not be minimized or moved out of the "monitor area" else the missing parts will be black. |
tic's Gdip_BitmapFromHWND() is a wrapper for PrintWindow
| Quote: |
if flashing windows, changing the order of windows dont disturb. then easiest is to move the window to foreground (win_activate win_id ) and after screenshot back to original z-index or into background. |
is it possible to get a window's exact z-index? |
|
| Back to top |
|
 |
holomind
Joined: 11 Mar 2006 Posts: 341 Location: Munich, Germany
|
Posted: Tue Jul 12, 2011 3:00 pm Post subject: |
|
|
if you use printwindow or gdip_getBmpfromwind(hdc), then the zindex of a window will not be changed. its the easiest method. it will make screenshot of window even if it is invisibe behind others. its kind of the next "refresh" of drawing the window is done into the hdc_buffer instead of the visible "desktop".
you can read the order of the windows, which is the order how the windows apear in the taskbar. which is basically the z-index. (i use the term from css/javascript. i don't know if there is a similar concept in MFC-Programming)
| Code: | ; Loop through all active windows-tasks (processes)
WinGet, ids, list,,, Program Manager
Loop, %ids%
{
StringTrimRight, task_id, ids%a_index%, 0 ; find the id of this window
; perhaps we dont need all this infos
winGetTitle, title , ahk_id %task_id%
WinGetClass, class , ahk_id %task_id% ;get Class-name
WinGetPos, x, y ,w,h, ahk_id %task_id%
|
the gdip.ahk, can be downloaded here: |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Jul 16, 2011 8:01 am Post subject: |
|
|
Hi holomind, I've been looking for ages for something like your script: simple, without tools and without send {printscreen}. I'm afraid to ask for help because everybody is going to tell me to search the forum. I have look everywhere and what I find doesnt fit what I need or its too complicated for me. Your script seems perfect but it doesnt work for me, I think it's because I have Windows XP, it says it's a GDIplus error.
What I need is simple: a hotkey that runs an script (printscreen.ahk), and that script sends an screenshot to the printer. I don't mind if it's the whole screen or the active window. It would be cool if it saved the snapshot.png in a folder too, but I don't mind. I thought it would be easy to print an screenshot, but man it's driving me crazy!
If anyone can help or knows about another similar post, apreciate it. |
|
| Back to top |
|
 |
holomind
Joined: 11 Mar 2006 Posts: 341 Location: Munich, Germany
|
Posted: Sun Jul 17, 2011 11:09 pm Post subject: |
|
|
hi guest, there is an example to print a file with ahk. here they create a full document by drawing, i think this can be simplified to just put the captured bitmap (hbm) onto the document and then use the printing function.
printing graphics in AHK
or here
Module: Printing Edits box text Function
Gdip.dll is already available on Windows-XP, so this should not be a problem. but maybe you need to copy the GDIP-AHK Library to your Script-Folder or in the Global AHK-Library Folder.
With Autohotkey it also should be easy to remap the real "PrntScreen" button on the keyboard and some alternatives for smaller keyboards like netbooks or VMWare-Mode of Windows Run in OSX which dont have printscreen buttons any more.
With the help of the Library from Philho it should be a quite short script to provide your application, also we can try to provide a complete script for user "feel" which is the library to have clean code. and be an example for others to play and modify the code. |
|
| Back to top |
|
 |
feel Guest
|
Posted: Tue Jul 19, 2011 10:32 am Post subject: |
|
|
Hi all!
Thanks a lot for your help!
I moreless got it working. I use this for continously obtaining frames from an IP camera stream. I wanted to do it as nonactive window to keep the pc usable. I was able to make the window transparent and seems to keep grabbing but I wasn't able to obtain the images when the window is minimized.
Do you guys know if it is possible to obtain the images when the window is minimized?
I though about trying a trick, let me know if you think this is possible:
-When the minimize button is pressed the window is not minimized but made transparent. When that window taskbar button is pressed (maybe when it turns active?) the window is turned non-transparent.
In case someone could find it useful here's what I've done by-now:
I placed in the same folder gdiplus.dll and the Gdip script.
Then I added a script very similar to the one shown above:
| Code: |
#Include, Gdip.ahk ;Thanks to Tic http://www.autohotkey.com/forum/topic55454.html
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
SetTitleMatchMode, 2
WinGet, hwnd, ID, Dispositivo(IP_Camera) - Google Chrome
WinSet, Transparent, 0, Dispositivo(IP_Camera) - Google Chrome
pBitmap:=Gdip_BitmapFromHWND(hwnd)
Gdip_SetBitmapToClipboard(pBitmap)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
ExitApp
|
holomind were you proposing strip the part used from the gdip script to add it to the one I use?
Please let me know your thoughts.
Regards and thanks,
feel |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Jul 19, 2011 12:07 pm Post subject: |
|
|
| If you want to minimize to get it out of the way when using the pc ,you could instead just move it offscreen using winmove. |
|
| Back to top |
|
 |
holomind
Joined: 11 Mar 2006 Posts: 341 Location: Munich, Germany
|
Posted: Tue Jul 19, 2011 12:29 pm Post subject: |
|
|
| Anonymous wrote: | | If you want to minimize to get it out of the way when using the pc ,you could instead just move it offscreen using winmove. |
yes i can confirm that, printwindow does not work with minimized windows. but it works if the window is even moved out of the visible part of the desktop. |
|
| Back to top |
|
 |
holomind
Joined: 11 Mar 2006 Posts: 341 Location: Munich, Germany
|
Posted: Tue Jul 19, 2011 12:42 pm Post subject: |
|
|
| Code: | If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
} |
this looks messy to me, why is there no funktion wich handles the errormessage already in the gdip.ahk library.
so one could just write like
| Code: |
pToken := Gdip_Startup_Ok()
; and in gdip.ahk file
Gdip_Startup_Ok()
{
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
return pToken
}
|
also the pToken could be handled as a global variable in the Gdip.ahk directly. as nobody will start use 2 tokens at the same time. then the code would be cleaner.
Did the AHK Forum change the message id s, or was the thread reorganized?
i think the include-line should be now:
| Code: |
#Include, Gdip.ahk ; Thanks to Tic http://www.autohotkey.com/forum/topic32238.html
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|