Session #9
During the first part of the session I showed a very simple demo on how to capture all message sent to the window and how to capture events when idle.
![]()
- WinProcMain.h - The definition of the main form.
- WinProcMain.cpp - The implementation.
- Project .zip file - Project files to build it yourself.
During the second part of the session, I showed some code that demonstrated how to search the file system for files. For example, you can find all of the .cpp files on the D: drive. The purpose of this was to set up for the next version which is going to be a multi-threaded file find program. This will allow you to search all of your drives simultaneously. Look at the code to get familiar with the algorithm. Since the directory structure in Windows uses a tree structure, it lends itself to a simple recursive algorithm. The tree isn't a binary tree, since a directory can have 0, 1, or N subdirectories (children). The algorithm isn't any more complicated than if there were just two subdirectories. The application itself is very simple because it's only meant to show the recursive search algorithm. When I extend it with multiple threads, the application will be more useful.
If you've never "searched" a file system below, you should check out the help for the functions: FindFirst, FindNext, and FindClose. You should be able to figure out how they work from the example code and the online help. These functions are wrappers around _findfirst, _findnext, and _findclose. (Some compilers will accept these latter functions with or without the leading underscores.) Some information on these functions.
|
|
During the third part of the session, I showed another way of traversing subdirectories in the Windows file system. This time, I made a multi-threaded application that allowed the application to search in multiple folders simultaneously. There is a lot of good information in this simple application. For details on working with the TThread class, look at Chapter 11 Writing multi-threaded applications in the Developer's Guide.
I also demonstrated how to launch files from within the application. By double-clicking on an item in the list view, that file will "launch". If it's an executable, it will run, it if it's a text file, it will be opened by the associated text editor, if it's an HTML file, it will be loaded by the default browser, etc. You can choose how to "launch" the file based on the radio buttons.
Finally, I showed how to use the clipboard to put files on it and then paste (copy) them to another folder in Windows. This is how it works when you copy and paste files in Explorer.
|
|
Exercises