AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WinCut - cut out piece of window on the fly
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Thu Sep 06, 2007 1:20 am    Post subject: WinCut - cut out piece of window on the fly Reply with quote

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. Shocked So I wrote a little snippet of code to cut out the important part:



That's better. Smile

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 Wink


Last edited by Roland on Sun Sep 09, 2007 1:46 pm; edited 2 times in total
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Thu Sep 06, 2007 1:22 am    Post subject: Reply with quote

Quote:
The Americans are going DOWN tonight

Those Da*n Americans anyway!....They suck. Shocked
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1205
Location: USA

PostPosted: Thu Sep 06, 2007 1:27 am    Post subject: Reply with quote

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
View user's profile Send private message
Mustang



Joined: 17 May 2007
Posts: 375
Location: England

PostPosted: Thu Sep 06, 2007 5:47 am    Post subject: Reply with quote

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
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2557
Location: Australia, Qld

PostPosted: Thu Sep 06, 2007 7:26 am    Post subject: Reply with quote

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. Smile

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. Shocked

Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Thu Sep 06, 2007 9:12 am    Post subject: Reply with quote

Hej, lex, how do you put thumbnails lilke that, I always wondered Smile Confused
_________________
Back to top
View user's profile Send private message MSN Messenger
Lexikos



Joined: 17 Oct 2006
Posts: 2557
Location: Australia, Qld

PostPosted: Thu Sep 06, 2007 10:19 am    Post subject: Reply with quote

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
View user's profile Send private message
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Thu Sep 06, 2007 12:11 pm    Post subject: Reply with quote

I just made two small changes to the script (after cutting my taskbar into little shreds yesterday Rolling Eyes ).

@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
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2557
Location: Australia, Qld

PostPosted: Thu Sep 06, 2007 2:20 pm    Post subject: Reply with quote

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. Wink 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. Wink
Back to top
View user's profile Send private message
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Thu Sep 06, 2007 4:43 pm    Post subject: Reply with quote

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. Wink
Back to top
View user's profile Send private message
Andreone



Joined: 20 Jul 2007
Posts: 257
Location: Paris, France

PostPosted: Sat Sep 08, 2007 9:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Ian



Joined: 15 Jul 2007
Posts: 1157
Location: Enterprise, Alabama

PostPosted: Sat Sep 08, 2007 9:29 pm    Post subject: Reply with 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.
_________________
ScriptPad/~dieom/dieom/izwian2k7/Trikster/God

Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 422
Location: Galil, Israel

PostPosted: Sun Sep 09, 2007 6:15 am    Post subject: Reply with quote

nicely done.

maybe a restore hotkey might be useful...

Code:
+#Esc::
WinSet, Region,, A
return


or such..
_________________
Joyce Jamce
Back to top
View user's profile Send private message
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Sun Sep 09, 2007 1:39 pm    Post subject: Reply with quote

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

Code:
#InstallMouseHook


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
View user's profile Send private message
Roland



Joined: 08 Jun 2006
Posts: 244

PostPosted: Sun Sep 09, 2007 1:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group