This program is based on a program called IconOutliner written by Jeroen-bart Engelen in December 2001 but there were a few problems with his implementation.
Icon Outliner available for download from:
http://codeguru.earthweb.com/net_general/IconOutliner.html
1. It was compiled with Microsoft Visual C++ 7 (Visual Studio .NET),
I did not have MFC70.DLL so I could not run the program!
I have Visual Studio 6 and just wanted a simple console app that would do the job.
2. It used the MFC,
Mainly for a nice user interface and occasional CString, but the core didn't need it.
3. It only worked on Windows XP,
4. It stored the icon positions in the registry.
5. To compile the code psapi.h and psapi.lib were required from the Microsoft Windows
Platform SDK. I did not have these files.
The code used a Windows NT and higher specific function called VirtualAllocEx() to allocate memory for the icon position retrieved by sending the desktop list control an LVM_GETITEMPOSITION message. This is great, and the memory can be read with ReadProcessMemory. This method isn't possible on Windows 9x because the memory organisation is different.
I still use Windows 98 mainly at home. I have XP but use it occasionally. I use Windows 2000 and NT4.0 at work. I decided that I wanted to make my version of this program work on all of these operating systems.
The outcome of about 5 hours work at home includes 2 versions of these programs:
NT2000XP
restoredesktop.exe
savedesktop.exe
9598ME
restoredesktop.exe
savedesktop.exe
General features are:
1. Simple C++ implementation with no dependencies on MFC,
I use psapi.lib, I found that it is available from the Microsoft Website.
2. The Windows NT\2000\XP version uses the virtual memory in the explorer process technique,
3. The Windows 95\98\ME version uses shared memory,
4. All executables require 1 argument - an input or output file name,
5. Operating system version detected in each executable to prevent the 95\98\ME version running on
NT\2000\XP etc.
6. The shared memory file is written to a temporary location on 95\98\ME and deleted on exit,
7. The file that stores the icon positions are in the following newline separated format:
icon count
{for each icon}
x position
y position
name
I store the name of each icon in the saved desktop file because I guess that the icon's index
may change when the operating system reboots.
This occurs when Windows 98 boots in Safe Mode, when rebooted again normally the icons are sorted
alphabetically.
I think that Jeroen-bart uses the list view item index, but he doesn't really explain why
he can rely on the index being the same when the desktop is shuffled about or if the operating
system is rebooted.
1.Problem: "Auto Arrange" can mess up the positions during restore.
Solution: Switch off "Auto Arrange" during a restore.
Reason: By default Windows explorer has Auto Arrange enabled. When the icons are being repositioned Auto Arrange could mess up the positions as they are being restored if the listview receives WM_PAINT messages.
For this reason restoredesktop.exe sorts the icon positions from right to left and bottom up in subranges of an array. I thought that positioning each icon in reverse order at (0,0) would force auto-arrange to shuffle the icons down the screen when new ones were added but it did not cure the problem. Simply using the original absolute positions works. This code is strictly speaking probably no longer necessary, but it is an interesting use of qsort().
Example (Windows 98):
2. Run the command restoredesktop.exe mydesktop.txt in the MS-DOS prompt,
3. Position the mouse over the desktop, press right mouse button and switch ON auto-arrange.
Example (Windows 98):
Example:
The source code and binaries for ALL 5 programs (95\98\ME save\restore NT\2000\XP save\restore and desktoprestore.exe) are available for a fee.
I have not seen this kind of program available elsewhere and it may be useful for educational programming purposes. The source code compiles with Microsoft Visual Studio 6. It has been designed exclusively for Microsoft Windows. Please email me for further details.
Back to index.