 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Roland
Joined: 08 Jun 2006 Posts: 244
|
Posted: Thu Sep 06, 2007 1:20 am Post subject: WinCut - cut out piece of window on the fly |
|
|
I can't watch tennis on TV, but would like to follow the Federer-Roddick match later, so I found myself this:
Which is terrible. So I wrote a little snippet of code to cut out the important part:
That's better.
To use it just Shift-Win-Left-Click and drag.
Edit: Changed to ignore the taskbar and desktop. Also you can press Escape now to cancel the operation.
Edit2: Added Shift+Win+Esc hotkey to restore the active window to its proper dimensions.
| Code: | #NoEnv
#SingleInstance force
+#LButton::
Hotkey, esc, cancel, On
cancel:=0
CoordMode, Mouse
MouseGetPos, sx, sy, win
WinGetClass, class, ahk_id%win%
if class in Progman,Shell_TrayWnd
return
WinGetPos, wx, wy,,, ahk_id%win%
Gui, +lastfound +alwaysOnTop +toolwindow -caption
Gui, Color, 00FFFF
WinSet, Transparent, 50
Gui, Show, noActivate
Loop {
if !getKeyState("LButton", "p")
break
ifEqual, cancel, 1, gosub exit
MouseGetPos, x, y
Gui, Show, % "x" sx "y" sy "w" x-sx "h" y-sy
} WinGetPos, gx, gy, w, h
Gui, destroy
WinGetPos, wx, wy,,, ahk_id%win%
x:=gx-wx, y:=gy-wy
WinSet, Region, % x "-" y " " x+w "-" y " " x+w "-" y+h " " x "-" y+h " " x "-" y, ahk_id%win%
Hotkey, esc, cancel, off
return
cancel:
cancel:=1
return
exit:
Hotkey, esc, cancel, off
Gui destroy
exit
+#Esc::
WinSet, Region,, A
return |
The Americans are going DOWN tonight 
Last edited by Roland on Sun Sep 09, 2007 1:46 pm; edited 2 times in total |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1205 Location: USA
|
Posted: Thu Sep 06, 2007 1:22 am Post subject: |
|
|
| Quote: | | The Americans are going DOWN tonight |
Those Da*n Americans anyway!....They suck.  |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1205 Location: USA
|
Posted: Thu Sep 06, 2007 1:27 am Post subject: |
|
|
Good god, I didn't even look at the code......I have never understood the winset, region command...no matter how good the help file is. ...thx
one other thing.....
this line:
| Code: | | Gui, Show, % "x" sx "y" sy "w" x-sx "h" y-sy |
would get interpreted as this: (where N is the variable)
| Code: | | Gui, Show, xNyNwNhN |
unless, the variable contain a trailing space.....i did not look at that. |
|
| Back to top |
|
 |
Mustang
Joined: 17 May 2007 Posts: 375 Location: England
|
Posted: Thu Sep 06, 2007 5:47 am Post subject: |
|
|
Hmm I like this idea of this
But it keeps crashing the window its trying to cut
OS: Vista Ultimate 32-bit |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2557 Location: Australia, Qld
|
Posted: Thu Sep 06, 2007 7:26 am Post subject: |
|
|
| ahklerner wrote: | would get interpreted as this: (where N is the variable)
| Code: | | Gui, Show, xNyNwNhN |
| It actually works without the spaces. Omitting them makes for a cleaner expression.
| Quote: | | But it keeps crashing the window its trying to cut | Works okay for me - Vista Business 32-bit. Actually, WinSet,Region doesn't seem to affect the glass frame (caption bar and border) around the window, other than making them unclickable.
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Thu Sep 06, 2007 9:12 am Post subject: |
|
|
Hej, lex, how do you put thumbnails lilke that, I always wondered  _________________
 |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2557 Location: Australia, Qld
