Advertisement
Guest User

Untitled

a guest
Apr 6th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. OnMessage(0x14, "WM_ERASEBKGND")
  2. Gui, -Caption +ToolWindow
  3. Gui, +LastFound
  4. WinSet, TransColor, Black
  5. ; Create the pen here so we don't need to create/delete it every time.
  6. RedPen := DllCall("CreatePen", "int", PS_SOLID:=0, "int", 5, "uint", 0xff)
  7. return
  8.  
  9. WM_ERASEBKGND(wParam, lParam)
  10. {
  11.     global x1, y1, x2, y2, RedPen
  12.     Critical 50
  13.     if A_Gui = 1
  14.     {
  15.         ; Retrieve stock brush.
  16.         blackBrush := DllCall("GetStockObject", "int", BLACK_BRUSH:=0x4)
  17.         ; Select pen and brush.
  18.         oldPen := DllCall("SelectObject", "uint", wParam, "uint", RedPen)
  19.         oldBrush := DllCall("SelectObject", "uint", wParam, "uint", blackBrush)
  20.         ; Draw rectangle.
  21.         DllCall("Rectangle", "uint", wParam, "int", 0, "int", 0, "int", x2-x1, "int", y2-y1)
  22.         ; Reselect original pen and brush (recommended by MS).
  23.         DllCall("SelectObject", "uint", wParam, "uint", oldPen)
  24.         DllCall("SelectObject", "uint", wParam, "uint", oldBrush)
  25.         return 1
  26.     }
  27. }
  28.  
  29. +LButton::
  30.    coordmode, mouse, screen
  31.     MouseGetPos, xorigin, yorigin
  32. ;   msgbox, %xorigin%, %yorigin%
  33.     SetTimer, rectangle, 10
  34. return
  35.  
  36. rectangle:
  37.   coordmode, mouse, screen
  38.     MouseGetPos, x2, y2
  39. ;   msgbox, %xorigin%, %yorigin%
  40.     ; Has the mouse moved?
  41.     if (x1 y1) = (x2 y2)
  42.         return
  43.    
  44.     ; Allow dragging to the left of the click point.
  45.     if (x2 < xorigin) {
  46.         x1 := x2
  47.         x2 := xorigin
  48.     } else
  49.         x1 := xorigin
  50.    
  51.     ; Allow dragging above the click point.
  52.     if (y2 < yorigin) {
  53.         y1 := y2
  54.         y2 := yorigin
  55. } else
  56.     y1 := yorigin
  57.  
  58. Gui, Show, % "NA X" x1 " Y" y1 " W" x2-x1 " H" y2-y1
  59. Gui, +LastFound +AlwaysOnTop
  60. WinGetPos, X, Y, W, H
  61. Tooltip % "X: " X ", Y: " Y "`nWidth: " W ", Height: " H
  62. DllCall("RedrawWindow", "uint", WinExist(), "uint", 0, "uint", 0, "uint", 5)
  63. return
  64.  
  65. +LButton Up::
  66. SetTimer, rectangle, Off
  67. Gui, Cancel
  68. coordmode, mouse, window
  69. tooltip
  70. msgbox % "X: " X ", Y: " Y "`nWidth: " W ", Height: " H
  71.  
  72.  
  73.  
  74.  
  75. X2 := % W+X
  76. Y2 := % H+Y
  77. MsgBox % "x2=" X2 "y2=" Y2
  78.  
  79. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement