Advertisement
Lorenzo501
Jun 20th, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;WinSetTransColor is better but here's some WinSetRegion test code:
  2.  
  3. #Requires AutoHotkey 2.0
  4. #SingleInstance Force
  5.  
  6. ; --- PART 1: Example Setup (You will replace this with your actual GUI/Window setup) ---
  7. ; Assume these are your main GUI's (the one that will get the hole) details
  8. ; These are the screen coordinates and dimensions you used to SHOW your main GUI.
  9. mainX := 100
  10. mainY := 100
  11. mainWidth := 600
  12. mainHeight := 400
  13.  
  14. mainGui := Gui("-Caption")
  15. mainGui.Title := "Main GUI (Always On Top)"
  16. mainGui.BackColor := "Gray" ; To clearly see the hole
  17. mainGui.Opt("+AlwaysOnTop") ; Make it always on top
  18. mainGui.AddButton("x220 y350 w300", "Refresh e-mails")
  19. mainGui.Show("x" mainX " y" mainY " w" mainWidth " h" mainHeight)
  20.  
  21. ; Assume these are your child window's (the one being covered) details
  22. ; These are the screen coordinates and dimensions of the window that will define the hole.
  23. childX := 450
  24. childY := 400
  25. childWidth := 300
  26. childHeight := 150
  27.  
  28. childGui := Gui("-Caption")
  29. childGui.Title := "Child Window (Visible Through Hole)"
  30. childGui.BackColor := "Navy"
  31. childGui.Add("Text", "cWhite", "I am the child window!")
  32. childGui.Show("x" childX " y" childY " w" childWidth " h" childHeight)
  33.  
  34. ; Give windows a moment to appear
  35. Sleep 100
  36.  
  37. ; --- PART 2: Core Logic to Create the Hole in mainGui ---
  38.  
  39. ; IMPORTANT: Get the *current actual screen position* of the main GUI.
  40. ; This is important in case it was moved after being shown.
  41. WinGetPos(&CurrentMainScreenX, &CurrentMainScreenY, &CurrentMainWidth, &CurrentMainHeight, "ahk_id " mainGui.Hwnd)
  42.  
  43.  
  44. ; 1. Calculate the hole's coordinates *relative to the main GUI's top-left corner (0,0)*
  45. ; The WinSetRegion command expects relative coordinates for both the outer and inner polygons.
  46. HoleLeftRelative := childX - CurrentMainScreenX
  47. HoleTopRelative := childY - CurrentMainScreenY
  48. HoleRightRelative := HoleLeftRelative + childWidth
  49. HoleBottomRelative := HoleTopRelative + childHeight
  50.  
  51. ; 2. Construct the outer polygon string (representing the entire main GUI)
  52. ; Coordinates are 0-0 up to its current actual width and height.
  53. OuterPolygonString := "0-0 " CurrentMainWidth "-0 " CurrentMainWidth "-" CurrentMainHeight " 0-" CurrentMainHeight " 0-0"
  54.  
  55. ; 3. Construct the inner polygon string (representing the hole)
  56. InnerPolygonString := ""
  57. InnerPolygonString .= HoleLeftRelative "-" HoleTopRelative " "
  58. InnerPolygonString .= HoleRightRelative "-" HoleTopRelative " "
  59. InnerPolygonString .= HoleRightRelative "-" HoleBottomRelative " "
  60. InnerPolygonString .= HoleLeftRelative "-" HoleBottomRelative " "
  61. InnerPolygonString .= HoleLeftRelative "-" HoleTopRelative ; Close the polygon
  62.  
  63. ; 4. Combine the outer and inner polygons into the final region string
  64. RegionStringForWinSetRegion := OuterPolygonString "   " InnerPolygonString
  65.  
  66. ; 5. Apply the region to your main GUI
  67. WinSetRegion(RegionStringForWinSetRegion, "ahk_id " mainGui.Hwnd)
  68.  
  69. ; --- PART 3: Event Handlers (for clean exit) ---
  70. mainGui_OnClose() {
  71.     ExitApp
  72. }
  73.  
  74. childGui_OnClose() {
  75.     ExitApp
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement