Announcement

Collapse
No announcement yet.

How to know the changes in the file system ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to know the changes in the file system ?

    Without exhaustively use DIR$

    SDK ans faster solutions ?

    Thank you

  • #2
    You can set up a FindFirstChangeNotification/FindNextChangeNotification loop as demo'd here: Win32(SDK): Internet Cookie Monitor April 25, 2001

    I'm also pretty sure there are some new techniques available today. I know there are some new API functions for this but I forget the names.

    Also, there may be something in one of the File System APIs with the COM interface.. maybe some EVENTS.

    But be careful about asking for "any" change in the file system... e.g., the swap file ("DriveLetter:\Pagefile.sys") changes constantly but I cannot see why you'd care about that.
    Michael Mattias
    Tal Systems Inc.
    Racine WI USA
    mmattias@talsystems.com
    http://www.talsystems.com

    Comment


    • #3
      There is also the app FolderSpy
      http://venussoftcorporation.blogspot...folderspy.html

      with a SDK
      http://venussoftcorporation.blogspot...8/tfs-sdk.html

      It has been my on list to created something similar & I would love to know how they do it. As yet I have no code to share,

      I have folder spy running a ransomware honeypot of files. Sort of an early warning system.
      Last edited by Frank Fenti; 3 Nov 2016, 12:39 PM.
      BASIC shampoo - DO:LATHER:RINSE:LOOP UNTIL CLEAN <>0

      Comment


      • #4
        Wow, that TFS-SDK page shows a 15 -line console program. DLL comes precompiled. It all works via callback, so you can write your own program easily enough.

        I think that callback requires creating a COM object and setting up the EVENTS but how to do that is in the PB help file. (You'll have to hope the TLIB is embedded in the DLL or provided separately if you want to use the PB COM Browser to create the CLASS/INTERFACE definitions).

        Oh, yeah, it's free if I read the page correctly...
        Products (All are free to download and small in size)
        I would love to know how they do it
        Using one of the underlying Windows' API functions is where I'm putting my money. Not that I'd care, if the product works as advertised.

        I think sometimes PB users are scared of using Windows' API functions because they look like just SO.. MUCH ..CODE! But Microsoft has some pretty good programmers and a lot of their guys are almost certainly "speed freaks" just like certain PB PSF members.

        .
        MCM
        Michael Mattias
        Tal Systems Inc.
        Racine WI USA
        mmattias@talsystems.com
        http://www.talsystems.com

        Comment


        • #5
          I do not know if it exists, but the ideal would be to create a function for the PB.
          How I admit not being able, I would like if possible that the brains of this forum accept this challenge.

          Comment


          • #6
            > but the ideal would be to create a function for the PB.

            I gave you the link to what you can use in Post#2.

            Here's a link to how it's used: https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx

            You should be able to restructrure that into a PB FUNCTION with the arguments/options you want.

            There is also a FileSystemWatcher .NET class, but I don't know how to use those with PB.

            But I have to admit that TFS thing looks very inviting.

            You do realize if you really want to monitor the filesystem or even just a single folder you are going to have to be able to use Windows API and/or other third-party (eg TFS) functions, right?

            There is no PowerBASIC 'FILESYSTEM WATCH drive[\startpath\[mask] [,SUBDIRS]] TO MyCallbackProc' statement.

            MCM
            Michael Mattias
            Tal Systems Inc.
            Racine WI USA
            mmattias@talsystems.com
            http://www.talsystems.com

            Comment


            • #7
              Thank you Michael.

              What I want is exactly this Obtaining Directory Change Notifications.

              I want it in a cycle, and as soon as there are any changes, the program does the rest. I knew there should be more effective alternatives that DIR$.

              The problem here is with me as I do not feel comfortable with SDK, again I ask the following:

              DO
              SDK Function ( Obtaining Directory Change Notifications )

              IF File/Fold renamed or File/SubFold created or File deleted THEN DIR$

              LOOP
              Last edited by Ribeiro Alvo; 3 Nov 2016, 04:17 PM. Reason: "Michael" was misspelled.

              Comment


              • #8
                Code:
                DO
                      SDK Function ( Obtaining Directory Change Notifications )
                
                      IF File/Fold renamed or File/SubFold created or File deleted THEN
                         get file/folder type and name
                         display or log rename, create or delete
                
                LOOP
                That's a good start. But I am biased because I lay out my programs using pseudocode, too.

                (I think you probably realize now I am not going to write this for you)

                MCM
                Michael Mattias
                Tal Systems Inc.
                Racine WI USA
                mmattias@talsystems.com
                http://www.talsystems.com

                Comment


                • #9
                  Michael

                  > (I think you probably realize now I am not going to write this for you)

                  Not probably, more then right.

                  Although like that to happen, I understand. It may be that someone else does. It's a challenge that I am very grateful in advance.

                  Comment


                  • #10
                    Hi Ribeiro,

                    Try the following code, it use SHChangeNotifyRegister and SHGetKnownFolderIDList.
                    Compile and start the program then copy, rename, delete, etc... files in Windows-Explorer.

                    Have fun.

                    Pierre

                    Code:
                    #COMPILE EXE '#Win 9.07#
                    #DIM ALL
                    #INCLUDE "Win32api.inc"
                    
                    GLOBAL hDlg AS DWORD
                    
                    $AppName = "SHChangeNotifyRegister"
                    %Edit    = 101
                    
                    %SHCNRF_SHELLLEVEL     = &H0002???
                    %KF_FLAG_SIMPLE_IDLIST = &H00000100
                    
                    TYPE SHChangeNotifyEntry
                      pidl       AS ITEMIDLIST POINTER
                      fRecursive AS LONG
                    END TYPE
                    
                    DECLARE FUNCTION SHGetKnownFolderIDList LIB "Shell32.dll" ALIAS "SHGetKnownFolderIDList" _
                    (rfid AS GUID, BYVAL dwFlags AS DWORD, BYVAL hToken AS DWORD, ppidl AS ANY) AS LONG
                    
                    DECLARE FUNCTION SHChangeNotifyRegister LIB "SHELL32.DLL" ALIAS "SHChangeNotifyRegister" _
                    (BYVAL HWND AS DWORD, BYVAL fSources AS LONG, BYVAL fEvents AS LONG, BYVAL wMsg AS DWORD, _
                     BYVAL cEntries AS LONG, BYREF ChangeNotifyEntry AS ANY) AS DWORD
                    
                    DECLARE FUNCTION SHChangeNotifyDeregister LIB "SHELL32.DLL" ALIAS "SHChangeNotifyDeregister" _
                    (BYVAL ulID AS DWORD) AS LONG
                    '__________________________________________________________________________
                    
                    SUB TextAdd (BYVAL sAddToText AS STRING)
                    
                     'Move the caret to the end of text.
                     SendMessage(GetDlgItem(hDlg, %Edit), %EM_SETSEL, -1, -1)
                    
                     sAddToText = sAddToText & $CRLF 'Add a CRLF
                    
                     'Insert the string at caret position.
                     SendMessage(GetDlgItem(hDlg, %Edit), %EM_REPLACESEL, %TRUE, BYVAL STRPTR(sAddToText))
                    
                    END SUB
                    '______________________________________________________________________________
                    
                    CALLBACK FUNCTION DialogProc()
                     DIM   zPath(0 TO 1) AS ASCIIZ * %MAX_PATH
                     LOCAL sMessage      AS STRING
                     LOCAL index         AS LONG
                    
                     SELECT CASE AS LONG CBMSG
                    
                       CASE %WM_INITDIALOG
                         CONTROL SET FOCUS hDlg, %Edit
                         CONTROL SEND hDlg, %Edit, %EM_SETSEL, -1, -1
                    
                       CASE %WM_APP 'SHChangeNotifyRegister SHCNE_DISKEVENTS notification
                         'wParam is a pointer to two PIDLIST_ABSOLUTE pointers that can be NULL, depending on the event
                         'lParam is the event
                    
                         DIM p(0 TO 1) AS ITEMIDLIST POINTER AT CBWPARAM
                         FOR index = 0 TO 1                                    'Check both ITEMIDLIST POINTER
                           IF p(index) THEN                                    'Some valid info to get
                             SHGetPathFromIDList(BYVAL p(index), zPath(index)) 'Get string
                             CoTaskMemFree(BYVAL p(index))                     'Free memory
                           ELSE
                             zPath(index) = "Nil"                              'Nothing
                           END IF
                         NEXT
                    
                         SELECT CASE CBLPARAM
                           CASE %SHCNE_MEDIAINSERTED : sMessage = "SHCNE_MEDIAINSERTED - Media inserted: Drive letter is " & zPath(0)
                           CASE %SHCNE_MEDIAREMOVED  : sMessage = "SHCNE_MEDIAREMOVED - Media removed: Drive letter is "   & zPath(0)
                           CASE %SHCNE_DRIVEREMOVED  : sMessage = "SHCNE_DRIVEREMOVED - Drive removed: Drive letter is  "  & zPath(0)
                           CASE %SHCNE_DRIVEADD      : sMessage = "SHCNE_DRIVEADD - Drive added: Drive letter is  "        & zPath(0)
                    
                           CASE %SHCNE_RENAMEITEM    : sMessage = "SHCNE_RENAMEITEM - "   & zPath(0) & " - " & zPath(1)
                           CASE %SHCNE_CREATE        : sMessage = "SHCNE_CREATE - "       & zPath(0) & " - " & zPath(1)
                           CASE %SHCNE_DELETE        : sMessage = "SHCNE_DELETE - "       & zPath(0) & " - " & zPath(1)
                           CASE %SHCNE_MKDIR         : sMessage = "SHCNE_MKDIR - "        & zPath(0) & " - " & zPath(1)
                           CASE %SHCNE_RMDIR         : sMessage = "SHCNE_RMDIR - "        & zPath(0) & " - " & zPath(1)
                           CASE %SHCNE_UPDATEITEM    : sMessage = "SHCNE_UPDATEITEM - "   & zPath(0) & " - " & zPath(1)
                           CASE %SHCNE_RENAMEFOLDER  : sMessage = "SHCNE_RENAMEFOLDER - " & zPath(0) & " - " & zPath(1)
                         END SELECT
                         IF LEN(zPath(0)) THEN TextAdd(sMessage)
                    
                       CASE %WM_SIZE
                         IF CBWPARAM <> %SIZE_MINIMIZED THEN
                           SetWindowPos(GetDlgItem(hDlg, %Edit), 0, 5, 5, LO(WORD, CBLPARAM) - 10, HI(WORD, CBLPARAM) - 10, %SWP_NOZORDER)
                         END IF
                    
                     END SELECT
                    
                    END FUNCTION
                    '______________________________________________________________________________
                    
                    FUNCTION PBMAIN()
                     LOCAL ChangeInfo   AS SHChangeNotifyEntry
                     LOCAL CsidlDesktop AS GUID
                     LOCAL ulID         AS DWORD
                     LOCAL hIcon        AS DWORD
                    
                     DIALOG NEW %HWND_DESKTOP, "SHChangeNotifyRegister for disk events", , , 400, 150, %WS_POPUP OR %WS_BORDER OR _
                     %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR _
                     %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
                     %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                    
                     hIcon = ExtractIcon(0, "powrprof.dll", 1)
                     SetClassLong(hDlg, %GCL_HICON, hIcon) 'Set dialog icon
                    
                     CONTROL ADD TEXTBOX, hDlg, %Edit, _
                     "Create, copy, rename, or delete files or folders on any drive, insert or remove media." & $CRLF, _
                     5, 5, 940, 225, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_HSCROLL OR %WS_VSCROLL OR _
                     %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL OR %ES_WANTRETURN OR _
                     %ES_NOHIDESEL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_LTRREADING
                    
                     'SHGetSpecialFolderLocation(hDlg, %CSIDL_DESKTOP, ChangeInfo.pidl) 'For XP. Monitor all drives
                     CsidlDesktop = GUID$("{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}") 'FOLDERID_Desktop
                     SHGetKnownFolderIDList(CsidlDesktop, %KF_FLAG_SIMPLE_IDLIST, 0, ChangeInfo.pidl) 'For Vista+. Monitor all drives
                     IF ChangeInfo.pidl THEN
                       ChangeInfo.fRecursive = %TRUE 'Do sub-folder
                       'Registers a window to receive notifications from the file system or Shell.
                       ulID = SHChangeNotifyRegister(BYVAL hDlg, %SHCNRF_SHELLLEVEL, _
                                                     %SHCNE_CREATE OR %SHCNE_DELETE OR %SHCNE_MKDIR OR _
                                                     %SHCNE_RENAMEFOLDER OR %SHCNE_RENAMEITEM OR %SHCNE_RMDIR OR _
                                                     %SHCNE_DISKEVENTS OR %SHCNE_UPDATEITEM OR %SHCNE_DRIVEADD OR _
                                                     %SHCNE_DRIVEREMOVED OR %SHCNE_MEDIAINSERTED OR _
                                                     %SHCNE_MEDIAREMOVED OR %SHCNE_SERVERDISCONNECT, _
                                                     BYVAL %WM_APP, BYVAL 1, BYVAL VARPTR(ChangeInfo))
                       IF ulID THEN
                         DIALOG SHOW MODAL hDlg, CALL DialogProc
                         SHChangeNotifyDeregister(ulID)
                       ELSE
                         DIALOG END hDlg
                         MSGBOX "SHChangeNotifyRegister error !"
                       END IF
                       CoTaskMemFree(BYVAL ChangeInfo.pidl)
                     ELSE
                       MSGBOX "SHGetKnownFolderIDList error !"
                     END IF
                     IF hIcon THEN DestroyIcon(hIcon)
                    
                    END FUNCTION
                    '______________________________________________________________________________
                    '
                    Last edited by Pierre Bellisle; 19 May 2017, 09:32 PM. Reason: Cleanup 2017-05-19

                    Comment


                    • #11
                      Just ask if you want any clarification. :-)

                      Comment


                      • #12
                        Is that what I want.
                        Now I'll adapt it to my program.
                        I'm curious to see the behavior, it is faster than the extensive use of the DIR $

                        Thank you Pierre

                        Comment


                        • #13
                          I'm glad to help. :-)

                          Comment


                          • #14
                            Pierre

                            What about a SDK version rather than a legacy DDT version

                            Anyway thank you for that piece of code !
                            Patrice Terrier
                            www.zapsolution.com
                            www.objreader.com
                            Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                            Comment


                            • #15
                              Frank

                              Patrice, despite the excellent Pierre's piece of code, I am also of the same opinion.
                              Perhaps the SDK staff appear.
                              I know some here in the forum, and I call for them.

                              Comment


                              • #16
                                removed
                                Last edited by Patrice Terrier; 5 Nov 2016, 08:51 AM.
                                Patrice Terrier
                                www.zapsolution.com
                                www.objreader.com
                                Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                                Comment


                                • #17
                                  Will do SDK soon...

                                  Comment


                                  • #18
                                    removed
                                    Last edited by Patrice Terrier; 5 Nov 2016, 08:53 AM.
                                    Patrice Terrier
                                    www.zapsolution.com
                                    www.objreader.com
                                    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                                    Comment


                                    • #19
                                      removed
                                      Last edited by Patrice Terrier; 5 Nov 2016, 08:53 AM.
                                      Patrice Terrier
                                      www.zapsolution.com
                                      www.objreader.com
                                      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                                      Comment


                                      • #20
                                        Here is my SDK version,
                                        Note that one may monitor only specific space, like a single folder by setting the pidl
                                        using SHSimpleIDListFromPath, SHGetKnownFolderIDList, or the old SHGetSpecialFolderLocation.

                                        Have fun,
                                        Pierre

                                        Code:
                                        #COMPILE EXE '#Win 9.07#
                                        #DIM ALL
                                        #REGISTER NONE
                                        #INCLUDE "Win32Api.inc"
                                        
                                        %SHCNRF_INTERRUPTLEVEL     = &H0001???
                                        %SHCNRF_SHELLLEVEL         = &H0002???
                                        %SHCNRF_RECURSIVEINTERRUPT = &H1000???
                                        %SHCNRF_NEWDELIVERY        = &H8000???
                                        %KF_FLAG_SIMPLE_IDLIST     = &H00000100
                                        
                                        TYPE SHChangeNotifyEntry
                                          pidl       AS ITEMIDLIST POINTER
                                          fRecursive AS LONG
                                        END TYPE
                                        
                                        DECLARE FUNCTION SHGetKnownFolderIDList LIB "Shell32.dll" ALIAS "SHGetKnownFolderIDList" _
                                        (rfid AS GUID, BYVAL dwFlags AS DWORD, BYVAL hToken AS DWORD, ppidl AS ANY) AS LONG
                                        
                                        DECLARE FUNCTION SHChangeNotifyRegister LIB "SHELL32.DLL" ALIAS "SHChangeNotifyRegister" _
                                        (BYVAL HWND AS DWORD, BYVAL fSources AS LONG, BYVAL fEvents AS LONG, BYVAL wMsg AS DWORD, _
                                         BYVAL cEntries AS LONG, BYREF ChangeNotifyEntry AS ANY) AS DWORD
                                        
                                        DECLARE FUNCTION SHChangeNotifyDeregister LIB "SHELL32.DLL" ALIAS "SHChangeNotifyDeregister" _
                                        (BYVAL ulID AS DWORD) AS LONG
                                        
                                        $AppName = "SHChangeNotifyRegister"
                                        %Edit    = 101
                                        '______________________________________________________________________________
                                        
                                        SUB TextAdd(hEdit AS DWORD, BYVAL sText AS STRING)
                                        
                                         'Move the caret to the end of text.
                                         SendMessage(hEdit, %EM_SETSEL, -1, -1)
                                        
                                          sText = sText & $CRLF 'Add a CRLF
                                        
                                         'Insert the string at caret position.
                                         SendMessage(hEdit, %EM_REPLACESEL, %TRUE, BYVAL STRPTR(sText))
                                        
                                        END SUB
                                        '______________________________________________________________________________
                                        
                                        FUNCTION MainProc(BYVAL hWnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                                         DIM   zPath(0 TO 1) AS ASCIIZ * %MAX_PATH
                                         LOCAL sMessage      AS STRING
                                         STATIC hEdit        AS DWORD
                                         LOCAL index         AS LONG
                                        
                                         SELECT CASE uMsg
                                        
                                           CASE %WM_CREATE
                                             hEdit = CreateWindowEx(%WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_LTRREADING, _ 'Extended styles
                                                                    "Edit", _                                    'Class name
                                                                    "Create, copy, rename, or delete files or folders on any drive, insert or remove media." & $CRLF, _ 'Caption
                                                                    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _ 'Window styles
                                                                    %WS_HSCROLL OR %WS_VSCROLL OR %ES_LEFT OR _
                                                                    %ES_MULTILINE OR %ES_AUTOHSCROLL OR _
                                                                    %ES_AUTOVSCROLL OR %ES_WANTRETURN OR _
                                                                    %ES_NOHIDESEL, _
                                                                    5, 5, _                                      'Left, top
                                                                    575, 200, _                                  'Width, height
                                                                    hWnd, %Edit, _                               'Handle of parent, control ID
                                             GetWindowLong(hWnd, %GWL_HINSTANCE), BYVAL %NULL) 'Handle of instance, creation parameters
                                             SendMessage(hEdit, %WM_SETFONT, GetStockObject(%DEFAULT_GUI_FONT), %TRUE)
                                             PostMessage(hEdit, %EM_SETSEL, -2, -2)
                                        
                                           CASE %WM_COMMAND
                                             SELECT CASE LOWRD(wParam)
                                               CASE %IDCANCEL
                                                 SendMessage(hWnd, %WM_CLOSE, 0, 0)
                                             END SELECT
                                        
                                           CASE %WM_SETFOCUS
                                             'Set the keyboard focus to the first control that is
                                             'visible, not disabled, and has the WS_TABSTOP style
                                             SetFocus(GetNextDlgTabItem(hWnd, %NULL, %FALSE))
                                        
                                           CASE %WM_APP 'SHChangeNotifyRegister SHCNE_DISKEVENTS notification
                                             'wParam is a pointer to two PIDLIST_ABSOLUTE pointers that can be NULL, depending on the event
                                             'lParam is the event
                                        
                                             DIM p(0 TO 1) AS ITEMIDLIST POINTER AT wParam
                                             FOR index = 0 TO 1                                    'Check both ITEMIDLIST POINTER
                                               IF p(index) THEN                                    'Some valid info to get
                                                 SHGetPathFromIDList(BYVAL p(index), zPath(index)) 'Get string
                                                 CoTaskMemFree(BYVAL p(index))                     'Free memory
                                               ELSE
                                                 zPath(index) = "Nil"                              'Nothing
                                               END IF
                                             NEXT
                                        
                                             SELECT CASE lParam
                                               CASE %SHCNE_MEDIAINSERTED : sMessage = "SHCNE_MEDIAINSERTED - Media inserted: Drive letter is " & zPath(0)
                                               CASE %SHCNE_MEDIAREMOVED  : sMessage = "SHCNE_MEDIAREMOVED - Media removed: Drive letter is "   & zPath(0)
                                               CASE %SHCNE_DRIVEREMOVED  : sMessage = "SHCNE_DRIVEREMOVED - Drive removed: Drive letter is "   & zPath(0)
                                               CASE %SHCNE_DRIVEADD      : sMessage = "SHCNE_DRIVEADD - Drive added: Drive letter is "         & zPath(0)
                                        
                                               CASE %SHCNE_RENAMEITEM    : sMessage = "SHCNE_RENAMEITEM - "   & zPath(0) & " - " & zPath(1)
                                               CASE %SHCNE_CREATE        : sMessage = "SHCNE_CREATE - "       & zPath(0) & " - " & zPath(1)
                                               CASE %SHCNE_DELETE        : sMessage = "SHCNE_DELETE - "       & zPath(0) & " - " & zPath(1)
                                               CASE %SHCNE_MKDIR         : sMessage = "SHCNE_MKDIR - "        & zPath(0) & " - " & zPath(1)
                                               CASE %SHCNE_RMDIR         : sMessage = "SHCNE_RMDIR - "        & zPath(0) & " - " & zPath(1)
                                               CASE %SHCNE_UPDATEITEM    : sMessage = "SHCNE_UPDATEITEM - "   & zPath(0) & " - " & zPath(1)
                                               CASE %SHCNE_RENAMEFOLDER  : sMessage = "SHCNE_RENAMEFOLDER - " & zPath(0) & " - " & zPath(1)
                                             END SELECT
                                             IF LEN(zPath(0)) THEN TextAdd(hEdit, sMessage)
                                        
                                           CASE %WM_SIZE
                                             IF wParam <> %SIZE_MINIMIZED THEN
                                               SetWindowPos(hEdit, 0, 5, 5, LO(WORD, lParam) - 10, HI(WORD, lParam) - 10, %SWP_NOZORDER)
                                             END IF
                                        
                                           CASE %WM_DESTROY
                                             PostQuitMessage(0)
                                             EXIT FUNCTION
                                        
                                         END SELECT
                                        
                                         FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)
                                        
                                        END FUNCTION
                                        '______________________________________________________________________________
                                        
                                        FUNCTION WINMAIN(BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, _
                                                         BYVAL pszCmdLine AS ASCIIZ POINTER, BYVAL nCmdShow AS LONG) AS LONG
                                         LOCAL ChangeInfo     AS SHChangeNotifyEntry
                                         LOCAL ClassInfo      AS WNDCLASSEX
                                         LOCAL tmsg           AS TAGMSG
                                         LOCAL WindowSize     AS SIZEL
                                         LOCAL zClassName     AS ASCIIZ * %MAX_PATH
                                         LOCAL CsidlDesktop   AS GUID
                                         LOCAL hWnd           AS DWORD
                                         LOCAL hIcon          AS DWORD
                                         LOCAL RegistrationId AS DWORD
                                        
                                         zClassName              = "Form1_Class"
                                         hIcon                   = ExtractIcon(hInstance, "PowrPrOf.dll", 1)
                                         ClassInfo.cbSize        = SIZEOF(ClassInfo)                   'Size of WNDCLASSEX structure
                                         ClassInfo.STYLE         = %CS_DBLCLKS                         'Class styles
                                         ClassInfo.lpfnWndProc   = CODEPTR(MainProc)                   'Address of window procedure used by class
                                         ClassInfo.cbClsExtra    = 0                                   'Extra class bytes
                                         ClassInfo.cbWndExtra    = 0                                   'Extra window bytes
                                         ClassInfo.hInstance     = hInstance                           'Instance of the process that is registering the window
                                         ClassInfo.hIcon         = hIcon                               'Handle of class icon
                                         ClassInfo.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW) 'Handle of class cursor
                                         ClassInfo.hbrBackground = %COLOR_BTNFACE + 1                  'Brush used to fill background of window's client area
                                         ClassInfo.lpszMenuName  = %NULL                               'Resource identifier of the class menu
                                         ClassInfo.lpszClassName = VARPTR(zClassName)                  'Class name
                                         ClassInfo.hIconSm       = %NULL                               'Handle of small icon shown in caption/system Taskbar
                                         RegisterClassEx(ClassInfo)
                                        
                                         WindowSize.cx = 600
                                         WindowSize.cy = 250
                                        
                                         hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                    'Extended styles
                                                               "Form1_Class", _                                        'Class name
                                                               $AppName, _                                             'Caption
                                                               %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                  'Window styles
                                                               (GetSystemMetrics(%SM_CXSCREEN) - WindowSize.cx) / 2, _ 'Pos X
                                                               (GetSystemMetrics(%SM_CYSCREEN) - WindowSize.cy) / 2, _ 'Pos Y
                                                               WindowSize.cx, WindowSize.cy, _                         'Width, height
                                                               %NULL, %NULL, _                                         'Handle of owner, menu handle
                                                               hInstance, BYVAL %NULL)                                 'Handle of instance, creation parameters
                                        
                                         'SHGetSpecialFolderLocation(hDlg, %CSIDL_DESKTOP, pshcne.pidl) 'For XP. Monitor all drives
                                         CsidlDesktop = GUID$("{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}") 'FOLDERID_Desktop
                                         SHGetKnownFolderIDList(CsidlDesktop, %KF_FLAG_SIMPLE_IDLIST, 0, ChangeInfo.pidl) 'For Vista+. Monitor all drives
                                         IF ChangeInfo.pidl THEN 'pidl was valid
                                           ChangeInfo.fRecursive = %TRUE 'Do sub-folder
                                           RegistrationId = SHChangeNotifyRegister(_ 'Ask Windows to send us message at %WM_APP for many events.
                                                                                   hWnd, %SHCNRF_SHELLLEVEL, _
                                                                                   %SHCNE_CREATE           OR %SHCNE_DELETE        OR %SHCNE_MKDIR        OR _
                                                                                   %SHCNE_RENAMEFOLDER     OR %SHCNE_RENAMEITEM    OR %SHCNE_RMDIR        OR _
                                                                                   %SHCNE_DISKEVENTS       OR %SHCNE_UPDATEITEM    OR %SHCNE_DRIVEADD     OR _
                                                                                   %SHCNE_DRIVEREMOVED     OR %SHCNE_MEDIAINSERTED OR %SHCNE_MEDIAREMOVED OR _
                                                                                   %SHCNE_SERVERDISCONNECT, _
                                                                                   BYVAL %WM_APP, BYVAL 1, BYVAL VARPTR(ChangeInfo))
                                           IF RegistrationId > 0 THEN  'SHChangeNotifyRegister successful
                                             ShowWindow(hWnd, nCmdShow)
                                             UpdateWindow(hWnd)
                                             WHILE GetMessage(tmsg, BYVAL %NULL, 0, 0) > 0
                                               IF IsDialogMessage(hWnd, tmsg) = 0 THEN
                                                 TranslateMessage(tmsg)
                                                 DispatchMessage(tmsg)
                                               END IF
                                             WEND
                                             FUNCTION = tmsg.wParam
                                             SHChangeNotifyDeregister(RegistrationId) 'De register clean up on exit
                                           ELSE
                                             MessageBox(%HWND_DESKTOP, "SHChangeNotifyRegister error !", $AppName, %MB_OK OR %MB_TOPMOST)
                                           END IF
                                         ELSE
                                           MessageBox(%HWND_DESKTOP, "SHGetKnownFolderIDList error !", $AppName, %MB_OK OR %MB_TOPMOST)
                                         END IF
                                        
                                         DestroyIcon(hIcon)
                                        
                                        END FUNCTION
                                        '______________________________________________________________________________
                                        '
                                        Last edited by Pierre Bellisle; 20 May 2017, 01:48 AM. Reason: Big clean up

                                        Comment

                                        Working...
                                        X