Jump to content
Sign in to follow this  
ahmet

Setting window region

Recommended Posts

ahmet

I tried to set a window's region using GdipCreateRegionPath, but it isn't working. Is it impossibble to set window's region returned from that function? I have used by Authenticity.

Here is what I have tried:

#include <GDIP.au3>
#Include <WinAPI.au3>
;~ #include<Array.au3>

Global $width[3]=[800,600,200], $height[3]=[400,400,200], $radius=20
Global $num_of_rgns=7, $rgns[$num_of_rgns+1]

_GDIPlus_Startup()


$main=GUICreate("Test",800,400)
#region CreatePath
$hPath=_GDIPlus_PathCreate()
_GDIPlus_PathAddArc($hPath,$radius,$radius,2*$radius,2*$radius,180,90)
_GDIPlus_PathAddArc($hPath,$width[1]-3*$radius,$radius,2*$radius,2*$radius,270,90)
_GDIPlus_PathAddArc($hPath,$width[1]-$radius,4*$radius,2*$radius,2*$radius,-180,-90)
_GDIPlus_PathAddArc($hPath,$width[0]-3*$radius,($height[0]-$height[2])/2+$radius,2*$radius,2*$radius,-90,90)
_GDIPlus_PathAddLine($hPath,$width[0]-$radius,($height[0]-$height[2])/2+2*$radius,$width[0]-$radius,$height[0]/2)
;mirror path
$hClone=_PathMirrorX($hPath,$height[0]/2)
_GDIPlus_PathReverse($hPath)
_GDIPlus_PathAddPath($hPath,$hClone);,False)
#endregion CreatePath
$hGraphic=_GDIPlus_GraphicsCreateFromHWND($main)

$r1=_GDIPlus_RegionCreateFromPath($hPath)
$bounds=_GDIPlus_RegionGetBounds($r1,$hGraphic)
$data=_GDIPlus_RegionGetDataSize($r1)
ConsoleWrite("$data=" & $data & @CRLF)
;~ _ArrayDisplay($bounds)
ConsoleWrite("Infinite " & _GDIPlus_RegionIsInfinite($r1,$hGraphic) & @CRLF)
;~ $r=_GDIPlus_RegionCreateFromHrgn($r1)
;~ ConsoleWrite("$r=" & $r & @CRLF)
_WinAPI_SetWindowRgn($main, $r1)
GUISetState()
While 1
;~  _GDIPlus_GraphicsFillRegion($hGraphic,$r1)
;~  _GDIPlus_GraphicsDrawPath($hGraphic,$hPath)
    Switch GUIGetMsg()
        Case -3
            ExitLoop
    EndSwitch
WEnd

_GDIPlus_RegionDispose($r1)
;~ _GDIPlus_RegionDispose($r)
_GDIPlus_PathDispose($hPath)
_GDIPlus_PathDispose($hClone)
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_Shutdown()

Func _PathMirrorX($hPath,$nOffset)
    $path_data=_GDIPlus_PathGetData($hPath)
    ConsoleWrite(UBound($path_data) & @CRLF)
    For $i=1 To UBound($path_data)-1
;~      ConsoleWrite("Old=" & $path_data[$i][1] & @CRLF)
        $path_data[$i][1]=2*$nOffset-$path_data[$i][1]
;~      ConsoleWrite("New=" & $path_data[$i][1] & @CRLF)
    Next
    $new_path=_GDIPlus_PathCreate2($path_data)
    Return $new_path
EndFunc

Share this post


Link to post
Share on other sites
taietel

I'm not very familiar with GDI+, but now the region is visible.You have to get the handle of that region (see the <<<<<<<<<<<<<<<< in the script)

#include <GDIP.au3>
#Include <WinAPI.au3>
;~ #include<Array.au3>

Global $width[3]=[800,600,200], $height[3]=[400,400,200], $radius=20
Global $num_of_rgns=7, $rgns[$num_of_rgns+1]

_GDIPlus_Startup()


$main=GUICreate("Test",800,400)
GUISetState()
#region CreatePath
$hPath=_GDIPlus_PathCreate()
_GDIPlus_PathAddArc($hPath,$radius,$radius,2*$radius,2*$radius,180,90)
_GDIPlus_PathAddArc($hPath,$width[1]-3*$radius,$radius,2*$radius,2*$radius,270,90)
_GDIPlus_PathAddArc($hPath,$width[1]-$radius,4*$radius,2*$radius,2*$radius,-180,-90)
_GDIPlus_PathAddArc($hPath,$width[0]-3*$radius,($height[0]-$height[2])/2+$radius,2*$radius,2*$radius,-90,90)
_GDIPlus_PathAddLine($hPath,$width[0]-$radius,($height[0]-$height[2])/2+2*$radius,$width[0]-$radius,$height[0]/2)
;mirror path
$hClone=_PathMirrorX($hPath,$height[0]/2)
_GDIPlus_PathReverse($hPath)
_GDIPlus_PathAddPath($hPath,$hClone);,False)
#endregion CreatePath
$hGraphic=_GDIPlus_GraphicsCreateFromHWND($main)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, $SmoothingModeAntiAlias)

$r1=_GDIPlus_RegionCreateFromPath($hPath)
$bounds=_GDIPlus_RegionGetBounds($r1,$hGraphic)
$data=_GDIPlus_RegionGetDataSize($r1)
ConsoleWrite("$data=" & $data & @CRLF)
;~ _ArrayDisplay($bounds)
ConsoleWrite("Infinite " & _GDIPlus_RegionIsInfinite($r1,$hGraphic) & @CRLF)
;~ $r=_GDIPlus_RegionCreateFromHrgn($r1)
;~ ConsoleWrite("$r=" & $r & @CRLF)

_GDIPlus_GraphicsDrawPath($hGraphic, $hPath)
_WinAPI_SetWindowRgn($main, $r1);<<<<<<<<<<<<<<<<<<<< this is not working because $r1 has to be the handle to that region

While 1
;~  _GDIPlus_GraphicsFillRegion($hGraphic,$r1)
;~  _GDIPlus_GraphicsDrawPath($hGraphic,$hPath)
    Switch GUIGetMsg()
        Case -3
            ExitLoop
    EndSwitch
WEnd

_GDIPlus_RegionDispose($r1)
;~ _GDIPlus_RegionDispose($r)
_GDIPlus_PathDispose($hPath)
_GDIPlus_PathDispose($hClone)
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_Shutdown()

Func _PathMirrorX($hPath,$nOffset)
    $path_data=_GDIPlus_PathGetData($hPath)
    ConsoleWrite(UBound($path_data) & @CRLF)
    For $i=1 To UBound($path_data)-1
;~      ConsoleWrite("Old=" & $path_data[$i][1] & @CRLF)
        $path_data[$i][1]=2*$nOffset-$path_data[$i][1]
;~      ConsoleWrite("New=" & $path_data[$i][1] & @CRLF)
    Next
    $new_path=_GDIPlus_PathCreate2($path_data)
    Return $new_path
EndFunc
Edited by taietel

Share this post


Link to post
Share on other sites
ahmet

In your example the rgion isn't visible, but the path is :) .

I just have searched and found _GDIPlus_RegionGetHRgn() that did the job. I haven't seen it a couple days ago.

Thanks for looking.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.