Advertisement
Ridelith

ScreenDisplayOnGUI

May 8th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. ; initializing the script:
  2. #SingleInstance force
  3. #NoEnv
  4. #KeyHistory 0
  5. SetWorkingDir,
  6. #include Thumbnail.ahk
  7.  
  8. ;--- Script to monitior a window or section of a window (such as a progress bar, or video) in a resizable live preview window
  9.  
  10. ;--- This is an update (in terms of functionality) to the original livewindows ahk script by Holomind http://www.autohotkey.com/forum/topic11588.html
  11. ;--- which takes advantage of windows vista/7 Aeropeak. The script relies on Thumbnail.ahk, a great script by relmaul.esel, http://www.autohotkey.com/forum/topic70839.html
  12. ;--------------------------------------------------------------------------------------------
  13.  
  14. Hotkey, ^+LButton , start_defining_region
  15. Hotkey, #w, watchWindow
  16.  
  17.  
  18. msgbox, Press win+w to watch the entire active window `n`nOr hold down ctrl+shift and drag a box around the `narea you are interested in to watch a specific region
  19. return
  20.  
  21. ;--------------------------------------------------------------------------------------------
  22.  
  23. watchWindow:
  24.  
  25. WinGetClass, class, A ; get ahk_id of foreground window
  26. targetName = ahk_class %class% ; get target window id
  27. WinGetPos, , , Rwidth, Rheight, A
  28. start_x := 0
  29. start_y := 0
  30. sleep, 500
  31.  
  32. ThumbWidth := 400
  33. ThumbHeight := 400
  34. thumbID := mainCode(targetName,ThumbWidth,ThumbHeight,start_x,start_y,Rwidth,Rheight)
  35.  
  36. return
  37.  
  38. start_defining_region:
  39.  
  40.  
  41. Gui, Destroy
  42. Thumbnail_Destroy(thumbID)
  43.  
  44. CoordMode, Mouse, Relative ; relative to window not screen
  45. MouseGetPos, start_x, start_y ; start position of mouse
  46. SetTimer end_defining_region, 200 ; check every 50ms for mouseup
  47.  
  48.  
  49. Return
  50.  
  51. end_defining_region:
  52.  
  53. ; get the region dimensions
  54. MouseGetPos, current_x, current_y
  55.  
  56. Rheight := abs(current_y - start_y)
  57. Rwidth := abs(current_x - start_x)
  58.  
  59. WinGetPos, win_x, win_y, , , A
  60.  
  61. P_x := start_x + win_x
  62. P_y := start_y + win_y
  63.  
  64. if (current_x < start_x)
  65. P_x := current_x + win_x
  66.  
  67. if (current_y < start_y)
  68. P_y := current_y + win_y
  69.  
  70. ; draw a box to show what is being defined
  71. Progress, B1 CWffdddd CTff5555 ZH0 fs13 W%Rwidth% H%Rheight% x%P_x% y%P_y%, , ,getMyRegion
  72. WinSet, Transparent, 110, getMyRegion
  73.  
  74. ; if mouse not released then loop through above code...
  75. If GetKeyState("LButton", "P")
  76. Return
  77.  
  78. ;...otherwise, stop defining region, and start thumbnail ------------------------------->
  79. SetTimer end_defining_region, OFF
  80.  
  81. Progress, off
  82.  
  83. MouseGetPos, end_x, end_y
  84. if (end_x < start_x)
  85. start_x := end_x
  86.  
  87. if (end_y < start_y)
  88. start_y := end_y
  89.  
  90. WinGetClass, class, A ; get ahk_id of foreground window
  91.  
  92. targetName = ahk_class %class% ; get target window id
  93.  
  94.  
  95. sleep, 500
  96. ThumbWidth := Rwidth
  97. ThumbHeight := Rheight
  98. thumbID := mainCode(targetName,ThumbWidth,ThumbHeight,start_x,start_y,Rwidth,Rheight)
  99.  
  100. return
  101.  
  102.  
  103.  
  104. mainCode(targetName,windowWidth,windowHeight,RegionX,RegionY,RegionW,RegionH)
  105. {
  106. ; get the handles:
  107. Gui +LastFound
  108. hDestination := WinExist() ; ... to our GUI...
  109. hSource := WinExist(targetName) ;
  110.  
  111. ; creating the thumbnail:
  112. hThumb := Thumbnail_Create(hDestination, hSource) ; you must get the return value here!
  113.  
  114. ; getting the source window dimensions:
  115. Thumbnail_GetSourceSize(hThumb, width, height)
  116.  
  117. ;-- make sure ratio is correct
  118. CorrectRatio := RegionW / RegionH
  119. testWidth := windowHeight * CorrectRatio
  120. if (windowWidth < testWidth)
  121. {
  122. windowHeight := windowWidth / CorrectRatio
  123. }
  124. ; else
  125. ; {
  126. ; windowWidth := testWidth
  127. ; }
  128.  
  129.  
  130. ; then setting its region:
  131. Thumbnail_SetRegion(hThumb, 0, 0 , windowWidth, windowHeight, RegionX , RegionY ,RegionW, RegionH)
  132.  
  133.  
  134.  
  135. ; now some GUI stuff:
  136. Gui +E0x20 +AlwaysOnTop +Resize -SysMenu -Border -Caption
  137. Gui, Show, x650 y520
  138. ; Now we can show it:
  139. Thumbnail_Show(hThumb) ; but it is not visible now...
  140. Gui Show, w%windowWidth% h%windowHeight%, Live Thumbnail ; ... until we show the GUI
  141. OnMessage(0x201, "WM_LBUTTONDOWN")
  142.  
  143. return hThumb
  144. }
  145.  
  146.  
  147. GuiSize:
  148. ;if ErrorLevel = 1 ; The window has been minimized. No action needed.
  149. ; return
  150.  
  151. Thumbnail_Destroy(thumbID)
  152. ThumbWidth := A_GuiWidth
  153. ThumbHeight := A_GuiHeight
  154. thumbID := mainCode(targetName,ThumbWidth,ThumbHeight,start_x,start_y,Rwidth,Rheight)
  155. return
  156.  
  157. ;----------------------------------------------------------------------
  158.  
  159. GuiClose: ; in case the GUI is closed:
  160. Thumbnail_Destroy(thumbID) ; free the resources
  161. ExitApp
  162.  
  163.  
  164. WM_LBUTTONDOWN(wParam, lParam)
  165. {
  166. mX := lParam & 0xFFFF
  167. mY := lParam >> 16
  168. SendClickThrough(mX,mY)
  169. }
  170.  
  171. SendClickThrough(mX,mY)
  172. {
  173. global
  174.  
  175. convertedX := Round((mX / ThumbWidth)*Rwidth + start_x)
  176. convertedY := Round((mY / ThumbHeight)*Rheight + start_y)
  177. ;msgBox, x%convertedX% y%convertedY%, %targetName%
  178. ControlClick, x%convertedX% y%convertedY%, %targetName%,,,, NA
  179. ; sleep, 250
  180. ; ControlClick, x%convertedX% y%convertedY%, %targetName%,,,, NA u
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement