 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
n00ge
Joined: 28 Sep 2007 Posts: 26
|
Posted: Wed Nov 21, 2007 3:05 pm Post subject: Looking for a script similar to Firefox' addon MeasureIt |
|
|
Does anybody know of a script (or even another app if this isn't possible w/ AHK) that functions like the MeasureIt add-on for Firefox? For anybody who doesn't know, it's a tool to draw a rectangle anywhere on a page and get the dimensions from the selection. It would be nice to use that anywhere on my desktop.
MeasureIt link:
http://www.kevinfreitas.net/extensions/measureit/ |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Nov 21, 2007 3:17 pm Post subject: |
|
|
| You can create a window, a tooltip will work,set its transparency, get the mouse coordinates and resize this window while you move the mouse. |
|
| Back to top |
|
 |
n00ge
Joined: 28 Sep 2007 Posts: 26
|
Posted: Wed Nov 21, 2007 3:19 pm Post subject: |
|
|
| Alright, thanks... Any direction to point me in on some functions to use? |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Nov 21, 2007 3:24 pm Post subject: |
|
|
tooltip
winset
mousegetpos
and some math |
|
| Back to top |
|
 |
n00ge
Joined: 28 Sep 2007 Posts: 26
|
Posted: Wed Nov 21, 2007 3:31 pm Post subject: |
|
|
| I'll look into it, thanks. If I get something useful, I'll be sure to post. |
|
| Back to top |
|
 |
n00ge
Joined: 28 Sep 2007 Posts: 26
|
Posted: Wed Nov 21, 2007 7:17 pm Post subject: |
|
|
I've done a bit of searching, but am not finding a way to create a window. Any help please?
Edit: I'm looking into GUI right now. It looks like that might be it. I know having a window w/out any controls wouldn't be very useful in many cases and that's probably why there aren't any examples, but is it possible to create a sized GUI w/out any controls or a titlebar? |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Nov 21, 2007 9:06 pm Post subject: |
|
|
There is no need for Gui windows, try a tooltip or progress window (progress might be better).
The commands sequence should be something like this:
coordmode, mouse,screen
mousegetpos
progress
winset, trans ;optional
loop
mousegetpos
...some math to calculate width,hiegth,position
winmove
...some condition to break the loop(getkeystate is ok)
end the loop
progress,off |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Wed Nov 21, 2007 9:53 pm Post subject: |
|
|
Someone can play with this.
| Code: | Gui, 1:+Lastfound +Resize +ToolWindow -Caption +Border
hGui := WinExist()
WinSet, TransColor, Yellow
Gui, 1:Color, Yellow
Gui, 2:+Owner1
Gui, 2:+ToolWindow
Gui, 2:Show, h0 w150, Size
Gui, 1:Show, h200 w300, Ruler
OnMessage(0x46, "WM_WINDOWPOSCHANGING")
Return
Esc::
2GuiClose:
ExitApp
GuiSize:
Ruler(hGui)
Gui, 2:Show,,W-%A_GuiWidth% px H-%A_GuiHeight% px
Return
WM_WINDOWPOSCHANGING(wParam, lParam)
{
if (A_Gui = 1) && !(NumGet(lParam+24) & 0x2) ; SWP_NOMOVE=0x2
{
; Since WM_WINDOWPOSCHANGING happens *before* the window moves,
; we must get the new position from the WINDOWPOS pointed to by lParam.
x := NumGet(lParam+8,0,"int") + NumGet(lParam+16) ; x + Width
y := NumGet(lParam+12,0,"int") ;+ NumGet(lParam+20) ; y + height
; Move - but don't activate - Gui 2.
Gui, 2:Show, X%x% Y%y% NA
}
if (A_Gui = 2) && !(NumGet(lParam+24) & 0x2) ; SWP_NOMOVE=0x2
{
Gui, 1:+LastFound
WinGetPos, , , W, H
; Since WM_WINDOWPOSCHANGING happens *before* the window moves,
; we must get the new position from the WINDOWPOS pointed to by lParam.
x := NumGet(lParam+8,0,"int") - W ; + NumGet(lParam+16) ; x + Width
y := NumGet(lParam+12,0,"int") ;+ NumGet(lParam+20) ; y + height
; Move - but don't activate - Gui 2.
Gui, 1:Show, X%x% Y%y% NA
}
}
Ruler(hGui) {
WinGetPos, , , @OutWidth, @OutHeight, ahk_id %hGui%
;Get the device context (DC) of the User GUI
hDc := API_GetDC(hGui)
;Create a DC in memory
; Create a pen to draw with
hPen := DllCall("CreatePen", "UInt", 0, "UInt", 1, "UInt", 0)
DllCall("SelectObject", "UInt", hDC, "UInt", hPen)
$NumPix = 5
$TickLen = 2
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
$NumPix = 10
$TickLen = 4
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
$NumPix = 50
$TickLen = 6
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
$NumPix = 100
$TickLen = 8
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
DllCall("ReleaseDC", "UInt", 0, "UInt", hDc) ; Clean-up.
DllCall("DeleteObject", "UInt", hPen)
}
API_GetDC( hwnd ){
return DllCall("GetDC", "uint", hwnd)
}
API_CreateCompatibleDC(hDC){
return DllCall("CreateCompatibleDC", "uint", hDC)
}
API_CreateCompatibleBitmap(hDC, hWidth, hHeight){
return DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hDC, "int", hWidth, "int", hHeight )
}
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Thu Nov 22, 2007 1:32 am Post subject: |
|
|
A slightly better version
| Code: | Gui, 1:+Lastfound +Resize +ToolWindow -Caption +Border
hGui := WinExist()
WinSet, Trans, 100
Gui, 1:Color, Aqua
Gui, 2:+Owner1
Gui, 2:+ToolWindow
x2 := A_ScreenWidth / 2 + 154
y2 := A_ScreenHeight / 2 - 104
Gui, 2:Show, x%x2% y%y2% h0 w150, Size
Gui, 1:Show, h200 w300, Ruler
OnMessage(0x46, "WM_WINDOWPOSCHANGING")
Return
Esc::
2GuiClose:
ExitApp
GuiSize:
Ruler(hGui)
Gui, 2:Show,,W-%A_GuiWidth% px H-%A_GuiHeight% px
Return
WM_WINDOWPOSCHANGING(wParam, lParam)
{
Static DockPos, Count
If !Count {
DockPos := "R"
Count++
}
if (A_Gui = 1) && !(NumGet(lParam+24) & 0x2) ; SWP_NOMOVE=0x2
{
Gui, 2:+LastFound
WinGetPos, , , 2W, 2H
; Since WM_WINDOWPOSCHANGING happens *before* the window moves,
; we must get the new position from the WINDOWPOS pointed to by lParam.
w1 := NumGet(lParam+16)
x1 := NumGet(lParam+8,0,"int")
y1 := NumGet(lParam+12,0,"int")
h1 := NumGet(lParam+20)
x := x1 + w1, y := y1 , DockPos := "R"
If (x1 + w1 + 2w > A_ScreenWidth)
x := x1 - 2w, DockPos := "L"
If (x < 0)
x := x1, y := y1 - 2h , DockPos := "T"
If (y < 0)
y := y1 + h1, DockPos := "B"
; Move - but don't activate - Gui 2.
Gui, 2:Show, X%x% Y%y% NA
}
if (A_Gui = 2) && !(NumGet(lParam+24) & 0x2) ; SWP_NOMOVE=0x2
{
Gui, 1:+LastFound
WinGetPos, , , W1, H1
; Since WM_WINDOWPOSCHANGING happens *before* the window moves,
; we must get the new position from the WINDOWPOS pointed to by lParam.
x2 := NumGet(lParam+8,0,"int")
w2 := NumGet(lParam+16) ; x + Width
y2 := NumGet(lParam+12,0,"int") ;+
h2 := NumGet(lParam+20) ; y + height
If (DockPos = "R")
x := x2 - w1, y := y2
Else If (DockPos = "T")
x := x2, y := y2 + h2
Else If (DockPos = "B")
x := x2, y := y2 - h1
Else If (DockPos = "L")
x := x2 + w2, y := y2
; Move - but don't activate - Gui 2.
Gui, 1:Show, X%x% Y%y% NA
}
}
Ruler(hGui) {
WinGetPos, , , @OutWidth, @OutHeight, ahk_id %hGui%
;Get the device context (DC) of the User GUI
hDc := API_GetDC(hGui)
;Create a DC in memory
; Create a pen to draw with
hPen := DllCall("CreatePen", "UInt", 0, "UInt", 1, "UInt", 0)
DllCall("SelectObject", "UInt", hDC, "UInt", hPen)
$NumPix = 5
$TickLen = 2
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
$NumPix = 10
$TickLen = 4
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
$NumPix = 50
$TickLen = 6
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
$NumPix = 100
$TickLen = 8
Line_x = 0
Line_y = 0
Loop, % @OutWidth / $NumPix ;vertical
{
; increase the x position by the Grid size
Line_x += $NumPix
; Set the begining of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "Uint", Line_x, "Uint", 0, "Uint", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", Line_x, "UInt", $TickLen)
}
Loop,% @OutHeight / $NumPix ;horizontal
{
; increase the y position by the Grid size
Line_y += $NumPix
; Set the beginning of the line
DllCall("gdi32.dll\MoveToEx", "UInt", hDc, "UInt",0, "UInt", Line_y, "UInt", 0 )
; Set the end of the line
DllCall("gdi32.dll\LineTo", "UInt", hDc, "UInt", $TickLen, "UInt", Line_y)
}
DllCall("ReleaseDC", "UInt", 0, "UInt", hDc) ; Clean-up.
DllCall("DeleteObject", "UInt", hPen)
}
API_GetDC( hwnd ){
return DllCall("GetDC", "uint", hwnd)
}
API_CreateCompatibleDC(hDC){
return DllCall("CreateCompatibleDC", "uint", hDC)
}
API_CreateCompatibleBitmap(hDC, hWidth, hHeight){
return DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hDC, "int", hWidth, "int", hHeight )
}
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Nov 22, 2007 8:08 am Post subject: |
|
|
I am thinking in a much simpler script
| Code: |
#LButton::
CoordMode, Mouse, Screen
MouseGetPos, original_X , original_Y
Progress, B c0 x%original_X% y%original_Y% w1 h1 cwBlue ctWhite fs8 zh0 zy1, , , Show Rectangle
WinSet, Trans, 100, Show Rectangle
Loop
{
If !GetKeyState("LButton", "P")
Break
MouseGetPos, current_X , current_Y
WinMove, Show Rectangle, , % newX := current_X > original_X ? original_X : current_X, % newY := current_Y > original_Y ? original_Y : current_Y, % newW := current_X > original_X ? current_X - original_X : original_X - current_X, % newH := current_Y > original_Y ? current_Y - original_Y : original_Y - current_Y
Progress, , %newW%x%newH%
}
;Sleep, 2000 ;necessary??
Progress, off
Return |
|
|
| Back to top |
|
 |
Guest
|
Posted: Thu Nov 22, 2007 8:11 am Post subject: |
|
|
| This one also moves the window to the left and up. |
|
| 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
|