PhilZ as guest Guest
|
Posted: Mon May 12, 2008 5:52 am Post subject: Would making this work require OLE? |
|
|
Ok so i got this script together to capture screen rectangles (with a lot of help. see here and here). The script works nicely...to an extent. All it does is if you press control alt A it will capture a screen rectangle based on the corners you give it. sometimes it just captures the box itself. I added the sleep comment to avert that glitch. any suggestions on that one? Also i thought if it was a clipboard bitmap i could simply paste it in word, openoffice writer, ect...
when i tried it it didn't work. So i am guessing it must be an OLE thing. what do you think? any suggestions? if it is an ole thing, printscreen and altprintscreen have some ole information in the clipboard.
I suppose if it isn't ole, Perhaps i don't put the file to the clipboard correctly.
any ideas?
| Code: | GDIPlus_start()
coordmode, mouse, screen
settimer, rectangle, 100
settimer, rectangle, off
hotkey, lbutton, toggler,off
toggle = 0
return
^!A::
hotkey, lbutton, toggler, on
return
^!S::
filename := cmndlg_save("","Save Screenshot","Portable Network Graphics (*.png)|Jpeg Image (*.jpg)|Graphics Interchange Format (*.gif)|Bitmap Image (*.bmp)|Tagged Image File Format (*.tif)",1, A_username "pictures\screenshots\","png"),
if filename = ;
return
stringright, filetype,filename, 3
GDIplus_LoadBitmapFromClipboard(bitmap)
GDIplus_GetEncoderCLSID(pngEncoder, #GDIplus_mimeType_%filetype%)
GDIplus_SaveImage(bitmap, filename, pngEncoder, noParams)
GDIplus_DisposeImage(bitmap)
return
toggler:
toggle := toggle = 0 ? 1 : 0
if %toggle% {
mousegetpos, x1,y1, win
settimer, rectangle, on
}
else {
hotkey, lbutton, toggler, off
settimer, rectangle, off
gosub capture
}
return
rectangle:
mousegetpos,x2,y2,win2
DllCall("RedrawWindow", "Uint", win, "Uint", 0, "Uint", 0, "Uint", 0x81)
DllCall("RedrawWindow", "Uint", win2, "Uint", 0, "Uint", 0, "Uint", 0x81)
drawrect(x1,y1,x2,y2)
return
capture:
DllCall("RedrawWindow", "Uint", win, "Uint", 0, "Uint", 0, "Uint", 0x81)
DllCall("RedrawWindow", "Uint", win2, "Uint", 0, "Uint", 0, "Uint", 0x81)
sleep, 200
xst:= x1 < x2 ? x1 : x2
yst:= y1 < y2 ? y1 : y2
width := abs(x1-x2)
height := abs(y1-y2)
GDIplus_CaptureScreenRectangle(bitmap, xst, yst, width, height)
return
SetClipboardData(hBitmap)
{
DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
pDIB := DllCall("GlobalLock", "Uint", hDIB)
DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
DllCall("GlobalUnlock", "Uint", hDIB)
DllCall("DeleteObject", "Uint", hBitmap)
DllCall("OpenClipboard", "Uint", 0)
DllCall("EmptyClipboard")
DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
DllCall("CloseClipboard")
}
getfiletype(byref filename) {
stringright, filename, filename, 3
if !(filename = "gif") AND !(filename = "png") AND !(filename = "tif") AND !(filename = "bmp") AND !(filename = "jpg")
return 1 ;the bad thing
else return 0 ;the good thing
}
|
the script also saves a bitmap from the clipboard. It will save it's own bitmaps from the ^!A as well as the !printscreen and printscreen.
the clipboard bitmaps it saves just cannot be pasted into ole programs
Oh yeah it uses Philho's gdi+ wrapper and I copied the setclipboarddata function from Sean's ScreenCapture script |
|