Jump to content

Valentines Day Surprise


NerdFencer
 Share

Recommended Posts

This is a program that I wrote to surprise my girlfriend Victoria on Valentines day.

Feel free to adapt it for your own significant other!

Suggestions welcome

http://autoclean.computersitter.com/Vday.zip

It comes with a pre-compiled executable and batch files to install, uninstall, and force execution (it wont do anything unless its valentines day). The batch files just execute the program with command line options.

The source is in the zip and below.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=VDay.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/SO
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.2.0
 Author:         Matthew McMullan

 Script Function:
    Valentines Day Script.

#ce ----------------------------------------------------------------------------

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

; ===============================================================================================================================
; Globals
; ===============================================================================================================================
Global Const $AC_SRC_ALPHA      = 1
Global $Himg[3]
Global $minihearts[2][10]
Global $ll, $lr

; ===============================================================================================================================
; Command Line Interpretation
; ===============================================================================================================================
If $CmdLine[0] = 0 Then
    If @MON=="02" And @MDAY="14" Or Not(@Compiled) Then
        Main()
    EndIf
ElseIf $CmdLine[1]=="/install" Then
    DirCreate(@ProgramFilesDir&"\Valentines Day\")
    FileCopy(@ScriptDir&"\valentine-heart-small.png",@ProgramFilesDir&"\Valentines Day\")
    FileCopy(@ScriptDir&"\valentine-heart-small-left.png",@ProgramFilesDir&"\Valentines Day\")
    FileCopy(@ScriptDir&"\valentine-heart-small-right.png",@ProgramFilesDir&"\Valentines Day\")
    FileCopy(@ScriptDir&"\VDgui.png",@ProgramFilesDir&"\Valentines Day\")
    FileCopy(@ScriptDir&"\Bryan Adams - When You Love Someone.mp3",@ProgramFilesDir&"\Valentines Day\")
    FileCopy(@ScriptFullPath,@ProgramFilesDir&"\Valentines Day\")
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run","Valentines Day","REG_SZ",@ProgramFilesDir&"\Valentines Day\"&@ScriptName)
ElseIf $CmdLine[1]=="/uninstall" Then
    RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run","Valentines Day")
    DirRemove(@ProgramFilesDir&"\Valentines Day\",1)
    DirRemove(@ProgramFilesDir&"\Valentines Day\",0)
ElseIf $CmdLine[1]=="/force" Then
    Main()
EndIf

; ===============================================================================================================================
; Here lies the romantic magic
; ===============================================================================================================================
Func main()
    Init()
    SoundSetWaveVolume(100)
    SoundPlay(@ScriptDir&"\Bryan Adams - When You Love Someone.mp3")
    Local $gui = GUICreate("Valentines Day",811,750,-1,-1,-1,BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST))
    Local $guiimg = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\VDgui.png")
    SetBitMap($gui, $guiimg, 255)
    PopulateMiniHearts($gui)
    GUISetState(@SW_SHOW,$gui)
    Local $msg
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case -3
                Exit
        EndSwitch
        Sleep(15)
        UpdateMiniHearts()
    WEnd
    Denit()
EndFunc

; ===============================================================================================================================
; Determines the placement for a heart
; ===============================================================================================================================
Func PlaceHeart(ByRef $last, $left, $right)
    Local $place = $last
    While $last-40<$place And $last+40>$place
        $place = Random($left,$right,1)
    WEnd
    $last = $place
    Return $place
EndFunc

; ===============================================================================================================================
; Initialize the screen full of romantic hearts
; ===============================================================================================================================
Func PopulateMiniHearts($gui)
    $ll = -300
    $lr = -300
    Local $left = (@DesktopWidth-811)/2
    Local $right = (@DesktopWidth+811)/2-49
    For $i=0 To 9
        $minihearts[0][$i]=CreateOverlayGui(PlaceHeart($ll,0,$left),$i*((@DesktopHeight+63)/10),Random(0,2,1),$gui,"0"&$i)
        $minihearts[1][$i]=CreateOverlayGui(PlaceHeart($lr,$right,@DesktopWidth-49),$i*((@DesktopHeight+63)/10),Random(0,2,1),$gui,"1"&$i)
    Next
EndFunc

; ===============================================================================================================================
; Make them bubble!
; ===============================================================================================================================
Func UpdateMiniHearts()
    Local $pos
    For $i=0 To 9
        For $j=0 To 1
            $pos = WinGetPos($minihearts[$j][$i])
            $pos[1]-=1
            If $pos[1]<-63 Then
                $pos[1] = @DesktopHeight
                If $j=0 Then
                    $pos[0]=PlaceHeart($ll,0,(@DesktopWidth-811)/2)
                Else
                    $pos[0]=PlaceHeart($lr,(@DesktopWidth+811)/2,@DesktopWidth-49)
                EndIf
            EndIf
            WinMove($minihearts[$j][$i],"",$pos[0],$pos[1])
        Next
    Next
EndFunc

; ===============================================================================================================================
; Create overlay gui
; ===============================================================================================================================
Func CreateOverlayGUI($x,$y,$img=-1,$master=-1,$title="OLgui")
    Local $retgui = GUICreate("OLgui",49,63,$x,$y,$WS_POPUP,$WS_EX_LAYERED,$master)
    If $img==-1 Then
        SetBitMap($retgui, $Himg[Random(0,2,1)], 128)
    Else
        SetBitMap($retgui, $Himg[$img], 128)
    EndIf
    GUISetState(@SW_SHOW,$retgui)
    Return $retgui
EndFunc

; ===============================================================================================================================
; Initialize
; ===============================================================================================================================
Func Init()
    ; Load layered image
    _GDIPlus_Startup()
    $Himg[0] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\valentine-heart-small.png")
    $Himg[1] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\valentine-heart-small-left.png")
    $Himg[2] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\valentine-heart-small-right.png")
EndFunc

; ===============================================================================================================================
; denit
; ===============================================================================================================================
Func denit()
    ; Release resources
    _GDIPlus_ImageDispose($Himg[0])
    _GDIPlus_ImageDispose($Himg[1])
    _GDIPlus_ImageDispose($Himg[2])
    _GDIPlus_Shutdown()
EndFunc

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($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", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc

It displays an image in the middle (semi-transparent) and has random hearts scrolling up the left and right sides.

Update: Made the center text generic (Happy Valentines Day! I Love You!), fixed a display bug found by rogue5099, added a base heart image with no text (for easier customization), and merged the code into one source file.

Edited by NerdFencer

_________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell

Link to comment
Share on other sites

If you dont mind can you please tell me how to change victoria's name in the scrip.... I have tried but no use. So I am asking you now.

You have to edit VDgui.png or create your own.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

This works fine on my computer but once I force it on her computer it has little windows which the small hearts are in...

me: Windows 7 (AutoIt installed, dunno if that makes a difference)

her: windows vista

I've tried editing:

Func CreateOverlayGUI($x,$y,$img=-1,$master=-1,$title="OLgui")
    Local $retgui = GUICreate("OLgui",49,63,$x,$y,-1,$WS_EX_LAYERED,$master)
    If $img==-1 Then
        SetBitMap($retgui, $Himg[Random(0,2,1)], 128)
    Else
        SetBitMap($retgui, $Himg[$img], 128)
    EndIf
    GUISetState(@SW_SHOW,$retgui)
    Return $retgui
EndFunc

No luck, also I have tried it on XP and another windows 7 machine and it works fine it just her comp. Thinking I need to install something on her comp to get ti to work correctly..

Solution:

(Changed -1 to $WS_POPUP)

Func CreateOverlayGUI($x,$y,$img=-1,$master=-1,$title="OLgui")
    Local $retgui = GUICreate("OLgui",49,63,$x,$y,$WS_POPUP,$WS_EX_LAYERED,$master)
    If $img==-1 Then
        SetBitMap($retgui, $Himg[Random(0,2,1)], 128)
    Else
        SetBitMap($retgui, $Himg[$img], 128)
    EndIf
    GUISetState(@SW_SHOW,$retgui)
    Return $retgui
EndFunc
Edited by rogue5099
Link to comment
Share on other sites

Attached is the Main heart that says "Happy Valentines Day".

I edited the picture to say just "I love you." Instead of saying "I love you Victoria".

Also I made all of the white background of the Image Transparent and changed the white letters to Red so they wouldn't be transparent as well.

Just replace this file with the one you have currently to apply the change.

By the way very nice script, opened up several options for the future for me.

post-32963-12653201151352_thumb.png

Edited by rogue5099
Link to comment
Share on other sites

Very Nice additions:

Never to place a heart in the same spot...

Func PlaceHeart(ByRef $last, $left, $right)
    Local $place = $last
    While $last-40<$place And $last+40>$place
        $place = Random($left,$right,1)
    WEnd
    $last = $place
    Return $place
EndFunc

Also I like the whole heart being transparent, I tried this with WinSetTrans but was unsuccessfull. The Capital L and Y in "I Love You" does make a differnce!!! Last but not least changing the GUI window name was a good idea to not let us idiot guys get in trouble with some other girls name!!

Glad I could be of some help.

Link to comment
Share on other sites

  • 2 weeks later...

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...