' Deklarace Windows API pro pehrn zvuku, mus bt na zatku modulu!
#If VBA7 Then
    Declare PtrSafe Function sndPlaySoundA Lib "winmm.dll" _
        (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
#Else
    Declare Function sndPlaySoundA Lib "winmm.dll" _
        (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
#End If

Sub CreateMovingImage()
    Dim slide As slide
    Dim img As Shape
    
    ' Vybere se prvn snmek nebo se vytvo nov
    If ActivePresentation.Slides.Count = 0 Then
        Set slide = ActivePresentation.Slides.Add(1, ppLayoutBlank)
    Else
        Set slide = ActivePresentation.Slides(1)
    End If
    
    ' Pidn obrzku
    Set img = slide.Shapes.AddPicture("C:\Users\Uivatel\Documents\BakalarskaPraceCviceni\cviceni12\kitten.jpg", _
                                      msoFalse, msoCTrue, 200, 200, 100, 100)
    
    ' Nastaven makra pro udlost MouseOver
    img.ActionSettings(ppMouseOver).Action = ppActionRunMacro
    img.ActionSettings(ppMouseOver).Run = "MoveImageRandomly"
    
    MsgBox "Obrzek byl pidn! Najed' my a uvid, co se stane!", vbInformation
End Sub

Sub MoveImageRandomly()
    Dim slide As slide
    Dim img As Shape
    Dim newX As Single, newY As Single
    Dim maxX As Single, maxY As Single
    
    ' Vybere se prvn snmek a obrzek
    Set slide = ActivePresentation.Slides(1)
    Set img = slide.Shapes(ActivePresentation.Slides(1).Shapes.Count)
    
    ' Nastaven maximlnch souadnic pro nhodn umstn
    maxX = ActivePresentation.PageSetup.SlideWidth - img.Width
    maxY = ActivePresentation.PageSetup.SlideHeight - img.Height
    
    ' Generovn novch souadnic
    Randomize
    newX = Rnd * maxX
    newY = Rnd * maxY
    
    ' Pesun obrzku
    img.Left = newX
    img.Top = newY

    ' Pehraje zvuk
    PlayMeowSound "C:\Users\Uivatel\Documents\BakalarskaPraceCviceni\cviceni12\meow.wav"
End Sub

Sub PlayMeowSound(soundPath As String)
    ' Pehraje zvukov soubor
    sndPlaySoundA soundPath, 1
End Sub


