Page 1 of 1

Mask a window with regions

Posted: Sun Oct 06, 2002 4:57 pm
by BackupUser
Restored from previous forum. Originally posted by altesocke.

Code updated for 5.20+

hi forum

below you see a little example, how to mask a window with regions.
for more information about using regions see the MSDN online: http://msdn.microsoft.com/library/en-us ... s_7ab7.asp

cu socke

Code: Select all

#Window1 = 1
#W1Btn1 = 1
#W1Btn2 = 2

WinW=500 : WinH=410
hwnd = OpenWindow( #Window1, (GetSystemMetrics_(#SM_CXSCREEN)-WinW)/2, (GetSystemMetrics_(#SM_CYSCREEN)-WinH)/2, WinW, WinH,"Region Mask", 0)   ; centred window
If hwnd > 0
  
  ButtonGadget(#W1Btn1,103,330 ,89,25,"Mask Window")
  ButtonGadget(#W1Btn2,264,330 ,89,25,"Close")
  
  RectRgn = CreateRoundRectRgn_(0, 0, WinW, WinH, 50, 50)  ; rectangle region to give the window rounded edges
  EllipRgn = CreateEllipticRgn_(50, 50, 250, 250) ; elliptic region
  CombinedRgn = RectRgn ; to combine regions, the target region must exist before calling CombineRgn
  CombineRgn_(CombinedRgn, CombinedRgn, EllipRgn, #RGN_XOR) ;the parameter #RGN_XOR creates the union of two combined regions except for any overlapping areas.
  
  Repeat
    Delay(1)
    EventID.l = WaitWindowEvent()
    
    Select EventID
        
      Case #PB_Event_Gadget
        
        Select EventGadget()
          Case #W1Btn1 ;----------Code
            SetWindowRgn_(hwnd, RectRgn, #True) ;sets the window region of a window, #TRUE repaints the window
            
          Case #W1Btn2 ;----------Code
            EventID = #PB_Event_CloseWindow
            
        EndSelect
        
    EndSelect
    
  Until EventID = #PB_Event_CloseWindow
  
EndIf
End


Posted: Wed May 05, 2004 8:09 pm
by Aeroschmelz
Is there a possibility to make the window transparent, but keep the gadgets on it visible ?

Posted: Thu May 06, 2004 9:21 am
by LarsG
I believe this was asked by another guy just recently.. try searching the forums for some code..

Posted: Thu May 06, 2004 7:34 pm
by Aeroschmelz
Didnt find any ! Sorry, only transparent windows, but not with the gadgets visible...

Posted: Thu May 06, 2004 7:50 pm
by fweil
...,

Maybe if you start workking with that you could find a way to catch gadgets regions and then make only gadgets visible.

Code: Select all

Structure eyes
  x.l
  y.l
EndStructure

  WindowXSize.l = 480
  WindowYSize.l = 360
  Where_I_Look.POINT
  Quit.l = #FALSE
  OldWhere_I_Look_x.l
  OldWhere_I_Look_y.l
  
  GetCursorPos_(Start.POINT)
  hWnd = OpenWindow(0, Start\x - WindowXSize / 2, Start\y - WindowYSize / 2, WindowXSize, WindowYSize, #PB_Window_SystemMenu, "Eyes")
  If hWnd
      AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)
      EllipRgn1 = CreateEllipticRgn_(WindowXSize / 4, WindowYSize / 2, WindowXSize / 4 + 100, WindowYSize / 2 + 50) ; elliptic region
      EllipRgn2 = CreateEllipticRgn_(WindowXSize / 2, WindowYSize / 2, WindowXSize / 2 + 100, WindowYSize / 2 + 50) ; elliptic region
      CombinedRgn = EllipRgn1 ; to combine regions, the target region must exist before calling CombineRgn
      CombineRgn_(CombinedRgn, CombinedRgn, EllipRgn2, #RGN_XOR) ;the parameter #RGN_XOR creates the union of two combined regions except for any overlapping areas.
      SetWindowRgn_(hWnd, CombinedRgn, #TRUE) ;sets the window region of a window, #TRUE repaints the window
      Repeat
        GetCursorPos_(Where_I_Look)
        If Where_I_Look\x <> OldWhere_I_Look_y Or Where_I_Look\y <> Where_I_Look_y
            ImageID = CreateImage(0, WindowXSize, WindowYSize)
            StartDrawing(ImageOutput())
              Box(0, 0, WindowXSize, WindowYSize, 0)
              FrontColor(255, 255, 255)
              DrawingMode(1)
              Ellipse(WindowXSize / 4, WindowYSize / 2, 100, 50, $300000)
              Ellipse(WindowXSize / 2, WindowYSize / 2, 100, 50, $300000)
              Circle(WindowXSize / 2 + (Where_I_Look\x - WindowXSize / 2) / 5, WindowYSize / 2- (WindowYSize / 2- Where_I_Look\y) / 8, 25, $C0FFFF)
              Circle(WindowXSize / 4 + (Where_I_Look\x - WindowXSize / 2) / 5, WindowYSize / 2- (WindowYSize / 2- Where_I_Look\y) / 8, 25, $C0FFFF)
            StopDrawing()
            StartDrawing(WindowOutput())
              DrawImage(ImageID, 0, 0)
            StopDrawing()
            OldWhere_I_Look_x= Where_I_Look\x
            OldWhere_I_Look_y = Where_I_Look\y
        EndIf
        Delay(1)
      Until WindowEvent() = #PB_Event_CloseWindow Or EventMenuID() = 99
  EndIf
  TerminateProcess_(GetCurrentProcess_(), 0)
End
I just let you think ATM but I start a workaround now.

Rgrds

Posted: Thu May 13, 2004 11:40 am
by Aeroschmelz
Why will this one work:

RgnB = CreateRectRgn_(25,0, 970, 30)

and this won't

RgnB = CreateRectRgn_(25,0, WindowWidth.f, 30)

Posted: Thu May 13, 2004 12:19 pm
by dell_jockey
Perhaps, WindowsWidth should be an integer instead of a float?

Posted: Thu May 13, 2004 12:51 pm
by Aeroschmelz
Ok, it works now, does somebody now how can i reset the window to show fully up again. This command somehow:

DeleteObject_(GRgn.l)