911radio Posted January 9, 2008 Share Posted January 9, 2008 Ok, this is my first time creating anything with Autoit. Most all of my code was borrowed from other projects here. I'm trying to re-create a piece of freeware that I had made for me a little while back (just for kicks, to see if I can do it, no disrespect to the person who created my software). There are a few issues I have before moving forward with extra functionality (I'll ask later on in this thread) but it's remarkably close at the moment. I guess the bugs are from noobish code and cramming code together! Problem: Before I added the functionality for the INI read and write, I could use the "X" or the exit button and it will close. Now it will not, also it seems to lock up a bit or get very slow at times, although it does work. If you can look at my code and tell me what changes to make it would be great. Basically what this program does is check for internet connection from a mobile computer by pinging a server. It lights green when it gets a response, red when it doesnt. I have the text box so that I can change IP's on the fly for testing but it has a static IP in the .INI file. The current software I have (compiled in VB5 I think) works great, so I know this will when I get the bugs worked out. Thanks for your help! expandcollapse popup#include <GUIConstants.au3> #include <Misc.au3> Global $message $Co_Ord1 = IniRead(@ScriptDir & "\pong.ini", "extras", "left", "-1") $Co_Ord2 = IniRead(@ScriptDir & "\pong.ini", "extras", "top", "-1") $IP_Addr = IniRead(@ScriptDir & "\pong.ini", "functions", "IP", "-1") GUICreate("Network Notifier 0.1", 240, 80, $Co_Ord1, $Co_Ord2) GUISetState() $Path1 = @scriptdir & "\null.bmp" $te = GUICtrlCreateLabel("Status:",2,30,50,20) $iplbl = GUICtrlCreateLabel("IP:",1,4,20,20) $pic = GuiCtrlCreatePic($path1, 190, 30, 33, 33) $ExitButton = GUICtrlCreateButton("Exit", 196,1,40,20) $newp = MouseGetPos() $i = GUICtrlCreateInput($IP_Addr, 15, 1, 180, 20) While 1 ;$msg = GUIGetMsg() $a = GUICtrlRead($i) $ping_result = ping($a, 5000) If $ping_result = 0 Then GuiCtrlSetImage($pic, @scriptdir & "\Off.bmp") Else GuiCtrlSetImage($pic, @scriptdir & "\On.bmp") EndIf ;If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_PRIMARYDOWN $mp = MouseGetPos() $wp = WinGetPos("Network Notifier 1.0") While _IsPressed("01") $newp = MouseGetPos() WinMove("Network Notifier 1.0", '', $wp[0] + $newp[0] - $mp[0], $wp[1] + $newp[1] - $mp[1]) WEnd If $wp[0] + $newp[0] - $mp[0] <> $Co_Ord1 Then IniWrite(@ScriptDir & "\pong.ini", "extras", "left", $wp[0] + $newp[0] - $mp[0]) IniWrite(@ScriptDir & "\pong.ini", "extras", "top", $wp[1] + $newp[1] - $mp[1]) EndIf Case $msg = $ExitButton GUIDelete() PLExit() EndSelect WEnd ;Exit Routine Func PLExit() If $Co_Ord1 <> $wp[0] + $newp[0] - $mp[0] Or $Co_Ord2 <> $wp[1] + $newp[1] - $mp[1] Then $message = " New Menu Position Saved" DisplayMessage() EndIf Exit EndFunc ;==>PLExit ;Message Box Subroutine Func DisplayMessage() SplashTextOn("Network Notifier 1.0", $message, 270, 50, 150, 350, 36, "Arial", 10, 600) Sleep(1000) SplashOff() EndFunc ;==>DisplayMessage pong.ini File CODE[functions] IP=192.168.5.1 [extras] left=25 top=25 interval=1 autostart=1NetNot.au3null.bmpOff.bmpOn.bmp Link to comment Share on other sites More sharing options...
covaks Posted January 10, 2008 Share Posted January 10, 2008 Hmm, I originally just made a few changes to get it running smoothly. But the forums were down for a few minutes, so I just kept mucking around with it. lol. You had two while loops, but the first one never ended, so the code in the second one was never executed. I figured you were just trying to record window coords with that second loop and store it in the ini file, but you were going about it wrong, I added a check for that in the PLExit function. The stringregexp just makes sure a valid IP is entered before trying to ping. expandcollapse popup#include <GUIConstants.au3> #include <Misc.au3> opt("GuiOnEventMode",1) $Co_Ord1 = IniRead(@ScriptDir & "\pong.ini", "extras", "left", "-1") $Co_Ord2 = IniRead(@ScriptDir & "\pong.ini", "extras", "top", "-1") $IP_Addr = IniRead(@ScriptDir & "\pong.ini", "functions", "IP", "-1") $hWnd = GUICreate("Network Notifier 0.1", 240, 80, $Co_Ord1, $Co_Ord2) GUISetState() $Path1 = @scriptdir & "\null.bmp" $te = GUICtrlCreateLabel("Status:",2,30,50,20) $iplbl = GUICtrlCreateLabel("IP:",1,4,20,20) $pic = GuiCtrlCreatePic($path1, 190, 30, 33, 33) $ExitButton = GUICtrlCreateButton("Exit", 196,1,40,20) GUICtrlSetOnEvent(-1,"PLExit") GUISetOnEvent($GUI_EVENT_CLOSE,"PLExit") $i = GUICtrlCreateInput($IP_Addr, 15, 1, 180, 20) While 1 If StringRegExp(GUICtrlRead($i),"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b",0) = 1 Then $a = GUICtrlRead($i) $ping_result = ping($a, 250) If $ping_result = 0 Then GuiCtrlSetImage($pic, @scriptdir & "\Off.bmp") Else GuiCtrlSetImage($pic, @scriptdir & "\On.bmp") EndIf EndIf Sleep(750) Wend ;Exit Routine Func PLExit() Local $winpos = WinGetPos($hWnd) If $Co_Ord1 <> $winpos[0] OR $Co_Ord2 <> $winpos[1] Then IniWrite(@ScriptDir & "\pong.ini", "extras", "left", $winpos[0]) IniWrite(@ScriptDir & "\pong.ini", "extras", "top", $winpos[1]) $msg = " New Menu Position Saved" DisplayMessage($msg) EndIf Exit EndFunc;==>PLExit ;Message Box Subroutine Func DisplayMessage($message, $SplashWidth = 270, $SplashHeight = 50) SplashTextOn("", $message, $SplashWidth, $SplashHeight, Int((@DesktopWidth/2) - ($SplashWidth/2)), Int((@DesktopHeight/2) - ($SplashHeight/2)), 33, "Arial", 10, 600) Sleep(1000) SplashOff() EndFunc;==>DisplayMessage Link to comment Share on other sites More sharing options...
911radio Posted January 12, 2008 Author Share Posted January 12, 2008 covaks, thanks very much for your help. It seems to work great now! To all, my next items on the list of things to add are: - Removal of the minimize button - (easy enough I'm sure but just haven't had the chance to research it) - A real progress bar that moves when $ping_result = 1 and stops moving when $ping_result = 0 and will display the time of the last successful ping underneath. - Ability to "grey out" the text window where the IP is until you double click inside it. That way the IP address can still be changed but not accidentally. - Possibly the ability to have a small button that will reset the screen position back to the default in the INI file, when it was first created, but still let position be saved as the user moves it like it is now. Any help on any of these items is appreciated. If I figure out any of it in the meantime, I will report back. Thanks! Link to comment Share on other sites More sharing options...
911radio Posted January 19, 2008 Author Share Posted January 19, 2008 I got the removal of the minimize button, and it was as easy as I thought. I still could use help with the rest - A real progress bar that moves when $ping_result = 1 and stops moving when $ping_result = 0 and will display the time of the last successful ping underneath. Been playing with this but putting the sleep commands in screw the script up. Kinda lost as to how to do it right. - Ability to "grey out" the text window where the IP is until you double click inside it. That way the IP address can still be changed but not accidentally. - Possibly the ability to have a small button that will reset the screen position back to the default in the INI file, when it was first created, but still let position be saved as the user moves it like it is now. - Working on this and think I might have it. Again, any help on any of these items is appreciated. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now