AutoHotkey Community

It is currently May 26th, 2012, 6:47 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: June 16th, 2009, 10:01 am 
Offline

Joined: June 16th, 2009, 4:44 am
Posts: 4
Screen ruler is a tool used to measure.The ahk script can be used to measure the distance between two points or more.
This script may be useful for web designers.

Code:
lx := A_ScreenWidth/2-75
Gui, +AlwaysOnTop +ToolWindow -caption
Gui +LastFound
WinSet, Transparent, 200
gui, font, s12 w600
Gui, Show,NoActivate W150 H50 X%lx% Y0 ,
color := 0x0000FF
width := 4
hdc_screen := DllCall( "GetDC", "uint", 0 )
hdc_buffer := DllCall( "CreateCompatibleDC", "uint", hdc_screen )
hdc_canvas := DllCall( "GetDC", "uint", 0)

return



f4:: ;按下此快捷键开始测量 ,start to measure width and height.
CoordMode, Mouse, Screen
MouseGetPos,,, win_id2, ctrl_id2
WinGetTitle, win_title, ahk_id %win_id2%
Loop
{
  Sleep,100
  KeyIsDown := GetKeyState("LButton")
  if (KeyIsDown = 1)
  {
    MouseGetPos, xpos, ypos
    px = %xpos%
    py = %ypos%
    Sleep,10
    Loop
    {
      Sleep,100
      KeyIsDown := GetKeyState("LButton")
      if (KeyIsDown = 1)
      {
      drawline(px, py, px1, py, color, width)
      drawline(px1, py, px1, py1, color, width)
      drawline(px, py1, px1, py1, color, width)
      drawline(px, py, px, py1, color, width)
      gui,2:destroy

        Exit
      }
      MouseGetPos, px1, py1
     Sleep,10
     MouseGetPos, px2, py2
      pw = % px1 - px
      ph = % py1 - py
      
     gui,2:color,00FF00
      Gui, 2:+LastFound
     WinSet, Transparent,150
     Gui, 2:-Caption
     Gui, 2:Show, x%px% y%py% h%ph% w%pw% 
     if px2!=%px1%
     {   
     Gui, Add, Text, x40 y10 r4 cMaroon,W:%pw% px`r`nH:%ph% px
    
     }
    }
  }
}
return

F2:: ;按下此快捷键清屏,重置测量值.reset width and height ,clear screen
   px=
   py=
   px1=
   py1=
   px2=
   py2=
   WinHide,%win_title%
   WinShow,%win_title%
   reload
return

drawLine(x0, y0, x1, y1, color_ini=0, width=1)
{
   global hdc_canvas, hdc_buffer
   
   color := color_ini
   erase := false
   if color_ini=ERASE
      erase := true
   
   dx := x1 - x0
   dy := y1 - y0
   stepx := 0
   stepy := 0
   if (dx < 0) {
      dx := -dx
      stepx := -1
   } else
      stepx := 1
   if (dy < 0) {
      dy := -dy
      stepy := -1
   } else
      stepy := 1
   
   Loop %width%
   {
      x := x0+A_Index-1
      y := y0
      if erase
         color := DllCall( "GetPixel", "uint", hdc_buffer, "int", x, "int", y )
      DllCall( "SetPixel", "uint", hdc_canvas, "int", x, "int", y, "uint", color )
   }
   if (dx > dy) {
      fraction := dy - (dx >> 1)
      Loop
      {
         if (x0 = x1)
            break
         if (fraction >= 0) {
            y0 += stepy
            fraction -= dx
         }
         x0 += stepx
         fraction += dy
         Loop %width%
         {
            x := x0+A_Index-1
            y := y0
            if erase
               color := DllCall( "GetPixel", "uint", hdc_buffer, "int", x, "int", y )
            DllCall( "SetPixel", "uint", hdc_canvas, "int", x, "int", y, "uint", color )
         }
      }
   } else {
      fraction = dx - (dy >> 1)
      Loop
      {
         if (y0 = y1)
            break
         if (fraction >= 0) {
            x0 += stepx
            fraction -= dy
         }
         y0 += stepy
         fraction += dx
         Loop %width%
         {
            x := x0+A_Index-1
            y := y0
            if erase
               color := DllCall( "GetPixel", "uint", hdc_buffer, "int", x, "int", y )
            DllCall( "SetPixel", "uint", hdc_canvas, "int", x, "int", y, "uint", color )
         }
      }
   }

}

Escape::
ExitApp


_________________
xueying608


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 16th, 2009, 10:14 pm 
Offline

Joined: March 27th, 2009, 10:48 pm
Posts: 71
No one use this, it screws up all the icons and makes them not show.
I had to restart my computer... :x


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2009, 5:08 am 
Offline

Joined: June 16th, 2009, 4:44 am
Posts: 4
BF2 Player wrote:
No one use this, it screws up all the icons and makes them not show.
I had to restart my computer... :x


i didn't understand.it works well in my computer. :?:
First,you shuould press F4, click anywhere and drag your mouse.Click again,a transparent green rectangle
will appear and the width and height of the rec will show in a window at the top of the screen.
Second,everytime you measure ,you should press F3 ,which will reset the values and clear the screen.

Your problem ,i realy do not understand. :?: :?:
Could you please tell me more?

It will like this
Image


Image

_________________
xueying608


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2009, 7:33 pm 
Offline

Joined: March 27th, 2009, 10:48 pm
Posts: 71
I beleive I pressed F2 before, then a whole bunch of ahk programs popped up.
Then after that it was like a canvas was over my desktop,
I couldn't do any iterations with my mouse and all my icons weren't being shown.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 7:24 am 
Offline

Joined: May 15th, 2007, 4:57 am
Posts: 33
Does not work on my computer, but I'm running Windows 7 so could just not be compatible.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 10th, 2009, 3:42 pm 
Offline

Joined: May 15th, 2007, 8:59 pm
Posts: 169
Ya I had some issues with this script as well. I got it to work but my icons did flicker some while using it.

It also left the area selection boarders on my background after closing the script. After closing the script a simple F5 to refresh the desktop removed the remnant lines afterward.

Using Win XP Sp3.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: fusion1920, infogulch, Ragnar, Retro Gamer and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group