Damein Posted March 31, 2012 Share Posted March 31, 2012 (edited) So I have a GUI that I want to constantly update the data shown. The problem is, when it refreshes (It deletes and re-creates the GUI, due to a GDI image. I believe I was told I had to do it this way to remove the image? Maybe I was mistaken) Anyways. So when it does this I lose focus on the window I am on. Not that it minimizes or anything, but I have to click the window again to start typing again. Also, full screen aps. get minimized. Here is the script. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icon.ico #AutoIt3Wrapper_Res_Comment=Beta testing #AutoIt3Wrapper_Res_Description=Pulls data from Weather.com #AutoIt3Wrapper_Res_Fileversion=1.3.0.0 #AutoIt3Wrapper_Res_LegalCopyright=RobertSSoftware #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #Include <WinAPI.au3> #include "WeatherUDF.au3" #include <array.au3> Opt("GUIOnEventMode", 1) Global $Statuses = IniReadSection("Statuses.ini", "Status") Global $XY = IniReadSection("Statuses.ini", "XY") Global $ZipCode, $GUI, $hgraphic, $himage, $RightNowGui, $TodayGui, $TonightGui, $TomorrowGui, $RefreshTime $ZipCode = InputBox("Zip code", "Please input your zip code") $ZipCode2 = "http://www.zip-codes.com/zip-code/" & $ZipCode Global $sSource = BinaryToString(InetRead($ZipCode2)) $City = StringRegExp($sSource,'(?i)(?s)<a href="/city/(.*?)-(.*?).asp',1) $State = StringRegExp($sSource,'(?i)(?s)<a href="/state(.*?)/(.*?).asp',1) $Url = 'http://www.weather.com/weather/today/' & $City[1] & '+' & $State[1] & '+' & $Zipcode Global $h_Desktop_SysListView32 _GetDesktopHandle() $Width = @DesktopWidth $Height = @DesktopHeight _GetOverViewTimes() _GetOverViewTemperature() _GetOverViewImages() _GetOverViewStatus() $RefreshRate = InputBox("Refresh Rate", "Please input a numerical value of 1-60." & @CRLF & @CRLF & "1 being one minute, 60 being an hour." & @CRLF & @CRLF & "This will be your refresh time for the Weather Widget","","",350,250) If $RefreshRate = 0 Then MsgBox(48,"Refresh Rate", "You've selected to have no refresh rate. To refresh the Weather Widget you may right click on it and select 'Refresh'") _RightNowGUI() Else For $i = 1 To $RefreshRate Step +1 $RefreshTime += 60000 Next AdlibRegister("_Refresh", $RefreshTime) _RightNowGUI() EndIf Func _RightNowGUI() GuiDelete($RightNowGUI) GuiDelete($TodayGUI) GuiDelete($TonightGUI) GuiDelete($TomorrowGUI) $RightNowGUI = GUICreate("", 150, 300, $Width-151, $Height-600, BitOR($WS_POPUP,$WS_BORDER), Default, WinGetHandle(AutoItWinGetTitle())) GuiSetFont(13) GUICtrlSetDefColor(0xFFFFFF) GUISetBkColor(0x000000) WinSetTrans($RightNowGUI,"",200) GuiSetState() GuiCtrlCreateLabel($OverViewTime[1],38,10,200,50) For $i = 1 To $Statuses[0][0] If $Statuses[$i][1] = $OverViewStatus[1] Then For $i = 1 To $XY[0][0] If $XY[$i][0] = $OverViewStatus[1] Then $Split = StringSplit($XY[$i][1],",") EndIf Next GuiCtrlCreateLabel($OverViewStatus[1],$Split[1],$Split[2]) GuiCtrlSetFont(-1,7.8) EndIf Next GuiCtrlCreateLabel("Temperature",35,230,200,40) GuiCtrlCreateLabel($OverViewTemp[1] & "°F",64,250,200,40) $ContextMenu = GuiCtrlCreateContextMenu() $RightNowItem = GuiCtrlCreateMenuItem($OverViewTime[1], $ContextMenu) GUICtrlSetOnEvent($RightNowItem, "_RightNowGUI") $TodayItem = GuiCtrlCreateMenuItem($OverViewTime[2], $ContextMenu) GUICtrlSetOnEvent($TodayItem, "_TodayGUI") $TonightItem = GuiCtrlCreateMenuItem($OverViewTime[3], $ContextMenu) GUICtrlSetOnEvent($TonightItem, "_TonightGUI") $TomorrowItem = GuiCtrlCreateMenuItem($OverViewTime[4], $ContextMenu) GUICtrlSetOnEvent($TomorrowItem, "_TomorrowGUI") $RefreshItem = GuiCtrlCreateMenuItem("Refresh", $ContextMenu) GUICtrlSetOnEvent($RefreshItem, "_Refresh") $ExitItem = GuiCtrlCreateMenuItem("Close", $ContextMenu) GUICtrlSetOnEvent($ExitItem, "_Exit") DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $RightNowGUI, "hwnd", $h_Desktop_SysListView32) _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Images/Image1.png") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($RightNowGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 13, 35, 130,160) EndFunc Func _TodayGUI() GuiDelete($RightNowGUI) GuiDelete($TodayGUI) GuiDelete($TonightGUI) GuiDelete($TomorrowGUI) $TodayGUI = GUICreate("", 150, 300, $Width-151, $Height-600, BitOR($WS_POPUP,$WS_BORDER), Default, WinGetHandle(AutoItWinGetTitle())) GuiSetFont(13) GUICtrlSetDefColor(0xFFFFFF) GUISetBkColor(0x000000) WinSetTrans($TodayGui,"",200) GuiSetState() For $i = 1 To $Statuses[0][0] If $Statuses[$i][1] = $OverViewStatus[2] Then For $i = 1 To $XY[0][0] If $XY[$i][0] = $OverViewStatus[2] Then $Split = StringSplit($XY[$i][1],",") EndIf Next GuiCtrlCreateLabel($OverViewStatus[2],$Split[1],$Split[2]) GuiCtrlSetFont(-1,7.8) EndIf Next If $OverViewTime[2] = "Today" Then GuiCtrlCreateLabel($OverViewTime[2], 48,10,200,50) ElseIf $OverViewTime[2] = "Tonight" Then GuiCtrlCreateLabel($OverViewTime[2], 45,10,200,50) Else MsgBox(0, "Test", "Error") EndIf GuiCtrlCreateLabel("Temperature",35,230,200,40) GuiCtrlCreateLabel($OverViewTemp[2] & "°F",64,250,200,40) $ContextMenu = GuiCtrlCreateContextMenu() $RightNowItem = GuiCtrlCreateMenuItem($OverViewTime[1], $ContextMenu) GUICtrlSetOnEvent($RightNowItem, "_RightNowGUI") $TodayItem = GuiCtrlCreateMenuItem($OverViewTime[2], $ContextMenu) GUICtrlSetOnEvent($TodayItem, "_TodayGUI") $TonightItem = GuiCtrlCreateMenuItem($OverViewTime[3], $ContextMenu) GUICtrlSetOnEvent($TonightItem, "_TonightGUI") $TomorrowItem = GuiCtrlCreateMenuItem($OverViewTime[4], $ContextMenu) GUICtrlSetOnEvent($TomorrowItem, "_TomorrowGUI") $RefreshItem = GuiCtrlCreateMenuItem("Refresh", $ContextMenu) GUICtrlSetOnEvent($RefreshItem, "_Refresh") $ExitItem = GuiCtrlCreateMenuItem("Close", $ContextMenu) GUICtrlSetOnEvent($ExitItem, "_Exit") DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $RightNowGUI, "hwnd", $h_Desktop_SysListView32) _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Images/Image2.png") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($TodayGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 13, 35, 130,160) EndFunc Func _TonightGUI() GuiDelete($RightNowGUI) GuiDelete($TodayGUI) GuiDelete($TonightGUI) GuiDelete($TomorrowGUI) $TonightGUI = GUICreate("", 150, 300, $Width-151, $Height-600, BitOR($WS_POPUP,$WS_BORDER), Default, WinGetHandle(AutoItWinGetTitle())) GuiSetFont(13) GUICtrlSetDefColor(0xFFFFFF) GUISetBkColor(0x000000) WinSetTrans($TonightGui,"",200) GuiSetState() For $i = 1 To $Statuses[0][0] If $Statuses[$i][1] = $OverViewStatus[3] Then For $i = 1 To $XY[0][0] If $XY[$i][0] = $OverViewStatus[3] Then $Split = StringSplit($XY[$i][1],",") EndIf Next GuiCtrlCreateLabel($OverViewStatus[3],$Split[1],$Split[2]) GuiCtrlSetFont(-1,7.8) EndIf Next If $OverViewTime[3] = "Tonight" Then GuiCtrlCreateLabel($OverViewTime[3], 48,10,200,50) ElseIf $OverViewTime[3] = "Tomorrow" Then GuiCtrlCreateLabel($OverViewTime[3], 43,10,200,50) Else MsgBox(0, "Test", "Error") EndIf GuiCtrlCreateLabel("Temperature",35,230,200,40) GuiCtrlCreateLabel($OverViewTemp[3] & "°F",64,250,200,40) $ContextMenu = GuiCtrlCreateContextMenu() $RightNowItem = GuiCtrlCreateMenuItem($OverViewTime[1], $ContextMenu) GUICtrlSetOnEvent($RightNowItem, "_RightNowGUI") $TodayItem = GuiCtrlCreateMenuItem($OverViewTime[2], $ContextMenu) GUICtrlSetOnEvent($TodayItem, "_TodayGUI") $TonightItem = GuiCtrlCreateMenuItem($OverViewTime[3], $ContextMenu) GUICtrlSetOnEvent($TonightItem, "_TonightGUI") $TomorrowItem = GuiCtrlCreateMenuItem($OverViewTime[4], $ContextMenu) GUICtrlSetOnEvent($TomorrowItem, "_TomorrowGUI") $RefreshItem = GuiCtrlCreateMenuItem("Refresh", $ContextMenu) GUICtrlSetOnEvent($RefreshItem, "_Refresh") $ExitItem = GuiCtrlCreateMenuItem("Close", $ContextMenu) GUICtrlSetOnEvent($ExitItem, "_Exit") DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $RightNowGUI, "hwnd", $h_Desktop_SysListView32) _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Images/Image3.png") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($TonightGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 13, 35, 130,160) EndFunc Func _TomorrowGUI() GuiDelete($RightNowGUI) GuiDelete($TodayGUI) GuiDelete($TonightGUI) GuiDelete($TomorrowGUI) $TomorrowGUI = GUICreate("", 150, 300, $Width-151, $Height-600, BitOR($WS_POPUP,$WS_BORDER), Default, WinGetHandle(AutoItWinGetTitle())) GuiSetFont(13) GUICtrlSetDefColor(0xFFFFFF) GUISetBkColor(0x000000) WinSetTrans($TomorrowGui,"",200) GuiSetState() For $i = 1 To $Statuses[0][0] If $Statuses[$i][1] = $OverViewStatus[4] Then For $i = 1 To $XY[0][0] If $XY[$i][0] = $OverViewStatus[4] Then $Split = StringSplit($XY[$i][1],",") EndIf Next GuiCtrlCreateLabel($OverViewStatus[4],$Split[1],$Split[2]) GuiCtrlSetFont(-1,7.8) EndIf Next If $OverViewTime[4] = "Tomorrow" Then GuiCtrlCreateLabel($OverViewTime[4], 45,10,200,50) ElseIf $OverViewTime[4] = "Tomorrow Night" Then GuiCtrlCreateLabel($OverViewTime[4], 22,10,200,50) EndIf GuiCtrlCreateLabel("Temperature",35,230,200,40) GuiCtrlCreateLabel($OverViewTemp[4] & "°F",64,250,200,40) $ContextMenu = GuiCtrlCreateContextMenu() $RightNowItem = GuiCtrlCreateMenuItem($OverViewTime[1], $ContextMenu) GUICtrlSetOnEvent($RightNowItem, "_RightNowGUI") $TodayItem = GuiCtrlCreateMenuItem($OverViewTime[2], $ContextMenu) GUICtrlSetOnEvent($TodayItem, "_TodayGUI") $TonightItem = GuiCtrlCreateMenuItem($OverViewTime[3], $ContextMenu) GUICtrlSetOnEvent($TonightItem, "_TonightGUI") $TomorrowItem = GuiCtrlCreateMenuItem($OverViewTime[4], $ContextMenu) GUICtrlSetOnEvent($TomorrowItem, "_TomorrowGUI") $RefreshItem = GuiCtrlCreateMenuItem("Refresh", $ContextMenu) GUICtrlSetOnEvent($RefreshItem, "_Refresh") $ExitItem = GuiCtrlCreateMenuItem("Close", $ContextMenu) GUICtrlSetOnEvent($ExitItem, "_Exit") DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $RightNowGUI, "hwnd", $h_Desktop_SysListView32) _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Images/Image4.png") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($TomorrowGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 13, 35, 130,160) EndFunc Func _Quit() Exit EndFunc While 1 Sleep(10) WEnd Func _GetDesktopHandle() $h_Desktop_SysListView32 = 0 Local Const $hDwmApiDll = DllOpen("dwmapi.dll") Local $sChkAero = DllStructCreate("int;") DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero)) Local $aero_on = DllStructGetData($sChkAero, 1) If Not $aero_on Then $h_Desktop_SysListView32 = WinGetHandle("Program Manager") Return 1 Else Local $hCBReg = DllCallbackRegister("_GetDesktopHandle_EnumChildWinProc", "hwnd", "hwnd;lparam") If $hCBReg = 0 Then Return SetError(2) DllCall("user32.dll", "int", "EnumChildWindows", "hwnd", _WinAPI_GetDesktopWindow(), "ptr", DllCallbackGetPtr($hCBReg), "lparam", 101) Local $iErr = @error DllCallbackFree($hCBReg) If $iErr Then Return SetError(3, $iErr, "") EndIf Return 2 EndIf EndFunc Func _Refresh() _GetOverViewTimes() _GetOverViewTemperature() _GetOverViewImages() ConsoleWrite(@CRLF & @CRLF & $OverViewImage[1] & @CRLF & $OverViewImage[2] & @CRLF & $OverViewImage[3] & @CRLF & $OverViewImage[4]) _GetOverViewStatus() _RightNowGUI() EndFunc Func _Exit() _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_ShutDown() Exit EndFunc So I guess the best thing would be do is just update the text boxes etc. without re-creating the whole GUI. So would this be possible? I'm going to test it now, just would like some light shed on this. Thanks! So a little update. When starting to test this I realized I don't think I would be able to do this. Owing to the fact I would have to use GuiCtrlSetData to change the labels. But since each label has a different X & Y I wouldn't be able to do this, would I? Edited March 31, 2012 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
martin Posted March 31, 2012 Share Posted March 31, 2012 needs to be applied before I could give any more help. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Damein Posted April 1, 2012 Author Share Posted April 1, 2012 (edited) I'm sorry, I must of forgot about that thread.. sorry ^^; (I have the worst memory in the world, I swear) But thank you so much, I forgot to add the Dispose's to the GDI and that worked out perfectly. Now, as for deleting and re-creating the GUI's.. As explained above, I have to re-create all the labels anyways because each one has a different X,Y coordinate. So is there a way around this to where I wouldn't have to re-create those labels, or no? Because with your suggestion in the previous thread it wouldn't work due to the problem of the positioning. Edited April 1, 2012 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
martin Posted April 2, 2012 Share Posted April 2, 2012 I don't really understand the repositioning bit. But all you need to do, is to create labels etc only once, update the data, caption or whatever, with GuiCtrlSetData, and change the position of a control if needed with ControlMove.If that isn'ty what you need then I need some more information to help me understand. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Damein Posted April 4, 2012 Author Share Posted April 4, 2012 Alright, so I thought of a way to get all the labels done. Now the last problem is the GDI images. How can I delete an image from the GUI? I don't see a option for that in the GDI function. So I currently have: _GDIPlus_StartUp() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "/Images/Image4.png") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($TomorrowGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 13, 35, 130,160) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Now when I do the refresh function, I want the image to be deleted from the GUI and the new image replaces it without having to startup the GDI again. Because this will cause the GUI to flash and consequently focus your PC to the GUI. Not what I want. Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
Damein Posted April 4, 2012 Author Share Posted April 4, 2012 So to show an update. I think I have everything done except for the images. For some reason now when I Hide/Show a GUI the image gets wiped from it. So next time I bring it back up it's blank. To show what I mean download the zip file, extract and run the Widget2.au3 file. Also, you'll notice there is no image from the start either. So you must force a refresh to see the image. So when you do that it comes up. But if you select another GUI from the contextmenu and then go back, the image is one again gone. You'll have to put your zip code in first run. TestWidget.zip Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
Damein Posted April 5, 2012 Author Share Posted April 5, 2012 Solved Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic 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