|
Posted: Thu Sep 06, 2007 10:19 am Post subject: |
|
|
It's a feature of ImageShack. When you upload an image, it provides a bunch of "links", including bbCode text to include an image in your post ([img]) and bbCode text to include a thumbnail of the image.
www.imageshack.us |
|
| Back to top |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 244
|
Posted: Thu Sep 06, 2007 12:11 pm Post subject: |
|
|
I just made two small changes to the script (after cutting my taskbar into little shreds yesterday ).
@Mustang & lexikos: Looks like it's a Vista-related problem. One of you should probably report this in Bug Reports (although, I don't know what the status is on compatibility with Vista...). |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2557 Location: Australia, Qld
|
Posted: Thu Sep 06, 2007 2:20 pm Post subject: |
|
|
Yes, definitely a Vista-related problem. I figured it (the glass frame problem) is because Aero ignores the region set by SetWindowRgn (since it only happens when Aero is enabled.) Shame on Microsoft. They probably expect any app that uses SetWindowRgn() to not have a caption/border, or to implement their own.
I also figured it probably isn't a bug within AutoHotkey. A partial workaround for your script could be to automatically remove the border when the region entirely excludes it. (Not a request, just an idea.)
No idea about the crashes Mustang gets. Though I've only used WinSet,Region a couple times, I've never had it crash the target app (or the script.)
Kudos for adding the Escape-to-cancel feature.  |
|
| Back to top |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 244
|
Posted: Thu Sep 06, 2007 4:43 pm Post subject: |
|
|
| Quote: | | A partial workaround for your script could be to automatically remove the border when the region entirely excludes it. (Not a request, just an idea.) |
It might be better if you code that - I wouldn't be able to verify if it works.  |
|
| Back to top |
|
 |
Andreone
Joined: 20 Jul 2007 Posts: 257 Location: Paris, France
|
Posted: Sat Sep 08, 2007 9:21 pm Post subject: |
|
|
| Quote: | | But it keeps crashing the window its trying to cut |
| Quote: | | @Mustang & lexikos: Looks like it's a Vista-related problem. |
Sorry, but the script doesn't work for me either and I'm running XP SP2 (FR). The window I try to cut disappears when I stop the drag. When I restore it clicking the taskbar, nothing is cut. |
|
| Back to top |
|
 |
Ian
Joined: 15 Jul 2007 Posts: 1157 Location: Enterprise, Alabama
|
Posted: Sat Sep 08, 2007 9:29 pm Post subject: |
|
|
Just a tip: You should try to restrict it's use to windows. and have it exclude the Program Manager (Desktop Screen). I accidentally cut out the whole lot of my icons and hed to reset my comp to get them back. _________________ ScriptPad/~dieom/dieom/izwian2k7/Trikster/God
 |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Sun Sep 09, 2007 6:15 am Post subject: |
|
|
nicely done.
maybe a restore hotkey might be useful...
| Code: | +#Esc::
WinSet, Region,, A
return |
or such.. _________________ Joyce Jamce |
|
| Back to top |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 244
|
Posted: Sun Sep 09, 2007 1:39 pm Post subject: |
|
|
| Andreone wrote: | | Quote: | | But it keeps crashing the window its trying to cut |
| Quote: | | @Mustang & lexikos: Looks like it's a Vista-related problem. |
Sorry, but the script doesn't work for me either and I'm running XP SP2 (FR). The window I try to cut disappears when I stop the drag. When I restore it clicking the taskbar, nothing is cut. |
Do you get the gui when you drag?
If not, try adding
If yes, I have no idea what the problem is - you could check if the problem is with the region being calculated incorrectly by putting
| Code: |
msgbox % x "-" y " " x+w "-" y " " x+w "-" y+h " " x "-" y+h " " x "-" y |
before the WinSet command. |
|
| Back to top |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 244
|
Posted: Sun Sep 09, 2007 1:40 pm Post subject: |
|
|
| Quote: | | Just a tip: You should try to restrict it's use to windows. and have it exclude the Program Manager (Desktop Screen). I accidentally cut out the whole lot of my icons and hed to reset my comp to get them back |
You must be running the first version, I already added this. |
|
| 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
|