Fabse Posted July 31, 2018 Share Posted July 31, 2018 (edited) Hi Community! I need to react on Desktop Changes. When i run: #include <WinAPIFiles.au3> #include <WinAPIMem.au3> $hDirectory = _WinAPI_CreateFileEx(@DesktopDir, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS) $pBuffer = _WinAPI_CreateBuffer(8388608) AdlibRegister("_CompareDesktop", 200) While 1 Sleep(10) WEnd Func _CompareDesktop() $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_ATTRIBUTES), $pBuffer, 8388608, 1) If $aData[0][0] <> 0 Then $Box = MsgBox(1 + 32 + 262144, "Desktop Files Changed") If $Box = 1 Then Else EndIf EndIf EndFunc its working pretty well, When i use another func with AdlibRegister, it freezes... #include <WinAPIFiles.au3> #include <WinAPIMem.au3> $hDirectory = _WinAPI_CreateFileEx(@DesktopDir, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS) $pBuffer = _WinAPI_CreateBuffer(8388608) AdlibRegister("_AnyFunc", 200) AdlibRegister("_CompareDesktop", 200) While 1 Sleep(10) WEnd Func _CompareDesktop() $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_ATTRIBUTES), $pBuffer, 8388608, 1) If $aData[0][0] <> 0 Then $Box = MsgBox(1 + 32 + 262144, "","Desktop Files Changed") If $Box = 1 Then Else EndIf EndIf EndFunc Func _AnyFunc() ToolTip("Im a fast refreshing tooltip") EndFunc My knowledge about Memory isnt very deep, I c+p from Helpfile, Also The Buffer! Thanks in advance! e: added some sleeps e²: changed title Edited August 1, 2018 by Fabse Link to comment Share on other sites More sharing options...
Developers Jos Posted July 31, 2018 Developers Share Posted July 31, 2018 2 minutes ago, Fabse said: When i use another func with AdlibRegister, it freezes... So you are running each 20 ms (50 times per second) this ToolTip() command and am surprised it freezes? Also your close loop While-Wend doesn't have any sleep(10) in it so will consume a lot of CPU. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Fabse Posted July 31, 2018 Author Share Posted July 31, 2018 (edited) #include <WinAPIFiles.au3> #include <WinAPIMem.au3> $hDirectory = _WinAPI_CreateFileEx(@DesktopDir, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS) $pBuffer = _WinAPI_CreateBuffer(8388608) AdlibRegister("_AnyFunc", 1000) AdlibRegister("_CompareDesktop", 2000) While 1 Sleep(100) WEnd Func _CompareDesktop() $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_ATTRIBUTES), $pBuffer, 8388608, 1) If $aData[0][0] <> 0 Then $Box = MsgBox(1 + 32 + 262144, "","Desktop Files Changed") If $Box = 1 Then Else EndIf EndIf EndFunc Func _AnyFunc() ToolTip("Im a slow refreshing tooltip") EndFunc I guess youre right but thats not the problem, this version isnt working either... And i got a strong cpu that can refresh a tooltip 50 times per second :S Edited July 31, 2018 by Fabse Link to comment Share on other sites More sharing options...
Developers Jos Posted July 31, 2018 Developers Share Posted July 31, 2018 so, which part isn't working exactly? It still freezes? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Fabse Posted July 31, 2018 Author Share Posted July 31, 2018 (edited) The Tooltip is Frozen until directory changes happened, then it goes on after i clicked the button. like, the Script is paused until i receive a change. I also cant pause or exit the script in that time per tray icon. also tried: #include <Array.au3> Func _CompareDesktop() $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_ATTRIBUTES), $pBuffer, 8388608, 1) If $aData[0][0] <> 0 Then $Box = MsgBox(1 + 32 + 262144, "","Desktop Files Changed") If $Box = 1 Then Else EndIf EndIf _ArrayDelete($aData) EndFunc Edited July 31, 2018 by Fabse Link to comment Share on other sites More sharing options...
Fabse Posted August 1, 2018 Author Share Posted August 1, 2018 (edited) Sorry, i was lazy yesterday @Jos ;( e: tidy e²: script was nonsense, i write it again e³: I read help again and wrote this script, which isnt returning any error expandcollapse popup#include <WinAPIFiles.au3> #include <WinAPIMem.au3> #include <WinAPISys.au3> #include <WinAPIError.au3> $BufferSize = 8388608 $hDirectory = _WinAPI_CreateFileEx(@DesktopDir, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_DELETE, $FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS) If @error Then _WinAPI_ShowLastError('1', 1) EndIf $pBuffer = _WinAPI_CreateBuffer($BufferSize) If @error Then _WinAPI_ShowLastError('2', 1) EndIf AdlibRegister("_CompareDesktop", 200) AdlibRegister("_CompareDesktopDir", 1000) While 1 Sleep(10) WEnd Func _CompareDesktop() $CurrentSelectedIconCount = ControlListView("Program Manager", "", "SysListView321", "GetSelectedCount", 1) if @error Then MsgBox(0, "", "Error Selected Counter") EndIf If $CurrentSelectedIconCount <> 0 Then ;SelectedIconCount changed ToolTip("Selected Icons :" & $CurrentSelectedIconCount) EndIf EndFunc Func _CompareDesktopDir() $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_ATTRIBUTES), $pBuffer, $BufferSize, 1) If @error Then _WinAPI_ShowLastError('3', 1) Else If $aData[0][0] <> 0 Then $Box = MsgBox(1 + 32 + 262144, "", "Desktop Files Changed") EndIf EndIf _WinAPI_FreeMemory($pBuffer) If @error Then _WinAPI_ShowLastError('4', 1) EndIf $pBuffer = _WinAPI_CreateBuffer($BufferSize) If @error Then _WinAPI_ShowLastError('5', 1) EndIf EndFunc Cant find the mistake. It reacts to directory changes but tooltips are frozen till then. Edited August 1, 2018 by Fabse Link to comment Share on other sites More sharing options...
Fabse Posted August 2, 2018 Author Share Posted August 2, 2018 couldnt fix it, still... Link to comment Share on other sites More sharing options...
Fabse Posted August 4, 2018 Author Share Posted August 4, 2018 anyone can help me? Link to comment Share on other sites More sharing options...
Fabse Posted August 7, 2018 Author Share Posted August 7, 2018 bump Link to comment Share on other sites More sharing options...
Fabse Posted August 9, 2018 Author Share Posted August 9, 2018 bump Link to comment Share on other sites More sharing options...
Danyfirex Posted August 9, 2018 Share Posted August 9, 2018 Hello. The issue is that You're using _WinAPI_ReadDirectoryChanges synchronously so it will pause your script even any AdlibRegister. sp You need to use the synchronous. Do a google search and find an example. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Fabse Posted August 9, 2018 Author Share Posted August 9, 2018 thx @Danyfirex Link to comment Share on other sites More sharing options...
Danyfirex Posted August 9, 2018 Share Posted August 9, 2018 Here some good resources... https://stackoverflow.com/questions/43664998/readdirectorychangesw-and-getoverlappedresult https://www.programcreek.com/python/example/65489/win32file.ReadDirectoryChangesW https://cboard.cprogramming.com/windows-programming/77061-readdirectorychangesw.html https://stackoverflow.com/questions/40593500/using-readdirectorychangesw-asynchronously-in-a-loop https://stackoverflow.com/questions/40342925/asynchronous-readdirectorychangesw-call-blocks-the-thread-from-exiting Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut 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