Some days ago, I encountered a message asking me about the monitoring software. Said that a netizen needs such information. Before that I checked related information on the Internet and wrote a simple monitoring program with VC (MFC), but it was not saved. After the system is redone, it will be gone. (Because it was only an experiment at the time, the folder of the MFC project was directly built on the C drive by default). Therefore, it was just a simple response to his You can use the shchangenotifyregister API. Afterwards, I suddenly felt that I should write this as a component. In the future, you do not need to write these things repeatedly. I was prepared to use VC for writing, because a large number of APIs and their declarations are required. However, because I do not use VC to write ActiveX, I have to choose a familiar v B. Windows has more than one method to monitor folders. You can use findfirstchangenotification, combined with waitformultipleobjects, and findnextchangenotification . You can also use this article to introduce de shchangenotifyregister. Of course, I prefer shchangenotifyregister. Shchangenotifyregister is the core of the entire monitoring folder, so before introducing it to Ha, you must first understand its specific content. Shchangenotifyregister declares this statement on msdn. Ulong shchangenotifyregister (hwnd, Int fsources, Long fevents, Uint wmsg, Int centries, Shchangenotifyentry * pfsne ); The first parameter does not need to be described in detail. The old ghost knows that this is a window handle, indicating the form in which the message is sent when the change is captured. The second parameter on msdn seems to have a problem (of course, I may understand it ). The third parameter mentioned in msdn is the same as farting. Therefore, it is excluded that I will discuss ha again on msdn. The second parameter indicates the data format returned to the address location pointed to by wparam in the form processing function. It can be shcnf_idlist (0x0000) // lpitemidlist You can also run shcnf_patha (0x0001) // path name If shcnf_idlist is used, the address to which wparam points is lpitemidlist (Windows namespace ID) If it is shcnf_patha, the address to which wparam points is stored as a path. Of course, the path here is a string like "C:/ABC. But what is namespace. Namespace is a directory management concept introduced in windows. It works the same as the path. Of course you will ask, it works the same way as the path. So what should we do. Use the path. Of course, Microsoft is not a sb. It naturally plays a role in making this thing. Although the path is We are common, but in fact Windows does not use paths to manage tree directories. The usage path is only used to be compatible with DOS. It is easy to understand. The namespace is used to manage the Windows tree directory. Anyone who has used computers knows. It is basically impossible to use a path to access all directories in windows. At least you cannot access the directory like control panel, online home, or recycle bin. But in fact, you can access them. If you cannot access them using a path, what access does it use. Of course, that is the namespace. After talking about this, what is the namespace. It is actually very simple. The namespace is the name space, which is all Directory and file name and a set of constraints (rules. Each directory and file in Windows has a unique name. This name is not as easy to remember and understand as the path. This name is A 32-bit number. Of course, to facilitate the explanation, we also need to use the concept of path. Such as C:/ABC/text/test.txt. The information is. "C:/ABC/text/test.txt" is the full path of "test.txt. Test.txt is the name of the file. Among them, "C:/ABC" is the full path of the folder "ABC" (note that the folder is not the directory here -- folder is the concept of the path system, while the Directory It is the concept in the namespace. Of course, we will often mix them. It doesn't matter, it doesn't affect understanding) ABC is the name of the folder "C:/ABC/text" is the full path of the folder "text", and text is the name of the S folder. Text is a sub-folder of ABC. Test.txt is stored in the text folder. C: It is a drive letter name. The above concepts should be clear. If you do not understand it, you should build a wall. We started to map the HA surface one by one. C: In the namespace, it is represented as feab2346 (of course, this is a hypothesis, which may be something else in reality) Similarly, ABC can also have a namespace that represents ea123456. Continue the corresponding text-> aaaa3dab Test.txt-> 12345678 Therefore, in order to facilitate reading and writing all the information on the HA Surface C:-> feab2346 ABC-> ea123456 Text-> aaaa3dab Test.txt-> 12345678 We can understand the corresponding introduction. In the namespace, if you want to access drive C, you must use feab2346 (this is not correct ). However, to understand this, we will explain it later) What should I do if I want to access C:/ABC? In fact, it is the same. In the path system, a/can be used to separate the representation. Tree structure. It is more convenient in The namespace. Directly add the abc id to the end of C: ID. So C:/the full address of ABC in The namespace is Feab2346 Ea123456 Similarly, C:/ABC/text is Feab2346 Ea123456 Aaaa3dab In other cases, we will not continue to push data. Of course, we must understand that what we have just said is. The namespace and path do not correspond one to one. The namespace can be accessed in a wider range, and it must be clarified. The path is based on the drive letter. The root of the namespace is the desktop. Its structure is like ha. Desktop -- Recycle Bin -- Network neighbors -- Control Panel ......... -- C: ---- ABC ------ Text --------Test.txt ......... -- N: Now we should know why feab2346 is not used to access the full address of drive C. Real full address Hai You should add a desktop before it. Of course, after reading the above instructions, you will have an impulse to beat people. There is no way to do this. The expression of Wo is just like this. However, if you want to continue looking at Ha, you will see it later. The third parameter refers to the event type to be captured. Here we capture all the events of shcn_allevents (0x7fffffff) or shcn_interrupt (0x7fffffff. The fourth message indicates the message to be sent to the form. Of course, this message must be customized. Here we define it as wm_sh1_y = & h401 Although I write this statement here, we recommend that you use the WM _ *** = wm_user + n method. The fifth parameter is an integer and used with the sixth parameter. For better explanation, we will first introduce the sixth parameter. The sixth parameter is a pointer to a struct. First, let's look at its definition. Typedef struct { Lpcitemidlist pidl; Bool frecursive; } Shchangenotifyentry It can be seen from the name that this is an entry structure. It indicates that we want to monitor the directory. His first element is the pidl of the lpcitemidlist type. Do not be scared by such a long name. Actually This is a pointer to the namespace ID we mentioned above. The second element indicates whether to monitor sub-directories. If the value is true, the sub-directories are monitored. Otherwise, it is not monitored. The fifth parameter is described in HA, because the sixth parameter and the fifth parameter are described in detail. In fact, the fifth parameter is the description. The number of arrays in the sixth parameter may be a bit confusing. Isn't the sixth parameter a struct, How does it become an array. Declare ha here. The sixth parameter is a struct. Because from the very beginning The sixth parameter is a pointer to a struct. Of course, this description is not accurate. Here, it should be Pointer to the struct array. Okay. I have already finished talking about several parameters. Of course I can understand a lot of them with my presentation skills. So now we have a comprehensive Description 1: ha. Ulong shchangenotifyregister (hwnd, Int fsources, Long fevents, Uint wmsg, Int centries, Shchangenotifyentry * pfsne ); In fact, this function is used to monitor changes to a directory (File) or a group of directories (Files) indicated by centries and pfsne. When these directories contain events within the event range described by fevents, A wmsg message is placed in the form hwnd In the queue. Now, the core functions have been introduced. Continue to go to ha. ------------------------------------------------------ |