Jump to content

while help


Didonet
 Share

Recommended Posts

Help... again! :P

I hate this while...

I'm creating program that change the mood in skype with the current song you play in winamp.

And i can't detect when does the song is changing...

I'm using this function to get the winamp song:

Func WinAmp()
    
Dim $PID = 1
$winampHWND = WinGetHandle ( "[CLASS:Winamp v1.x]")
If $winampHWND = 0 Then
   MsgBox (0,"","Winamp does not appear to be running.")
   Exit
EndIf

$result = _SendMessage($winampHWND, 0x0400, 0, 0x7D, 0)
If @error Then
   MsgBox (0,"","SendMessage failed." & @error)
   Exit
EndIf

$result2 = _SendMessage($winampHWND, 0x0400, $result, 0xD4, 0)
If @error Then
   MsgBox (0,"","SendMessage failed.")
   Exit
EndIf

$lpszTitle = $result2

$result3 = DllCall("user32.dll","int","GetWindowThreadProcessId","hwnd",$winampHWND,"int_ptr", $PID)

$PID = $result3[2]

if (@error OR NOT $PID) Then
   MsgBox (0,"","GetWindowThreadProcessId failed.")
   Exit
EndIf

$result4 = DllCall("kernel32.dll", "uint", "OpenProcess", "byte", 0x10, "int",0, "int", $PID)

if (@ERROR OR NOT $result4[0]) then
   MsgBox (0,"","OpenProcess failed: " & @ERROR)
   Exit
endif

$ProcessHandle = $result4[0]
$SongTitle = ""
While 1
    Local $v_Struct = DllStructCreate ('byte[1]')
   
    $result5 = DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $ProcessHandle, 'int', $lpszTitle, 'int', DllStructGetPtr ($v_Struct, 1), 'int', 1, 'int', 0)   

    if (@error) Then
        MsgBox (0,"","ReadProcessMemory failed: " & @error)
        DllCall("Kernel32.dll", "int", "CloseHandle", "int", $ProcessHandle)
        Exit
    EndIf
   
    $temp = DllStructGetData ($v_Struct, 1)
    $v_Struct = 0
    if $temp = 0 then ExitLoop
    $SongTitle &= Chr($temp)
    $lpszTitle += 1
WEnd

DllCall("Kernel32.dll", "int", "CloseHandle", "int", $ProcessHandle)  ; ErrorLevel and return value are not checked.
Return "I'm listening to: <b>" & $SongTitle & "</b>"
EndFuncoÝ÷ Ù©Ý~àzÛb.®·§¶j(v)ì*^jëh×6Func GetMood()
    $skype = ObjCreate("Skype4COM.Skype")
    If Not $skype.Client.IsRunning Then
        $skype.Client.Start()
    EndIf
    $skype.Attach
    Return $skype.CurrentUserProfile.MoodText
EndFunc

BUT... the loop is too fast... if i set sleep(5000) the whole program sleeps for 5 secs...

How can i check if the song is changed to change it... ;)

Link to comment
Share on other sites

  • Moderators

Just make a separate function to check every 5 seconds the same function you're checking in the loop.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

While 1
    $msg = GUIGetMsg()

    If $loop > 500 Then
        $currentWinamp = WinAmp()
            If $currentWinamp <> GetMood() Then
                GUICtrlSetData($text, $currentWinamp)
                ChangeMood($currentWinamp)
                TrayTip('Current listening...', $currentWinamp, 5)
            EndIf
        $loop = 0
    EndIf
$loop+=1
WEnd

I created this... and without AdlibEnable it works... 1-2% of cpu...

I don't get it where to put the AdlibEnable too...

Link to comment
Share on other sites

  • Moderators

This should be even less CPU:

Global $sMood = "", $bCheckMood = False
AdlibEnable("_AdlibManager", 5000)

While 1
    $msg = GUIGetMsg()
    
    If $bCheckMood And $sMood <> GUICtrlRead($text) Then
        GUICtrlSetData($text, $sMood)
        $bCheckMood = False
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Func _AdlibManager()
    $bCheckMood = True
    $sMood = GetMood()
EndFunc

Func GetMood()
    $skype = ObjCreate("Skype4COM.Skype")
    If Not $skype.Client.IsRunning Then
        $skype.Client.Start()
    EndIf
    $skype.Attach
    Return $skype.CurrentUserProfile.MoodText
EndFunc
Of course include your big winamp() func too.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

hah, it's true, the process is 0% CPU :)

Thanks... but... one problem :P

If I want to change my mood by the program... when i start to writing the new mood it checks that the content of the edit is not like in my mood and it deletes what i write at this moment and replace it with my mood... is it possible when i'm writing something to stop checking 0.o

Thanks again! ;)

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