PDA

Показать полную графическую версию : [решено] Проблема с треем (иконка и менюшка)


sashadeg
27-02-2010, 11:10
Я никак не могу понять, как можно сделать чтобы в скрипте шел какой-нибудь процесс и в то же время можно было работать с треем и иконками в трее?

Например у меня имеется вот такой скрипт:
(записывает в лог-файл все изменения ip адреса)
#include <Inet.au3>
While 1
$1=FileExists("iplog.txt")
If $1 = 0 Then
FileWrite(@ScriptDir & "\iplog.txt", " Время Дата Ip-адресс")
EndIf
$PublicIP = _GetIP()
$line = FileReadLine('iplog.txt', -1)
$line2 = StringTrimLeft($line,24)
If $PublicIP <> -1 Then
If $PublicIP <> $line2 Then
FileWrite(@ScriptDir & "\iplog.txt", @CRLF & @HOUR & ":" & @MIN & ":" & @SEC & " "&@MDAY&"."&@MON&"."&@YEAR&" " & $PublicIP)
TrayTip ("IpLog",$PublicIP,"", 1)
EndIf
EndIf
Sleep(1000*20)
WEnd

Я хочу, чтобы при отсутствии интернета (отсутствии ip адресса), в трее иконка процесса была одна, а при наличии интернета другая.
Как мне в мой скрипт встроить вот такой код:
#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)

$exititem = TrayCreateItem("Exit")

TraySetState()

$start = 0
While 1
$msg = TrayGetMsg()
If $msg = $exititem Then ExitLoop
TraySetIcon("Shell32.dll")
WEnd

Exit

madmasles
27-02-2010, 11:29
sashadeg,
Есть интернет - одна иконка, нет - другая:#include <WinAPIEx.au3>

Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("TrayMenuMode",1)

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$inet = _WinAPI_IsNetworkAlive()
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $inet = 0 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
TraySetIcon (http://www.autoitscript.com/autoit3/docs/functions/TraySetIcon.htm)("Shell32.dll", 10)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
TraySetIcon (http://www.autoitscript.com/autoit3/docs/functions/TraySetIcon.htm)("Shell32.dll", 20)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(1000)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

WinAPIEx (http://autoit-script.ru/index.php?topic=47.0)

sashadeg
27-02-2010, 12:48
madmasles, ты наверно не увидел:

Как мне в мой скрипт встроить вот такой код: »

Creat0R
27-02-2010, 13:45
Как мне в мой скрипт встроить вот такой код »
#NoTrayIcon
#include <Inet.au3>
#Include <Constants.au3>

Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("TrayMenuMode", 1)
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("TrayOnEventMode", 1)

$nExitItem = TrayCreateItem (http://www.autoitscript.com/autoit3/docs/functions/TrayCreateItem.htm)("Exit")
TrayItemSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/TrayItemSetOnEvent.htm)($nExitItem, "_Exit_Proc")
TraySetIcon (http://www.autoitscript.com/autoit3/docs/functions/TraySetIcon.htm)("Shell32.dll", 9)
TraySetState (http://www.autoitscript.com/autoit3/docs/functions/TraySetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) FileExists (http://www.autoitscript.com/autoit3/docs/functions/FileExists.htm)("iplog.txt") Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
FileWrite (http://www.autoitscript.com/autoit3/docs/functions/FileWrite.htm)(@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & "\iplog.txt", " Время Дата Ip-адресс")
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

$PublicIP = _GetIP()

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $PublicIP <> -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
TraySetIcon (http://www.autoitscript.com/autoit3/docs/functions/TraySetIcon.htm)("Shell32.dll", 9) ;Одна иконка

$sLine = StringTrimLeft (http://www.autoitscript.com/autoit3/docs/functions/StringTrimLeft.htm)(FileReadLine (http://www.autoitscript.com/autoit3/docs/functions/FileReadLine.htm)('iplog.txt', -1), 24)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $PublicIP <> $sLine Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
FileWrite (http://www.autoitscript.com/autoit3/docs/functions/FileWrite.htm)(@ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@ScriptDir) & "\iplog.txt", @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & @HOUR (http://www.autoitscript.com/autoit3/docs/macros.htm#@HOUR) & ":" & @MIN (http://www.autoitscript.com/autoit3/docs/macros.htm#@MIN) & ":" & @SEC (http://www.autoitscript.com/autoit3/docs/macros.htm#@SEC) & " " & @MDAY (http://www.autoitscript.com/autoit3/docs/macros.htm#@MDAY)&"."&@MON (http://www.autoitscript.com/autoit3/docs/macros.htm#@MON)&"."&@YEAR (http://www.autoitscript.com/autoit3/docs/macros.htm#@YEAR) & " " & $PublicIP)
TrayTip (http://www.autoitscript.com/autoit3/docs/functions/TrayTip.htm)("IpLog", $PublicIP, "", 1)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
TraySetIcon (http://www.autoitscript.com/autoit3/docs/functions/TraySetIcon.htm)("Shell32.dll", 10) ;Другая иконка
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(1000*20)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Exit_Proc()
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

sashadeg
27-02-2010, 14:34
If Not FileExists("iplog.txt") Then »
зачем нужно NOT ? Что он делает?

madmasles
27-02-2010, 14:58
зачем нужно NOT ? Что он делает? »Если нет файла iplog.txt, то он создается следующей строкой кода.

sashadeg
27-02-2010, 15:01
Спасибо. В общем то тоже самое что и у меня =) Чтото не въехал сразу... =\




© OSzone.net 2001-2012