home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /* Folder View - Drag and drop directory viewer */
- /* Public Domain (P) 1993 Benjamin Cooley */
- /* fldrview.cpp - FolderView Main Module */
- /********************************************************************/
-
- // FolderViews is an orphaned project, begun with the best intentions
- // before its poor overworked programmer was sucked up into other
- // more pressing projects. Please give FolderViews a home, and a new
- // life.
-
- // FolderViews is Donationware.. $15 for the program itself, and $10
- // dollars if your are going to use the source in another product.
- // Donationware means payment for use is purely VOLUNTARY, but
- // wouldn't you feel guilty if you finished FolderViews and were
- // making zogs of money via shareware and didn't give the poor
- // original programmer his $25 measly bucks?
-
- // Please feel free to expand upon FolderViews and publish any
- // derivitives as shareware, public domain, or even as an actual
- // product. All I ask is that you actually IMPROVE upon the product,
- // that the new product remains upwards compatible with the old,
- // and that any new product remains as compatible as possible with
- // Windows conventions, control styles, dialog styles, etc. Also,
- // feel free to change the name, but mention me (Ben Cooley), and
- // FolderViews in the about box if you could.
-
- // As this product is not complete, please feel free to finish..
- //
- // o File copying, moving, deleting, etc.
- // o Add lots of PRE-SETUP directory views for commonly used applications.
- // Folderviews tries to find the directory name of the application in
- // its view database before creating a new entry. Predefined views
- // for many popular programs could be put in this database so that when
- // the user installed FolderVies, he wouldn't have to set up all his
- // directories himself. This would probably be the most usefull addition
- // to the basic program.
- // o Add a GOOD default view setup that would display the folders and exe
- // files in a directory, and have the various other groups one might use
- // iconified underneath.
- // o Add an 'Association..' menu item to the File menu that would work
- // like File Managers association menu.
- // o Implementing drag and drop server code.
- // o Adding the ability to drop group, file, or view icons into a Program
- // Manager window
- // o Backup and restore
- // o Drive views available from program manager via a toolbar with drive
- // icons for each disk in system. (Wish I could of added this).
- // o Completion of the 'Desktop' project.
- // o Search
- // o Directory creating, renaming, moving
- // o Help
- // o A ZIP view DLL that allows a view window to be displayed for
- // a zip file.
- // o Interface to 3rd party DLL 'view' drivers so that other up and
- // coming programs can build view drivers for different kinds of
- // compression formats.
- // o Make FolderViews understand that floppy disks are not hard disks
- // o Teach FolderViews Desktop that CD-ROMS aren't Netword Drives
- // o Keep background windows from coming to the top immediately if your
- // going to drag an icon.
- // o Add more OS/2 type Workplace Shell stuff with the right button click
- // thing.
- // o Put the small view of the icon in the close box for the MDI group
- // windows, and possibly even the main view windows.
- // o Make the view intelligently set up the group windows when a directory
- // is first displayed.
-
-
-
- #include "include.h"
- #pragma hdrstop
-
- #include "fldrview.h"
-
- /********************************************************************/
- /* Variables */
- /********************************************************************/
-
- /* FolderView main window */
- PTMainView FolderView;
-
- /* Program global values */
- HINSTANCE hInstance;
- char ProgramName[] = "Folder Views";
- char TextBuf[TEXTBUFLEN];
- char FolderViewFileName[MAXPATH];
- char FolderViewPath[MAXPATH];
- char DefaultFolderInfoDir[] = "FOLDERS\\";
- char FolderInfoPath[MAXPATH];
- char FolderInfoFileName[] = "FLDR0000.FIF";
- char FolderInfoWildcard[] = "FLDR*.FIF";
- int FolderInfoFileCountPos = 4;
- int FolderInfoFileCountLen = 4;
- char DefaultFolderInfoFileName[] = "DEFAULT.FIF";
- char DirFolderInfoFileName[] = "FOLDER.FIF";
- char ProfileSettings[] = "Settings";
- char ProfileDirectories[] = "Folders";
- char ProfileName[] = "FLDRVIEW.INI";
- char FileIconName[] = "[FileIcon]";
- char DirIconName[] = "[DirIcon]";
- char ProgIconName[] = "[ProgIcon]";
- char BatchIconName[] = "[BatchIcon]";
- char PifIconName[] = "[PifIcon]";
- int IconWidth, IconHeight, SmallIconWidth, SmallIconHeight;
- int IconSpaceWidth, IconSpaceHeight;
- int DescWidth, DescHeight, WrapDesc;
- int IconNameWidth, IconNameHeight;
- char FontName[MAXFONTNAME];
- int FontPointSize;
- HFONT Font;
- COLORREF TextColor, TextBkColor, SelectedTextColor, SelectedTextBkColor;
- COLORREF WindowColor;
- HBRUSH WindowBrush, SelectedBrush;
- int IconLeft, IconTop;
- HDC MemDC;
- HBITMAP MemBitMap;
- HFONT MemFont;
- HBRUSH MemBrush;
- int AllNameWidth, AllDateWidth, AllTimeWidth, AllSizeWidth,
- AllAttribWidth, AllDescWidth;
- BOOL ShuttingDown = FALSE; // True when shutting down
- BOOL MouseDown = FALSE;
- PTIcon MouseDownIcon = NULL;
- int MouseDownIconX, MouseDownIconY;
- BOOL Dragging = FALSE;
- HCURSOR DragIconCursor, DragCursor;
-
- /* DIB Bitmap structures */
- static long palette2[] = { 0x000000L, 0xFFFFFFL };
-
- static long palette16[] =
- { 0x000000L, 0x800000L, 0x008000L, 0x808000L,
- 0x000080L, 0x800080L, 0x008080L, 0xC0C0C0L,
- 0x808080L, 0xFF0000L, 0x00FF00L, 0xFFFF00L,
- 0x0000FFL, 0xFF00FFL, 0x00FFFFL, 0xFFFFFFL };
-
- static char bmid2[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2];
- BITMAPINFO *bmi2 = (BITMAPINFO *)bmid2;
- BITMAPINFOHEADER *bmih2 = (BITMAPINFOHEADER *)bmid2;
- static char bmid16[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 16];
- BITMAPINFO *bmi16 = (BITMAPINFO *)bmid16;
- BITMAPINFOHEADER *bmih16 = (BITMAPINFOHEADER *)bmid16;
-
- /* Icon List */
- TIconList IconList;
-
- /********************************************************************/
- /* TMainApp Application Class */
- /********************************************************************/
-
- _CLASSDEF(TMainApp)
- class TMainApp : public TApplication
- {
- public:
- TMainApp(LPSTR AName, HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow);
- virtual ~TMainApp();
- virtual void InitMainWindow();
- virtual void InitInstance();
- };
-
- TMainApp::TMainApp(LPSTR AName, HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow):
- TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow)
- {
- char buf[10];
-
- /* Set Global Instance */
- ::hInstance = hInstance;
-
- /* Get Folderview Path */
- GetModuleFileName(hInstance, FolderViewFileName, MAXPATH);
- strcpy(FolderViewPath, FolderViewFileName);
- Pchar ptr = FolderViewPath + strlen(FolderViewPath);
- while (ptr > FolderViewPath && *ptr != '\\')
- *(ptr--) = NULL;
-
- /* Get global mememory dc */
- HDC dc = GetDC(NULL);
- MemDC = CreateCompatibleDC(dc);
- ReleaseDC(NULL, dc);
-
- /* Icon width and height */
- IconWidth = GetSystemMetrics(SM_CXICON);
- IconHeight = GetSystemMetrics(SM_CYICON);
-
- /* FolderInfoPathEntry entry */
- char FolderInfoPathEntry[] = "FolderInfoPath";
- GetPrivateProfileString(
- ProfileSettings, FolderInfoPathEntry, "",
- FolderInfoPath, MAXPATH, ProfileName);
- if (!*FolderInfoPath)
- {
- strcpy(FolderInfoPath, FolderViewPath);
- strcat(FolderInfoPath, DefaultFolderInfoDir);
- WritePrivateProfileString(
- ProfileSettings, FolderInfoPathEntry, "", ProfileName);
- // Note: 'FolderInfoPath=' empty means uses program directory
- }
- else if (*(FolderInfoPath + strlen(FolderInfoPath) - 1) != '\\')
- {
- strcat(FolderInfoPath, "\\"); // Make sure path hase '\' at end
- WritePrivateProfileString(
- ProfileSettings, FolderInfoPathEntry, FolderInfoPath, ProfileName);
- }
-
- /* IconSpacingWidth entry */
- char IconSpaceWidthEntry[] = "IconSpacingWidth";
- IconSpaceWidth = GetPrivateProfileInt(
- ProfileSettings, IconSpaceWidthEntry, 0, ProfileName);
- if (IconSpaceWidth == 0)
- {
- IconSpaceWidth = GetSystemMetrics(SM_CXICONSPACING);
- WritePrivateProfileString(
- ProfileSettings, IconSpaceWidthEntry,
- itoa(IconSpaceWidth, buf, 10), ProfileName);
- }
-
- /* IconSpacingHeight entry */
- char IconSpaceHeightEntry[] = "IconSpacingHeight";
- IconSpaceHeight = GetPrivateProfileInt(
- ProfileSettings, IconSpaceHeightEntry, 0, ProfileName);
- if (IconSpaceHeight == 0)
- {
- IconSpaceHeight = GetSystemMetrics(SM_CYICONSPACING);
- WritePrivateProfileString(
- ProfileSettings, IconSpaceHeightEntry,
- itoa(IconSpaceHeight, buf, 10), ProfileName);
- }
-
- /* FontName entry */
- char FontNameEntry[] = "FontName";
- GetPrivateProfileString(
- ProfileSettings, FontNameEntry, "",
- FontName, MAXFONTNAME, ProfileName);
- if (!*FontName)
- {
- strcpy(FontName, "Helv");
- WritePrivateProfileString(
- ProfileSettings, FontNameEntry, FontName, ProfileName);
- }
-
- /* FontPointSize entry */
- char FontPointSizeEntry[] = "FontPointSize";
- FontPointSize = GetPrivateProfileInt(
- ProfileSettings, FontPointSizeEntry, 0, ProfileName);
- if (FontPointSize == 0)
- {
- FontPointSize = 8;
- WritePrivateProfileString(
- ProfileSettings, FontPointSizeEntry, "8", ProfileName);
- }
-
- /* Initialize global resources */
- Font = CreateFont(FontPointSize,0,0,0,0,0,0,0,0,0,0,0,0,FontName);
- TextColor = GetSysColor(COLOR_WINDOWTEXT);
- TextBkColor = GetSysColor(COLOR_WINDOW);
- SelectedTextColor = GetSysColor(COLOR_HIGHLIGHTTEXT);
- SelectedTextBkColor = GetSysColor(COLOR_HIGHLIGHT);
- WindowColor = TextBkColor;
- WindowBrush = CreateSolidBrush(WindowColor);
- SelectedBrush = CreateSolidBrush(SelectedTextBkColor);
- IconLeft = (IconSpaceWidth - IconWidth) / 2;
- if (IconLeft < 0) IconLeft = 0;
- IconTop = (IconSpaceHeight - IconHeight - (FontPointSize + 4)) / 2;
- if (IconTop < 0) IconTop = 0;
- SmallIconWidth = 16;
- SmallIconHeight = 16;
- IconNameWidth = FontPointSize * 11 + SmallIconWidth;
- IconNameHeight = FontPointSize + 4;
- if (IconNameHeight < SmallIconHeight + 2)
- IconNameHeight = SmallIconHeight + 2;
- AllNameWidth = FontPointSize * 8;
- AllDateWidth = FontPointSize * 7;
- AllTimeWidth = FontPointSize * 6;
- AllSizeWidth = FontPointSize * 8;
- AllAttribWidth = FontPointSize * 5;
- AllDescWidth = FontPointSize * 50;
-
- /* Initialize DIB stuff */
- bmih2->biSize = sizeof(BITMAPINFOHEADER);
- bmih2->biPlanes = 1;
- bmih2->biBitCount = 1;
- bmih2->biCompression = BI_RGB;
- memcpy(bmi2->bmiColors, palette2, 4 * 2);
- bmih16->biSize = sizeof(BITMAPINFOHEADER);
- bmih16->biPlanes = 1;
- bmih16->biBitCount = 4;
- bmih16->biCompression = BI_RGB;
- memcpy(bmi16->bmiColors, palette16, 4 * 16);
-
- /* Get Icons */
- IconList.AddIconImage(new TIconImage(FileIconName, 0,
- LoadIcon(hInstance, MAKEINTRESOURCE(ICO_File)) ));
- IconList.AddIconImage(new TIconImage(DirIconName, 0,
- LoadIcon(hInstance, MAKEINTRESOURCE(ICO_Directory)) ));
- IconList.AddIconImage(new TIconImage(BatchIconName, 0,
- LoadIcon(hInstance, MAKEINTRESOURCE(ICO_Batch)) ));
- IconList.AddIconImage(new TIconImage(PifIconName, 0,
- LoadIcon(hInstance, MAKEINTRESOURCE(ICO_Pif)) ));
- IconList.AddIconImage(new TIconImage(ProgIconName, 0,
- LoadIcon(hInstance, MAKEINTRESOURCE(ICO_Program)) ));
-
- }
-
- TMainApp::~TMainApp()
- {
-
- /* Delete global dc */
- DeleteDC(MemDC);
-
- /* Free global resources */
- if (Font) DeleteObject(Font);
- if (WindowBrush) DeleteObject(WindowBrush);
- if (SelectedBrush) DeleteObject(SelectedBrush);
-
- }
-
- void TMainApp::InitMainWindow()
- {
- char filepath[MAXPATH];
- char filename[FILELEN];
- BOOL fileexists = FALSE;
- unsigned dummy;
-
- BOOL wildcard =
- lpCmdLine[strlen(lpCmdLine) - 1] != '\\';
-
- /* Look for full path in [Directories] section */
- GetPrivateProfileString(ProfileDirectories, lpCmdLine,
- "", filename, FILELEN, ProfileName);
- if (*filename)
- {
- strcpy(filepath, FolderInfoPath);
- strcat(filepath, filename);
- }
-
- /* If full path not there, try just the directory name */
- if (!*filename)
- {
- GetPrivateProfileString(ProfileDirectories, lpCmdLine + 3,
- "", filename, FILELEN, ProfileName);
- if (*filename)
- {
- strcpy(filepath, FolderViewPath);
- strcat(filepath, filename);
- }
- }
-
- /* See if setup in FOLDERS directory exists */
- if (*filename)
- if (!_dos_getfileattr(filepath, &dummy))
- fileexists = TRUE;
-
- /* If no user setup in FOLDERS directory, try current directory */
- if (!fileexists && !wildcard) // Don't bother if wildcard view
- {
- strcpy(filepath, lpCmdLine);
- strcat(filepath, DirFolderInfoFileName);
- if (!_dos_getfileattr(filepath, &dummy))
- fileexists = TRUE;
- }
-
- /* If neither user, or directory setup exists, use default setup file */
- if (!fileexists && !wildcard)
- {
- strcpy(filepath, FolderViewPath);
- strcat(filepath, DefaultFolderInfoFileName);
- if (!_dos_getfileattr(filename, &dummy))
- fileexists = TRUE;
- }
-
- /* If we have a file, try to load setup from it */
- if (fileexists)
- {
- ifpstream is(filepath);
- if (!is.fail())
- {
- Pchar buf = new char[FILEBUFSIZE];
- is.setbuf(buf, FILEBUFSIZE);
- is >> FolderView;
- is.close();
- delete buf;
- }
- else fileexists = FALSE; // Drop down to no setup file below
- }
-
- /* If no setup file, start from scratch */
- if (!fileexists)
- {
- FolderView = new TMainView(lpCmdLine);
- }
-
- MainWindow = FolderView;
- }
-
- void TMainApp::InitInstance()
- {
- TApplication::InitInstance();
-
- /* Load accelerators */
- HAccTable = LoadAccelerators(hInstance,
- MAKEINTRESOURCE(ACC_Accelerator));
- }
-
- /********************************************************************/
- /* Main Program */
- /********************************************************************/
-
- char dirbuf[MAXDIR];
-
- int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
-
- Pchar dir;
- if (!lpCmdLine || !*lpCmdLine)
- {
- strcpy(dirbuf, "?:\\");
- dirbuf[0] = _getdrive() + 'A' - 1;
- getcurdir(0, dirbuf + 3);
- strcat(dirbuf, "\\");
- dir = dirbuf;
- }
- else dir = lpCmdLine;
- strupr(dir);
-
- TMainApp MainApp("FolderView", hInstance, hPrevInstance,
- dir, nCmdShow);
- MainApp.Run();
- return MainApp.Status;
- }
-