Jump to content

AdlibRegister/Loop and _WinAPI_ReadDirectoryChanges


Recommended Posts

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 by Fabse
Link to comment
Share on other sites

  • Developers
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

#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 by Fabse
Link to comment
Share on other sites

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 by Fabse
Link to comment
Share on other sites

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

#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 by Fabse
Link to comment
Share on other sites

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

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