Abgerundetes Rechteck mit _WINAPI_RoundRect()

  • Hi,
    ich habe das Beispiel aus der Hilfe für _WINAPI_RoundRect() verwendet und es aufs nötigste gekürzt (möchte lediglich ein Rechteck mit runden Ecken und in Farbe), verstehe aber nicht wieso ich Zeile 15, 16 benötige, damit er das Rechteck anzeigt. Der Teil mit dem Merge Bitmap ebenfalls. Kann das jemand bitte mal umschreiben, dass ich nur das gerundete Rechteck habe und es dann dem Pic Control zuweisen kann?


    [autoit]

    #include <APIGdiConstants.au3>
    #include <FontConstants.au3>
    #include <StaticConstants.au3>
    #include <WinAPIGdi.au3>
    #include <WindowsConstants.au3>

    [/autoit][autoit][/autoit][autoit]

    ; Create GUI
    Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400)
    Local $idPic = GUICtrlCreatePic('', 0, 0, 60, 60)
    Local $hPic = GUICtrlGetHandle($idPic)

    [/autoit][autoit][/autoit][autoit]

    ; Create bitmap
    Local $hDev = _WinAPI_GetDC($hPic)
    Local $hDC = _WinAPI_CreateCompatibleDC($hDev)
    Local $hSource = _WinAPI_CreateCompatibleBitmapEx($hDev, 400, 400, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE)))
    Local $hSv = _WinAPI_SelectObject($hDC, $hSource)

    [/autoit][autoit][/autoit][autoit]

    ; Draw objects
    Local $hOldBrush = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_BRUSH))
    Local $hOldPen = _WinAPI_SelectObject($hDC, _WinAPI_GetStockObject($DC_PEN))
    _WinAPI_SetDCBrushColor($hDC, 0x990404)
    _WinAPI_SetDCPenColor($hDC, 0x990404)
    $tRECT = _WinAPI_CreateRect(0, 0, 140, 90)
    _WinAPI_OffsetRect($tRECT, 220, 279)
    _WinAPI_RoundRect($hDC, $tRECT, 20, 20)

    [/autoit][autoit][/autoit][autoit]

    ; Merge bitmap
    Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDev, 400, 400)
    $hBrush = _WinAPI_SelectObject($hDC, $hOldBrush)
    _WinAPI_DeleteObject($hBrush)
    Local $hPen = _WinAPI_SelectObject($hDC, $hOldPen)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_SelectObject($hDC, $hBitmap)
    _WinAPI_DrawBitmap($hDC, 0, 0, $hSource, $MERGECOPY)
    _WinAPI_ReleaseDC($hPic, $hDev)
    _WinAPI_SelectObject($hDC, $hSv)
    _WinAPI_DeleteObject($hSource)
    _WinAPI_DeleteDC($hDC)

    [/autoit][autoit][/autoit][autoit]

    ; Set bitmap to control
    _SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
    $hObj = _SendMessage($hPic, $STM_GETIMAGE)
    If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    GUISetState(@SW_SHOW)

    [/autoit][autoit][/autoit][autoit]

    Do
    Until GUIGetMsg() = -3

    [/autoit]
  • Probiere mal die GDI+ Variante:

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    Global Const $STM_SETIMAGE = 0x0172
    ; Create GUI
    Local $hForm = GUICreate('Test', 400, 400)
    Local $idPic = GUICtrlCreatePic('', 0, 0, 60, 60)
    Local $hPic = GUICtrlGetHandle($idPic)
    Local $hGDIBmp = _GDIPlus_CreateBitmapRoundCornerRect()
    _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp))
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3
    _WinAPI_DeleteObject($hGDIBmp)
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_CreateBitmapRoundCornerRect($iW = 60, $iH = 60, $iColorBg = 0xFFFFFFFF, $iColorBorder = 0xFF000000, $iRadius = 8, $bGDIBmp = 1)
    Local Const $iX = 0, $iY = 0, $iPenSize = 1
    Local Const $iWidth = $iW - $iPenSize, $iHeight = $iH - $iPenSize
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT)
    Local Const $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90)
    _GDIPlus_PathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)
    _GDIPlus_PathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)
    _GDIPlus_PathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)
    _GDIPlus_PathCloseFigure($hPath)

    [/autoit] [autoit][/autoit] [autoit]

    Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColorBg)
    _GDIPlus_GraphicsFillPath($hCtxt, $hPath, $hBrush)
    Local Const $hPen = _GDIPlus_PenCreate($iColorBorder, $iPenSize)
    _GDIPlus_GraphicsDrawPath($hCtxt, $hPath, $hPen)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_PathDispose($hPath)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hCtxt)
    If $bGDIBmp Then
    Local $hGDIBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hGDIBmp
    EndIf
    Return $hBitmap
    EndFunc

    [/autoit]


    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (25. Oktober 2014 um 00:22)

  • Die Variante ist nicht schlecht, vor allem weil man kein WM_PAINT registrieren muss, vielen Dank.

    Habe mich jetzt in eine weitere Variante verbissen, die ich unbedingt zum laufen bringen möchte, aber komme nicht weiter. Hier erstelle ich mit _WinAPI_CreateDIBSection() das bitmap handle. Jetzt muss nur noch irgendwas mit alpha channel gemacht werden, damit das bitmap transparent ist, aber ich verzweifel an der sache. Kannst du mal bitte drüber schauen, skript ist vom _WinAPI_CreateDIBSection() example aus der Hilfe.

    [autoit]

    #include <APIGdiConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WinAPIGdi.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>

    [/autoit][autoit][/autoit][autoit]

    ; Create 32 bits-per-pixel device-independent bitmap (DIB) that use a mask
    Local $tBIV5HDR = DllStructCreate($tagBITMAPV5HEADER)

    [/autoit][autoit][/autoit][autoit]

    DllStructSetData($tBIV5HDR, 'bV5Size', DllStructGetSize($tBIV5HDR))
    DllStructSetData($tBIV5HDR, 'bV5Width', 100)
    DllStructSetData($tBIV5HDR, 'bV5Height', 100)
    DllStructSetData($tBIV5HDR, 'bV5Planes', 1)
    DllStructSetData($tBIV5HDR, 'bV5BitCount', 32)
    DllStructSetData($tBIV5HDR, 'biCompression', $BI_BITFIELDS)
    DllStructSetData($tBIV5HDR, 'bV5SizeImage', 0)
    DllStructSetData($tBIV5HDR, 'bV5XPelsPerMeter', 0)
    DllStructSetData($tBIV5HDR, 'bV5YPelsPerMeter', 0)
    DllStructSetData($tBIV5HDR, 'bV5ClrUsed', 0)
    DllStructSetData($tBIV5HDR, 'bV5ClrImportant', 0)
    ;~ DllStructSetData($tBIV5HDR, 'bV5RedMask', 0x00FF0000)
    ;~ DllStructSetData($tBIV5HDR, 'bV5GreenMask', 0x0000FF00)
    ;~ DllStructSetData($tBIV5HDR, 'bV5BlueMask', 0x000000FF)
    DllStructSetData($tBIV5HDR, 'bV5AlphaMask', 0xFF000000)
    DllStructSetData($tBIV5HDR, 'bV5CSType', 0)
    DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 1)
    DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 2)
    DllStructSetData($tBIV5HDR, 'bV5Endpoints', 0, 3)
    DllStructSetData($tBIV5HDR, 'bV5GammaRed', 0)
    DllStructSetData($tBIV5HDR, 'bV5GammaGreen', 0)
    DllStructSetData($tBIV5HDR, 'bV5GammaBlue', 0)
    DllStructSetData($tBIV5HDR, 'bV5Intent', 0)
    DllStructSetData($tBIV5HDR, 'bV5ProfileData', 0)
    DllStructSetData($tBIV5HDR, 'bV5ProfileSize', 0)
    DllStructSetData($tBIV5HDR, 'bV5Reserved', 0)

    [/autoit][autoit][/autoit][autoit]

    ; Create GUI
    Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 256, 256)
    Local $idPic = GUICtrlCreatePic('', 0, 0, 80, 80)
    Local $hPic = GUICtrlGetHandle($idPic)

    [/autoit][autoit][/autoit][autoit]

    $g_hDC = _WinAPI_GetDC($hForm)
    $g_hDC_Backbuffer = _WinAPI_CreateCompatibleDC($g_hDC)

    [/autoit][autoit][/autoit][autoit]

    Local $pBits
    Local $hBitmap = _WinAPI_CreateDIBSection(0, $tBIV5HDR, $DIB_RGB_COLORS, $pBits)

    [/autoit][autoit][/autoit][autoit]

    ;~ ; Fill bitmap green with variable alpha channel
    Local $tBits = DllStructCreate('dword[65536]', $pBits)
    For $y = 0 To 99
    For $x = 1 To 100
    DllStructSetData($tBits, 1, BitOR(0xFF000000, BitShift($y, -32)), $x + (100 * $y))
    Next
    Next

    [/autoit][autoit][/autoit][autoit]

    Local $hSv = _WinAPI_SelectObject($g_hDC_Backbuffer, $hBitmap)

    [/autoit][autoit][/autoit][autoit]

    $hbrush = _WinAPI_CreateSolidBrush(0xF0CAA6)
    Local $test = _WinAPI_SelectObject($g_hDC_Backbuffer, $hbrush)
    $tRECT = _WinAPI_CreateRect(0, 0, 80, 80)
    _WinAPI_RoundRect($g_hDC_Backbuffer, $tRECT, 20, 20)

    [/autoit][autoit][/autoit][autoit]

    _WinAPI_DeleteObject($test)
    _WinAPI_ReleaseDC($hForm, $g_hDC)
    _WinAPI_DeleteDC($g_hDC_Backbuffer)

    [/autoit][autoit][/autoit][autoit]

    ; Set bitmap to control
    _SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
    Local $hObj = _SendMessage($hPic, $STM_GETIMAGE)
    If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    ; Set background color to green and show GUI
    ;~ GUISetBkColor(0x0000FF)
    GUISetState(@SW_SHOW)

    [/autoit][autoit][/autoit][autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit]
  • Dann probiere mal dies:

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_Version=b
    #include <APIGdiConstants.au3>
    #include <FontConstants.au3>
    #include <StaticConstants.au3>
    #include <WinAPIGdi.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ; Create GUI
    Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400)
    Local $idPic = GUICtrlCreatePic('', 0, 0, 60, 60)
    Local $hPic = GUICtrlGetHandle($idPic)

    [/autoit] [autoit][/autoit] [autoit]

    ; Create bitmap
    Local $hDC = _WinAPI_GetDC($hForm)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, 60, 60)
    $hBitmapDC = _WinAPI_CreateCompatibleDC($hDC)
    $hObjOld = _WinAPI_SelectObject($hBitmapDC, $hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    ; Draw objects
    _WinAPI_GetSysColor($COLOR_3DFACE)
    Local $hOldBrush = _WinAPI_SelectObject($hBitmapDC, _WinAPI_GetStockObject($DC_BRUSH))
    Local $hOldPen = _WinAPI_SelectObject($hBitmapDC, _WinAPI_GetStockObject($DC_PEN))

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetDCBrushColor($hBitmapDC, _WinAPI_GetSysColor($COLOR_3DFACE))
    _WinAPI_ExtFloodFill($hBitmapDC, 0, 0, 0, $FLOODFILLSURFACE)

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetDCBrushColor($hBitmapDC, 0x990404)
    _WinAPI_SetDCPenColor($hBitmapDC, 0x990404)
    $tRECT = _WinAPI_CreateRect(0, 0, 60, 60)
    _WinAPI_RoundRect($hBitmapDC, $tRECT, 20, 20)

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_BitBlt($hDC, 0, 0, 60, 60, $hBitmapDC, 0, 0, $SRCCOPY)

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SelectObject($hBitmapDC, $hObjOld)
    _WinAPI_ReleaseDC($hPic, $hDC)

    [/autoit] [autoit][/autoit] [autoit]

    ; Set bitmap to control
    _WinAPI_DeleteObject(_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap))

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3
    $hBrush = _WinAPI_SelectObject($hDC, $hOldBrush)
    _WinAPI_DeleteObject($hBrush)
    $hPen = _WinAPI_SelectObject($hDC, $hOldPen)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_DeleteDC($hBitmapDC)
    _WinAPI_DeleteObject($hBitmap)

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Danke für die Mühen UEZ!!, es macht was es soll, aber genau genommen ist es nicht transparent, du hast als Füllfarbe die GUI Farbe genommen. Ich habe immer noch nicht rausgefunden wie man Bitmaps transparent macht sofern das überhaupt möglich ist. Ich belasse es dabei und bedanke mich herzlich!