Bilder als Buttons bei GDI+ Hintergrund Bild + Hover

  • Hey,
    ich brauche Leider immer noch Hilfe an meinem Problem. Es ist mitlerweile fast 1 Monat her, dass ich an meinem Problem sitze und ich habe bis jetzt immer noch kein Weg gefunden :(
    Bitte hilft mir.
    mfg Freaky

  • Hi, also so geht's bei mir ...

    Spoiler anzeigen
    [autoit]


    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <Constants.au3>
    #include <StaticConstants.au3>
    #include <GDIPlus.au3>
    #include <IE.au3>

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

    Global $iImagePfad = @ScriptDir & "\Bilder\"

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

    ;~ Global Const $IMAGE_BITMAP = 0
    Global Const $SC_DRAGMOVE = 0xF012
    Global Const $STM_SETIMAGE = 0x0172
    ;~ Global Const $LWA_ALPHA = 0x00000002

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

    ; The script's entry point
    Exit (ScriptMain ( ))

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

    Func ScriptMain ( )

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

    Local $hWnd
    Local $oIE
    Local $iButton [3]
    Local $hBmp, $hImage, $hBrush
    Local $iWidth, $iHeight
    Local $hbrOld

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

    _GDIPlus_StartUp ( )

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

    $hImage = _GDIPlus_ImageLoadFromFile ($iImagePfad & "background.png")

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

    $iWidth = _GDIPlus_ImageGetWidth ($hImage)
    $iHeight = _GDIPlus_ImageGetHeight ($hImage)

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

    $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap ($hImage)

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

    ; Create the main window
    $hWnd = GUICreate ("Test", $iWidth, $iHeight, -1, -1, _
    BitOR ($WS_POPUP, $WS_CLIPCHILDREN), BitOR ($WS_EX_LAYERED, $WS_EX_TOPMOST))

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

    GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

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

    $bImage_Pic1 = _GDIPlus_ImageLoadFromFile($iImagePfad & "start_1.png")
    $bImage_Pic2 = _GDIPlus_ImageLoadFromFile($iImagePfad & "start_2.png")

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

    $hbmpButton1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bImage_Pic1)
    $hbmpButton2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bImage_Pic2)

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

    ; Create the button
    GUICreate ("", 118, 31, 100, 100, _
    BitOr($WS_POPUP, $WS_CHILD, $WS_VISIBLE, $WS_CLIPSIBLINGS), $WS_EX_MDICHILD, $hWnd)
    $iButton = GUICtrlCreatePic ("", 0, 0, 118, 31, BitOr($SS_NOTIFY, $WS_CLIPSIBLINGS, $GUI_SS_DEFAULT_PIC))
    GUICtrlSendMsg ($iButton, $STM_SETIMAGE, $IMAGE_BITMAP, $hbmpButton1)

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

    GUISetState (@SW_SHOW, $hWnd)

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

    SetTransparentBitmap($hWnd, $hImage)

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

    _WinAPI_DeleteObject ($hBmp)
    _GDIPlus_ImageDispose ($hImage)

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

    ; Create embedded "iexplore" object
    $oIE = _IECreateEmbedded ( )

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

    If ($oIE <> 0) Then

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

    _CreateIEObject($hWnd, $oIE, 200, 200, 200, 200)

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

    _IENavigate($oIE, 'http://google.de')
    Else
    MsgBox (BitOR ($MB_OK, $MB_ICONHAND), 0, "_IECreateEmbedded fehlgeschlagen!")
    EndIf

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

    Local $isHover = False
    Local $mem = True

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

    ; Message loop
    While (TRUE)

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

    Switch (GUIGetMsg ( ))
    Case $iButton
    ContinueCase
    Case $GUI_EVENT_CLOSE
    GUIDelete ($hWnd)
    ExitLoop
    EndSwitch

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

    Local $aCoord = GUIGetCursorInfo ($hWnd)

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

    If $aCoord[4] = $iButton Then
    If Not $isHover Then
    GUICtrlSendMsg ($iButton, $STM_SETIMAGE, $IMAGE_BITMAP, $hbmpButton1)
    $isHover = True
    $mem = True
    EndIf
    Else
    If $mem Then
    GUICtrlSendMsg ($iButton, $STM_SETIMAGE, $IMAGE_BITMAP, $hbmpButton2)
    $mem = False
    $isHover = False
    EndIf
    EndIf

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

    WEnd

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

    ;~ _IEQuit ($oIE)
    _GDIPlus_ImageDispose ($bImage_Pic1)
    _GDIPlus_ImageDispose ($bImage_Pic2)
    _WinAPI_DeleteObject ($hbmpButton1)
    _WinAPI_DeleteObject ($hbmpButton2)
    _WinAPI_DeleteObject ($hBrush)
    _GDIPlus_ShutDown ( )

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

    Return 0

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

    EndFunc

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

    Func _CreateIEObject ($iForm,$iVar,$iX,$iY,$iW,$iH)
    $iIEForm = GUICreate ("",$iX,$iY,$iW,$iH,BitOr($WS_POPUP, $WS_CHILD, $WS_VISIBLE, $WS_CLIPSIBLINGS), $WS_EX_MDICHILD, $iForm)
    GUICtrlCreateObj ($iVar,0,0,$iW,$iH)
    GUISetState (@SW_SHOW,$iIEForm)
    EndFunc

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

    Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndFunc ;==>_WM_LBUTTONDOWN

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

    Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    _WinAPI_ReleaseDC(0, $hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, 0, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
    EndFunc ;==>SetBitmap

    [/autoit]


    Gruß
    Greenhorn


  • Hey,
    vielen Dank, dass du dir die Zeit genommen hast um dir das anzugucken.
    Das Hintergrundbild wird nun so angezeigt, wie ich mir das gewünscht habe. Leider spinnt nun der Button.
    Wenn ich das Script starte, ist alles ok. Nach ca. 2 Sekunden, geht der Hover des Buttons and und bleibt auch an. Und $aCoord[4] zeigt mir dauerhaft 0 an, als ob es kein Object in der Form findet. Nicht einmal die IE Form.
    Leider kann ich mir auch nicht erklären, wieso $aCoord[4] nichts findet. Gibt es dafür eine simple Begründung oder ist da ein Fehler?
    mfg Freaky :)