Jump to content

Rounded Coner Rectangle in gdiPlus


Recommended Posts

Hi there

how do I create a rounded corner rect in GDIPlus ?

thanks in advance

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Hi there

how do I create a rounded corner rect in GDIPlus ?

thanks in advance

Using gdi32.dll:

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
   Dim $pos, $ret, $ret2
   $pos = WinGetPos($h_win)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long",  $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3,  "long", $i_y3)
   If $ret[0] Then
      $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
      If $ret2[0] Then
         Return 1
      Else
         Return 0
      EndIf
   Else
      Return 0
   EndIf
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

I need it as an image and not as a gui...

thanks anyway muttley

any other suggestions ?

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Hi there

how do I create a rounded corner rect in GDIPlus ?

thanks in advance

Adding to/expanding Andreik example, we have :-

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <misc.au3>
#include <GuiMenu.au3>

Global $iPath = "C:\Documents and Settings\My Documents\My Pictures\autoit9_wall_blue_800x600.jpg" 

Global $GuiSizeX = 400, $GuiSizeY = 400
Global $PicturePoints[4][2] = [[3,0],[0,0],[$GuiSizeX,0],[0,$GuiSizeY]]

$hGui = GUICreate("MyGUI", $GuiSizeX, $GuiSizeX, -1, -1, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
_GuiRoundCorners($hGui, 0, 0,$GuiSizeX, $GuiSizeX, 80, 80) 

GUISetState()

_GDIPlus_Startup ()
$hWnd = _WinAPI_GetDC ($hGui)
$hDC = _WinAPI_CreateCompatibleDC ($hWnd)
$hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $GuiSizeX, $GuiSizeY)
_WinAPI_SelectObject ($hDC, $hBitmap)
$hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)
$hImage = _GDIPlus_ImageLoadFromFile ($iPath) 

_GDIPlus_DrawImagePoints($hGraphic, $hImage, $PicturePoints[1][0], $PicturePoints[1][1], _
 $PicturePoints[2][0], $PicturePoints[2][1], $PicturePoints[3][0], $PicturePoints[3][1])
    
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", $GuiSizeX)
DllStructSetData($tSize, "Y", $GuiSizeY)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 254)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow ($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)

_GDIPlus_GraphicsDispose ($hGraphic)
_WinAPI_ReleaseDC ($hGui, $hWnd)
_WinAPI_DeleteObject ($hBitmap)
_WinAPI_DeleteDC ($hDC)
_GDIPlus_ShutDown ()

While 1
     $msg = GUIGetMsg()
     Select
          Case $msg = $GUI_EVENT_CLOSE
               ExitLoop
          Case Else
               ;;;
     EndSelect
WEnd
Exit

;Ref http://www.autoitscript.com/forum/index.php?s=&showtopic=27269&view=findpost&p=542801
;From  CreateRoundRectRgn()    Author(s):  Larry
; Parameter(s): handle of GUI, left,   top,   width,   height, horizontal rounding, vertical rounding
Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $iWidth, $iHeight, $i_x3, $i_y3)
     Dim  $ret, $ret2
     $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $iWidth, _
                                                               "long", $iHeight, "long", $i_x3, "long", $i_y3)
     If $ret[0]Then
          $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
          If $ret2[0]Then
               Return 1
          Else
               Return 0
          EndIf
     Else
          Return 0
     EndIf
EndFunc   ;==>_GuiRoundCorners

Note: Add your own Image file path and name @ Global $iPath = " " in script.

Link to comment
Share on other sites

Adding to/expanding Andreik example, we have :-

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <misc.au3>
#include <GuiMenu.au3>

Global $iPath = "C:\Documents and Settings\My Documents\My Pictures\autoit9_wall_blue_800x600.jpg" 

Global $GuiSizeX = 400, $GuiSizeY = 400
Global $PicturePoints[4][2] = [[3,0],[0,0],[$GuiSizeX,0],[0,$GuiSizeY]]

$hGui = GUICreate("MyGUI", $GuiSizeX, $GuiSizeX, -1, -1, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
_GuiRoundCorners($hGui, 0, 0,$GuiSizeX, $GuiSizeX, 80, 80) 

GUISetState()

_GDIPlus_Startup ()
$hWnd = _WinAPI_GetDC ($hGui)
$hDC = _WinAPI_CreateCompatibleDC ($hWnd)
$hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $GuiSizeX, $GuiSizeY)
_WinAPI_SelectObject ($hDC, $hBitmap)
$hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)
$hImage = _GDIPlus_ImageLoadFromFile ($iPath) 

_GDIPlus_DrawImagePoints($hGraphic, $hImage, $PicturePoints[1][0], $PicturePoints[1][1], _
 $PicturePoints[2][0], $PicturePoints[2][1], $PicturePoints[3][0], $PicturePoints[3][1])
    
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", $GuiSizeX)
DllStructSetData($tSize, "Y", $GuiSizeY)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", 254)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow ($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)

_GDIPlus_GraphicsDispose ($hGraphic)
_WinAPI_ReleaseDC ($hGui, $hWnd)
_WinAPI_DeleteObject ($hBitmap)
_WinAPI_DeleteDC ($hDC)
_GDIPlus_ShutDown ()

While 1
     $msg = GUIGetMsg()
     Select
          Case $msg = $GUI_EVENT_CLOSE
               ExitLoop
          Case Else
               ;;;
     EndSelect
WEnd
Exit

;Ref http://www.autoitscript.com/forum/index.php?s=&showtopic=27269&view=findpost&p=542801
;From  CreateRoundRectRgn()    Author(s):  Larry
; Parameter(s): handle of GUI, left,   top,   width,   height, horizontal rounding, vertical rounding
Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $iWidth, $iHeight, $i_x3, $i_y3)
     Dim  $ret, $ret2
     $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $iWidth, _
                                                               "long", $iHeight, "long", $i_x3, "long", $i_y3)
     If $ret[0]Then
          $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
          If $ret2[0]Then
               Return 1
          Else
               Return 0
          EndIf
     Else
          Return 0
     EndIf
EndFunc   ;==>_GuiRoundCorners

Note: Add your own Image file path and name @ Global $iPath = " " in script.

http://www.autoitscript.com/forum/index.ph...GuiRoundCorners

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...