Category : Windows 3.X Files
Archive   : DIRMGR.ZIP
Filename : DIRM.C

 
Output of file : DIRM.C contained in archive : DIRMGR.ZIP
#include
#include
#include
#include
#include
#include
#include "dirm.h"
#include "rdir.h"

#define ID_SCROLLBAR 500

long FAR PASCAL WndProc(HWND,WORD,WORD,LONG);

long FAR PASCAL WndProcFile(HWND,WORD,WORD,LONG); /* In DirmFile.c */
long FAR PASCAL WndProcButton(HWND,WORD,WORD,LONG); /* In DirmButt.c */
void PrintDirStr(HDC hdc,int x, int y,LPSTR str); /* In DirmMisc.c */
void PaintDirRect(HDC hdc,WORD top,WORD bottom); /* In DirmMisc.c */
BOOL LoadNewDriveInfo(HWND hwnd,int Drive); /* In DirmMisc.c */
WORD GetLongestDirStr(HDC hdc); /* In DirmMisc.c */
HANDLE readalldir(HWND,char *); /* In RDir.c */
BOOL DirmCreateMsg(HWND hwnd,HANDLE hInst,LPRECT DirRect,LPRECT FileRect,
WORD *x1,WORD *y1,WORD *x2,WORD *y2); /* In DmCreate.c */
BOOL FAR PASCAL ViewListDlgProc(HWND,WORD,WORD,LONG);
BOOL FAR PASCAL AboutDlgProc(HWND,WORD,WORD,LONG);
void GetStats(WORD *numhi,LONG *total);
char *CreatePathname(HANDLE hDirTab,HANDLE hTreeTab,int dirnum);
BOOL FAR PASCAL GetStringDlgProc(HWND,WORD,WORD,LONG);


extern WORD TotalDirs; /* Total Directories in Table minus 1 */
extern WORD LongestStr; /* Length of longest str in Table */
extern char DriveList[28]; /* List of valid drives */
extern char NumberDrives; /* number of drives in list */
extern int FileHilite[512]; /* files that are hilited */
extern HFONT hFont; /* Fixed font used for entire program */
extern HWND hwndFuncWins[5];
extern HMENU hMenu, hMenuSort, hMenuFile;
extern WORD TotalFiles; /* Total number of files */
extern char szStartStr[130]; /* String to set as edit string */
extern char szDest[130]; /* Destination String for GetString */
extern char szDlgCaption[50]; /* Caption for GetStringDlg Dialog box */
extern char szDlgPrompt[80]; /* Prompt to display left of the dialogs */
extern char blank[80];
extern int blanklen;

char szAppName[] = "DirManager";
char szCaption[] = "Dir Manager";
char szFileWin[] = "DirmFileWindow";
char szButtonWin[] = "DirmButtonWindow";
char szViewListWin[] = "DirmViewList";
HWND hwndsb; /* scroll bar handle */
HWND hwndFile; /* File window handle */
HWND hwndStat; /* Stat's window handle */
HANDLE hInst; /* Instance of program */
int yOrg = 0; /* Y origin */
int CurDir = 0; /* Current directory in table */
int HiDir = 0; /* Current hilited directory */
int OldHiDir = -1; /* Old Hilited Directory */
int MaxRightPos; /* Furthest position used to the right */
DIR_ELE DirTab = NULL; /* Pointer for Directory Array */
TREEITEM TreeStrTab = NULL; /* Pointer for Dir ASCII tree listing */
FEPTR ftab = NULL; /* Pointer for array of files */
short cxChar, cyChar; /* Width, and height of a char */
HANDLE hDirTab = NULL; /* handle for the directory array */
HANDLE hTreeTab = NULL; /* handle for dir ASCII tree listing */
HANDLE hFileTab = NULL; /* handle to array of files in CWD */
WORD OldFileDir = 0xFFFF;
BOOL TabError = TRUE; /* Table Error flag */
int Drive = 0; /* Current Drive */
int SpaceExtent = 1; /* Width of a space on screen */
int SortType = IDM_SORTNONE; /* Current sorting method */
int OldSortType; /* Sorting method at start up */
WNDCLASS wndclass;
WNDCLASS wndclassfile;
WNDCLASS wndclassbutton;
HBITMAP hBitmap[28] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
char AscendingFlag = 1; // 1 if ascending order, else -1
char OldAscendingFlag; // 1 if ascending order, else -1
BOOL SortChanged = FALSE;
DWORD SysTextColor, SysBkColor;
short cxCharStat,cyCharStat;
HPEN hHiPen = NULL; /* Pen used to hilite directories */

int PASCAL WinMain(hInst,hPreInst,lpszCmdLine,nCmdShow)
HANDLE hInst,hPreInst;
LPSTR lpszCmdLine;
int nCmdShow;
{
HANDLE hAccel;
HWND hwnd;
MSG msg;

SysTextColor = GetSysColor(COLOR_WINDOWTEXT);
SysBkColor = GetSysColor(COLOR_WINDOW);

if(!hPreInst)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW; /* Main Window Class */
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon(hInst,"DirmIcon");
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = COLOR_WINDOW+1;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass (&wndclass))
return FALSE;
/* File Window Class */
wndclassfile.style = CS_NOCLOSE | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wndclassfile.lpfnWndProc = WndProcFile;
wndclassfile.cbClsExtra = 0;
wndclassfile.cbWndExtra = 0;
wndclassfile.hInstance = hInst;
wndclassfile.hIcon = NULL;
wndclassfile.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclassfile.hbrBackground = COLOR_WINDOW+1;
wndclassfile.lpszMenuName = NULL;
wndclassfile.lpszClassName = szFileWin;
if (!RegisterClass (&wndclassfile))
return FALSE;
/* Owner Draw Button Class */
wndclassbutton.style = NULL;
wndclassbutton.lpfnWndProc = WndProcButton;
wndclassbutton.cbClsExtra = 0;
wndclassbutton.cbWndExtra = 2 * 7;
wndclassbutton.hInstance = hInst;
wndclassbutton.hIcon = NULL;
wndclassbutton.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclassbutton.hbrBackground = COLOR_WINDOW+1;
wndclassbutton.lpszMenuName = NULL;
wndclassbutton.lpszClassName = szButtonWin;
if (!RegisterClass (&wndclassbutton))
return FALSE;
}

hwnd = CreateWindow(szAppName,"Dir Manager",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
CW_USEDEFAULT,CW_USEDEFAULT,
GetSystemMetrics(SM_CXCURSOR) * 17,
15 * GetSystemMetrics(SM_CYMENU),
NULL,NULL,hInst,NULL);

hwndStat = CreateWindow("static",NULL,
WS_CHILD | WS_VISIBLE | SBS_VERT | WS_BORDER,
0,0,0,0,hwnd,ID_SCROLLBAR,hInst,NULL);

hwndFile = CreateWindow(szFileWin,NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE |
WS_VSCROLL | WS_HSCROLL | WS_BORDER,
0,0,0,0,hwnd,NULL,hInst,NULL);

/* Directory window scroll bar */
hwndsb = CreateWindow("scrollbar",NULL,
WS_CHILD | WS_VISIBLE | SBS_VERT | WS_CLIPCHILDREN,
0,0,0,0,hwnd,ID_SCROLLBAR,hInst,NULL);

/* Static text window */
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);

hAccel = LoadAccelerators(hInst,"DirMan");

while (GetMessage(&msg,NULL,NULL,NULL))
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wParam);
}


long FAR PASCAL WndProc(hwnd,messg,wParam,lParam)
HWND hwnd;
unsigned messg;
WORD wParam;
LONG lParam;
{
static RECT rect, DirRect, FileRect, HiDirRect;
static WORD x1, y1, x2, y2;
static int PageInc = 0; /* PageUp, PageDown Inc */
static int MaxScroll = 0; /* Max Scroll position */
static int OldScrollPos = 0; /* Current Scroll Position */
static int ScrollWidth; /* Width of Dir Window scroll bar */
static BOOL GotFirstPaintMsg = FALSE;
static BOOL GotFocus = TRUE, HiliteRectOn = FALSE;
int i, j, neworg;
int sx, sy, k;
HDC hdc;
HMENU hMenu;
PAINTSTRUCT ps;
TEXTMETRIC tm;

switch(messg)
{
case WM_CREATE:
{
ScrollWidth = GetSystemMetrics(SM_CXVSCROLL);
hInst = ((LPCREATESTRUCT) lParam) -> hInstance;
TabError = DirmCreateMsg(hwnd,hInst,&DirRect,&FileRect,&x1,&y1,&x2,&y2);
if(TabError) { /* if error, end program */
SendMessage(hwnd,WM_CLOSE,0,0L);
return 0;
}
OldSortType = SortType; /* Save first sort type */
OldAscendingFlag = AscendingFlag;
}
return 0;

case WM_SIZE: /* Don't process WM_SIZE until */
{ /* first paint message. No, harm */
if(!GotFirstPaintMsg) /* but causes a lot of flicker */
return 0; /* because of window resizing */
GetClientRect(hwnd,&rect);
sx = ScrollWidth*3/4; /* Get dimensions of dir */
sy = GetSystemMetrics(SM_CYVSCROLL); /* window scroll bar */

DirRect.bottom = rect.bottom;
k = 2 * cyCharStat + cyChar + GetSystemMetrics(SM_CYICON);

if(rect.bottom > k) /* Ensure a min of about 4 */
FileRect.bottom = rect.bottom - k; /* lines for file window */
else
FileRect.bottom = FileRect.top + 4 * cyChar;

FileRect.right = rect.right - 2;
if((FileRect.right - FileRect.left) < (8 * cxChar))
FileRect.right = FileRect.left + 8 * cxChar + ScrollWidth;
if(FileRect.right > MaxRightPos-1+ScrollWidth+FileRect.left)
FileRect.right = MaxRightPos-1+ScrollWidth+FileRect.left;

if(x2 < rect.right && rect.bottom > sy && rect.bottom < y2)
{
MaxScroll = y2 - rect.bottom; /* Not enough room */
MaxScroll = (MaxScroll+cyChar-1)/cyChar; /* dir window, so */
MaxScroll = max(0,MaxScroll); /* scroll bar */
PageInc = (rect.bottom-cyChar+1)/cyChar - 1;
OldScrollPos = min(MaxScroll,OldScrollPos);
MoveWindow(hwndsb,x2,y1,sx,rect.bottom,TRUE);
SetScrollRange(hwndsb,SB_CTL,0,MaxScroll,FALSE);
SetScrollPos(hwndsb,SB_CTL,OldScrollPos,TRUE);
}
else
{
OldScrollPos = 0; /* Can fit the entire dir window */
MaxScroll = 0; /* on one screen */
PageInc = 0;
MoveWindow(hwndsb,x2,y1,sx,rect.bottom,TRUE);
SetScrollRange(hwndsb,SB_CTL,0,0,FALSE);
SetScrollPos(hwndsb,SB_CTL,0,TRUE);
}
OldScrollPos = min(MaxScroll,OldScrollPos);
yOrg = OldScrollPos * cyChar;

sy = FileRect.bottom + 2 * cyCharStat;
sx = FileRect.left;
for(i = 0; i < NUMBUTTONS; i++) // Draw the Five Function Icons
{
MoveWindow(hwndFuncWins[i],sx,sy,BUTTONSIZE,BUTTONSIZE,FALSE);
sx += BUTTONSPACING + 32;
InvalidateRect(hwndFuncWins[i],NULL,FALSE);
}
/* Set file window positon and size */
MoveWindow(hwndFile,FileRect.left,FileRect.top,
FileRect.right-FileRect.left-1,
FileRect.bottom-FileRect.top-1,TRUE);
/* Set Static text window */
MoveWindow(hwndStat,FileRect.left,FileRect.bottom + cyCharStat /2,
FileRect.right-FileRect.left-1,cyCharStat+2,TRUE);

HiDirRect.left = DirRect.left; /* Set Width of the Cursor */
HiDirRect.right = DirRect.right - 2; /* for the keyboard */
InvalidateRect(hwnd,NULL,TRUE); /* Redraw */
}
return 0;

case WM_COMMAND:
switch (wParam)
{
int newdrive;

case IDM_SORTNONE:
case IDM_SORTNAME: /* User selected a sort from the menu */
case IDM_SORTDATE:
case IDM_SORTEXT:
case IDM_SORTSIZE:
if(SortType != wParam)
{
SortChanged = TRUE;
hMenu = GetMenu(hwnd);
CheckMenuItem(hMenu,IDM_SORTNONE,MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_SORTNAME,MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_SORTDATE,MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_SORTEXT,MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_SORTSIZE,MF_UNCHECKED);
CheckMenuItem(hMenu,wParam,MF_CHECKED);
SortType = wParam;
SendMessage(hwndFile,WM_COMMAND,ID_RESORT,0L);
InvalidateRect(hwndFile,NULL,FALSE);
}
return 0;

case IDM_ASCENDING:
if(AscendingFlag != 1)
{
SortChanged = TRUE;
hMenu = GetMenu(hwnd);
CheckMenuItem(hMenu,IDM_ASCENDING,MF_CHECKED);
CheckMenuItem(hMenu,IDM_DESCENDING,MF_UNCHECKED);
AscendingFlag = 1;
SendMessage(hwndFile,WM_COMMAND,ID_RESORT,0L);
InvalidateRect(hwndFile,NULL,FALSE);
}
return 0;

case IDM_DESCENDING:
if(AscendingFlag != -1)
{
SortChanged = TRUE;
hMenu = GetMenu(hwnd);
CheckMenuItem(hMenu,IDM_ASCENDING,MF_UNCHECKED);
CheckMenuItem(hMenu,IDM_DESCENDING,MF_CHECKED);
AscendingFlag = -1;
SendMessage(hwndFile,WM_COMMAND,ID_RESORT,0L);
InvalidateRect(hwndFile,NULL,FALSE);
}
return 0;

case IDM_COPY:
PostMessage(hwndFile,WM_COMMAND,IDM_COPY,0L);
return 0;
case IDM_MOVE:
PostMessage(hwndFile,WM_COMMAND,IDM_MOVE,0L);
return 0;
case IDM_DELETE:
PostMessage(hwndFile,WM_COMMAND,IDM_DELETE,0L);
return 0;
case IDM_RENAME:
PostMessage(hwndFile,WM_COMMAND,IDM_RENAME,0L);
return 0;
case IDM_ATTRIB:
PostMessage(hwndFile,WM_COMMAND,IDM_ATTRIB,0L);
return 0;

case ID_DISPSTRING:
SetWindowText(hwndStat,(LPSTR) lParam);
return 0;

case IDM_MARKALL:
memset(FileHilite,0xFFFF,512); /* Set All mark bits */
PostMessage(hwnd,WM_COMMAND,ID_STAT,0L);
InvalidateRect(hwndFile,NULL,TRUE); /* Redraw File Rect */
return 0;
case IDM_UNMARKALL:
memset(FileHilite,0,512); /* Clear All mark bits */
PostMessage(hwnd,WM_COMMAND,ID_STAT,0L);
InvalidateRect(hwndFile,NULL,TRUE); /* Redraw File Rect */
return 0;

case ID_VIEWLIST: /* View Results from last file op */
{
BOOL rc;
FARPROC lpDlgProc;

lpDlgProc = MakeProcInstance(ViewListDlgProc, hInst);
rc = DialogBox(hInst,"ViewListDlg", hwnd, lpDlgProc);
FreeProcInstance(lpDlgProc);
return 0;
}

case ID_STAT: /* Update the static text Stat's window */
{
WORD hi;
DWORD totbytes;
char szBuff[256];

GetStats(&hi,&totbytes);
sprintf(szBuff,"%lu byte(s) selected in %u file(s) out of %u file(s) total",
totbytes,hi,TotalFiles);
SetWindowText(hwndStat,(LPSTR) &szBuff[0]);
return 0;
}

case IDM_MKDIR: /* Make Directory */
{
char *path;
FARPROC lpDlgProc;
char szBuff[256];
BOOL rc;

path = CreatePathname(hDirTab,hTreeTab,CurDir);
strcpy(szDlgCaption,"Make Directory");
strcpy(szDlgPrompt,"Name of New Directory: ");
strcpy(szStartStr,path);
lpDlgProc = MakeProcInstance(GetStringDlgProc, hInst);
rc = DialogBox(hInst,"GetStringDlg", hwnd, lpDlgProc);
FreeProcInstance(lpDlgProc);
strcpy(szStartStr,"");
if(rc == FALSE)
return 0;
if(strlen(szDest) > 66 || strlen(path) > 67) {
MessageBox(hwnd,"Directory name is too large",szCaption,
MB_ICONINFORMATION | MB_OKCANCEL);
return 0;
}
if(mkdir(szDest) != 0) {
sprintf(szBuff,"Error making %s - %s",szDest,strerror(errno));
i = MessageBox(hwnd,szBuff,szCaption,
MB_ICONINFORMATION | MB_OKCANCEL);
}
else
SendMessage(hwnd,WM_COMMAND,IDM_REREADDISK,0L);
return 0;
}

case IDM_RMDIR: /* Remove Directory */
{
char *path;
char szBuff[256];

path = CreatePathname(hDirTab,hTreeTab,CurDir);
i = strlen(path);
*(path + i - 1) = '\0';
if(strlen(path) > 3) {
sprintf(szBuff,"Remove %s ?",path);
i = MessageBox(hwnd,szBuff,szCaption,MB_ICONQUESTION | MB_OKCANCEL);
if(i == IDOK) {
char szTmp[128];

strcpy(szTmp,path);
szTmp[3] = '\0';
chdir(szTmp);
if(rmdir(path) != 0) {
sprintf(szBuff,"Error removing %s - %s",path,strerror(errno));
i = MessageBox(hwnd,szBuff,szCaption,
MB_ICONINFORMATION | MB_OKCANCEL);
}
else
SendMessage(hwnd,WM_COMMAND,IDM_REREADDISK,0L);
}
}
return 0;
}

case IDM_RNDIR: /* Rename Directory */
{
char *path;
FARPROC lpDlgProc;
char szBuff[256];
BOOL rc;

path = CreatePathname(hDirTab,hTreeTab,CurDir);
i = strlen(path);
*(path + i - 1) = '\0';
strcpy(szBuff,path);
if(strlen(path) > 3) {
strcpy(szDlgCaption,"Rename Directory");
strcpy(szDlgPrompt,"Rename Directory as: ");
strcpy(szStartStr,path);
lpDlgProc = MakeProcInstance(GetStringDlgProc, hInst);
rc = DialogBox(hInst,"GetStringDlg", hwnd, lpDlgProc);
FreeProcInstance(lpDlgProc);
strcpy(szStartStr,"");
if(rc == FALSE)
return 0;
if(rename(szBuff,szDest) != 0) {
sprintf(szBuff,"Error renaming %s - %s",szDest,strerror(errno));
i = MessageBox(hwnd,szBuff,szCaption,
MB_ICONINFORMATION | MB_OKCANCEL);
}
else
SendMessage(hwnd,WM_COMMAND,IDM_REREADDISK,0L);
}
return 0;
}

case IDM_ABOUT:
{
BOOL rc;
FARPROC lpDlgProc;

lpDlgProc = MakeProcInstance(AboutDlgProc, hInst);
rc = DialogBox(hInst,"DirmAboutDlg", hwnd, lpDlgProc);
FreeProcInstance(lpDlgProc);
return 0;
}

case IDM_DISKFREE: /* User Selected disk free from menu */
{
DWORD free, z;
WORD b, m, t, h;
char szBuff[256];
char szStr[80];
struct diskfree_t dinfo;

if(_dos_getdiskfree(Drive,&dinfo) == 0) {
free = (LONG) dinfo.avail_clusters *
(LONG) dinfo.sectors_per_cluster *
(LONG) dinfo.bytes_per_sector;
b = LOWORD(free / 1000000000L); /* Get billions of bytes */
free = free % 1000000000L;
m = LOWORD(free / 1000000L); /* Get millions of bytes */
free = free % 1000000L;
t = LOWORD(free / 1000L); /* Get thousands of bytes */
h = free % 1000L; /* Get hundreds of bytes */
if(b > 0)
sprintf(szBuff,"%u,%03u,%03u,%03u byte(s) free\n",b,m,t,h);
else if(m > 0)
sprintf(szBuff,"%u,%03u,%03u byte(s) free\n",m,t,h);
else if(t > 0)
sprintf(szBuff,"%u,%03u byte(s) free\n",t,h);
else
sprintf(szBuff,"%u byte(s) free\n",h);
if(TotalDirs == 0)
strcpy(szStr,"1 Directory\n");
else
sprintf(szStr,"%u Directories\n",TotalDirs+1);
strcat(szBuff,szStr);
sprintf(szStr,"%luK of memory free",GetFreeSpace(0)/1024);
strcat(szBuff,szStr);
MessageBox(hwnd,szBuff,szCaption,MB_ICONINFORMATION | MB_OK );
}
else {
MessageBox(hwnd,"Error getting number of bytes free",szCaption,
MB_ICONINFORMATION | MB_OK );
}
return 0;
}

case IDM_REREADDISK: /* Reload the current disk */
i = 0;
while(DriveList[i] != Drive && i < NumberDrives)
i++;
if(DriveList[i] != Drive) {
MessageBox(hwnd,"Error rereading drive",szCaption,
MB_ICONINFORMATION | MB_OK );
return 0;
}
wParam = i + IDM_CHGDRIVE; /* Simulate drive change */
Drive = -1; /* and fall through */
/* Reset OldDrive in DIRMFILE.C */
SendMessage(hwndFile,WM_COMMAND,IDM_REREADDISK,0L);

/* Fall through */

case IDM_CHGDRIVE:
case IDM_CHGDRIVE+1:
case IDM_CHGDRIVE+2:
case IDM_CHGDRIVE+3:
case IDM_CHGDRIVE+4:
case IDM_CHGDRIVE+5:
case IDM_CHGDRIVE+6:
case IDM_CHGDRIVE+7:
case IDM_CHGDRIVE+8:
case IDM_CHGDRIVE+9:
case IDM_CHGDRIVE+10:
case IDM_CHGDRIVE+11:
case IDM_CHGDRIVE+12:
case IDM_CHGDRIVE+13:
case IDM_CHGDRIVE+14:
case IDM_CHGDRIVE+15:
case IDM_CHGDRIVE+16:
case IDM_CHGDRIVE+17:
case IDM_CHGDRIVE+18:
case IDM_CHGDRIVE+19:
case IDM_CHGDRIVE+20:
case IDM_CHGDRIVE+21:
case IDM_CHGDRIVE+22:
case IDM_CHGDRIVE+23:
case IDM_CHGDRIVE+24:
case IDM_CHGDRIVE+25:
case IDM_CHGDRIVE+26:
case IDM_CHGDRIVE+27:
case IDM_CHGDRIVE+28:
i = wParam - IDM_CHGDRIVE;
newdrive = DriveList[i];
if(Drive != newdrive)
{
Drive = newdrive;
TabError = LoadNewDriveInfo(hwnd,Drive);
if(TabError) {
MessageBox(hwnd,"Error reading drive",szCaption,
MB_ICONINFORMATION | MB_OK );
SendMessage(hwnd,WM_CLOSE,0,0L);
return 0;
}
OldScrollPos = 0;
OldFileDir = CurDir = 0;
GetClientRect(hwnd,&rect);
x1 = 0; y1 = 0;
hdc = GetDC(hwnd);
SelectObject(hdc,hFont);
j = GetLongestDirStr(hdc);
ReleaseDC(hwnd,hdc);
if(j != 0)
{
j = max(j,15*cxChar);
x2 = j + cxChar;
}
else
x2 = (LongestStr+1) * cxChar;
y2 = (TotalDirs+1) * cyChar;
DirRect.left = x1;
DirRect.top = y1;
DirRect.right = x2-1;
DirRect.bottom = rect.bottom;
sx = ScrollWidth*3/4;
sy = GetSystemMetrics(SM_CYVSCROLL);
FileRect.left = x2 + sx + cyChar;
FileRect.top = y1+1;
memset(blank,' ',10);
blank[10] = 0;
i = strlen(blank);
while(LOWORD(GetTextExtent(hdc,blank,i)) < DirRect.right && i < 80)
blank[i++] = ' ';
blank[i] = '\0';
blanklen = strlen(blank);
HiDir = 0;
InvalidateRect(hwndsb,NULL,TRUE);
InvalidateRect(hwndFile,NULL,TRUE);
SendMessage(hwnd,WM_SIZE,SIZENORMAL,MAKELONG(rect.right,rect.bottom));
InvalidateRect(hwnd,NULL,TRUE);
}
return 0;
}
break;

case WM_VSCROLL:
switch(wParam)
{
case SB_TOP:
OldScrollPos = 0;
break;
case SB_BOTTOM:
OldScrollPos = MaxScroll;
break;
case SB_PAGEDOWN:
OldScrollPos += PageInc; /* Fall through */
case SB_LINEDOWN:
OldScrollPos = min(MaxScroll,OldScrollPos+1);
break;
case SB_PAGEUP:
OldScrollPos -= PageInc; /* Fall through */
case SB_LINEUP:
OldScrollPos = max(0,OldScrollPos-1);
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
OldScrollPos = LOWORD(lParam);
break;
default:
break;
}
SetScrollPos(hwndsb,SB_CTL,OldScrollPos,TRUE);
neworg = OldScrollPos * cyChar;
if(neworg != yOrg) {
yOrg = neworg;
InvalidateRect(hwnd,&DirRect,FALSE);
}
break;

case WM_KEYDOWN:
switch(wParam)
{
case VK_HOME:
OldScrollPos = 0;
break;
case VK_END:
OldScrollPos = MaxScroll;
break;
case VK_NEXT:
OldScrollPos += PageInc; /* Fall through */
case VK_DOWN:
OldScrollPos = min(MaxScroll,OldScrollPos+1);
break;
case VK_PRIOR:
OldScrollPos -= PageInc; /* Fall through */
case VK_UP:
OldScrollPos = max(0,OldScrollPos-1);
break;
case VK_LEFT:
HiDir = max(0,HiDir-1);
if(HiDir != OldHiDir) {
hdc = GetDC(hwnd);
SelectObject(hdc,hHiPen);
SelectObject(hdc,GetStockObject(NULL_BRUSH));
SetBkMode(hdc,TRANSPARENT);
i = SetROP2(hdc,R2_XORPEN);
j = OldHiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
j = HiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
OldHiDir = HiDir;
SetROP2(hdc,i);
ReleaseDC(hwnd,hdc);
HiliteRectOn = TRUE;
}
return 0;
case VK_RIGHT:
HiDir = min(TotalDirs,HiDir+1);
if(HiDir != OldHiDir) {
hdc = GetDC(hwnd);
SelectObject(hdc,hHiPen);
SelectObject(hdc,GetStockObject(NULL_BRUSH));
SetBkMode(hdc,TRANSPARENT);
i = SetROP2(hdc,R2_XORPEN);
j = OldHiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
j = HiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
OldHiDir = HiDir;
SetROP2(hdc,i);
ReleaseDC(hwnd,hdc);
HiliteRectOn = TRUE;
}
return 0;
case VK_SPACE:
case VK_RETURN:
if(HiDir != CurDir) {
j = HiDir * cyChar - yOrg;
SendMessage(hwnd,WM_LBUTTONDOWN,0,MAKELONG(DirRect.left,j));
}
return 0;
case VK_TAB:
SetFocus(hwndFile);
return 0;
default:
break;
}
SetScrollPos(hwndsb,SB_CTL,OldScrollPos,TRUE);
neworg = OldScrollPos * cyChar;
if(neworg != yOrg) {
yOrg = neworg;
InvalidateRect(hwnd,&DirRect,FALSE);
}
break;

case WM_SETFOCUS:
if(!GotFirstPaintMsg || HiliteRectOn)
return 0;
GotFocus = TRUE;
hdc = GetDC(hwnd);
SelectObject(hdc,hHiPen);
SelectObject(hdc,GetStockObject(NULL_BRUSH));
SetBkMode(hdc,TRANSPARENT);
i = SetROP2(hdc,R2_XORPEN);
j = HiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
OldHiDir = HiDir;
SetROP2(hdc,i);
ReleaseDC(hwnd,hdc);
HiliteRectOn = TRUE;
return 0;

case WM_KILLFOCUS:
GotFocus = FALSE;
if(HiliteRectOn) {
hdc = GetDC(hwnd);
SelectObject(hdc,hHiPen);
SelectObject(hdc,GetStockObject(NULL_BRUSH));
SetBkMode(hdc,TRANSPARENT);
i = SetROP2(hdc,R2_XORPEN);
j = HiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
OldHiDir = HiDir;
SetROP2(hdc,i);
ReleaseDC(hwnd,hdc);
HiliteRectOn = FALSE;
}
return 0;

case WM_LBUTTONDOWN:
{
int mx, my, cd;

mx = LOWORD(lParam);
my = HIWORD(lParam);
if(DirRect.left <= mx && DirRect.right >= mx && hTreeTab != NULL)
{
if(DirRect.top <= my && DirRect.bottom >= my)
{
TreeStrTab = (TREEITEM) GlobalLock(hTreeTab);
if(TreeStrTab != NULL)
{
int OldDir;
TREEITEM tptr;

OldDir = CurDir;
my += yOrg;
cd = my / cyChar;
if(cd < 0)
CurDir = 0;
else if(cd > TotalDirs)
CurDir = TotalDirs;
else
CurDir = cd;
if(CurDir != OldDir)
{
if((CurDir == HiDir || OldDir == HiDir) && GotFocus) {
hdc = GetDC(hwnd);
SelectObject(hdc,hHiPen);
SelectObject(hdc,GetStockObject(NULL_BRUSH));
SetBkMode(hdc,TRANSPARENT);
i = SetROP2(hdc,R2_XORPEN);
j = HiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
OldHiDir = HiDir;
SetROP2(hdc,i);
ReleaseDC(hwnd,hdc);
}
hdc = GetDC(hwnd);
SelectObject(hdc,hFont);
tptr = (TreeStrTab+OldDir);
SetBkColor(hdc,SysBkColor);
SetTextColor(hdc,SysTextColor);
PrintDirStr(hdc,0,OldDir,tptr -> TreeStr);
tptr = (TreeStrTab+CurDir);
PrintDirStr(hdc,0,CurDir,tptr -> TreeStr);
ReleaseDC(hwnd,hdc);
InvalidateRect(hwndFile,NULL,TRUE);
memset(FileHilite,0,512);
if((CurDir == HiDir || OldDir == HiDir) && GotFocus) {
hdc = GetDC(hwnd);
SelectObject(hdc,hHiPen);
SelectObject(hdc,GetStockObject(NULL_BRUSH));
SetBkMode(hdc,TRANSPARENT);
i = SetROP2(hdc,R2_XORPEN);
j = HiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
OldHiDir = HiDir;
SetROP2(hdc,i);
ReleaseDC(hwnd,hdc);
}
}
GlobalUnlock(hTreeTab);
}
}
}
}
break;

case WM_SYSCOLORCHANGE:
SysTextColor = GetSysColor(COLOR_WINDOWTEXT);
SysBkColor = GetSysColor(COLOR_WINDOW);
wndclass.hbrBackground = COLOR_WINDOW+1;
wndclassfile.hbrBackground = COLOR_WINDOW+1;
wndclassbutton.hbrBackground = COLOR_WINDOW+1;
return 0;

case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
if(!GotFirstPaintMsg) {
GotFirstPaintMsg = TRUE;
GetClientRect(hwnd,&rect);
PostMessage(hwnd,WM_SIZE,SIZENORMAL,MAKELONG(rect.right,rect.bottom));
EndPaint(hwnd,&ps);
return 0;
}
if(!TabError)
{
RECT trect;

SelectObject(hdc,hFont);
SetBkColor(hdc,SysBkColor);
SetTextColor(hdc,SysTextColor);
if(IntersectRect(&trect,&ps.rcPaint,&DirRect)) {
TreeStrTab = (TREEITEM) GlobalLock(hTreeTab);
if(TreeStrTab != NULL) {
GetClientRect(hwnd,&rect);
PaintDirRect(hdc,ps.rcPaint.top,ps.rcPaint.bottom);
GlobalUnlock(hTreeTab);
}
}
if(GotFocus) {
SelectObject(hdc,hHiPen);
SelectObject(hdc,GetStockObject(NULL_BRUSH));
SetBkMode(hdc,TRANSPARENT);
i = SetROP2(hdc,R2_XORPEN);
j = HiDir * cyChar - yOrg;
k = j + cyChar;
Rectangle(hdc,HiDirRect.left,j,HiDirRect.right,k);
OldHiDir = HiDir;
SetROP2(hdc,i);
HiliteRectOn = TRUE;
}
}
EndPaint(hwnd,&ps);
return 0;

case WM_DESTROY:
{
char szSortTypeOut[20];

DestroyWindow(hwndsb);
DestroyWindow(hwndFile);
DestroyWindow(hwndStat);
for(i = 0; i < NumberDrives; i++)
DeleteObject(hBitmap[i]);
if(hDirTab != NULL)
GlobalFree(hDirTab);
if(hTreeTab != NULL)
GlobalFree(hTreeTab);
if(hFileTab != NULL)
GlobalFree(hFileTab);
/* if(hFont != NULL)
DeleteObject(hFont); */
if(hHiPen != NULL)
DeleteObject(hHiPen);
if(SortChanged &&
(OldSortType != SortType || OldAscendingFlag != AscendingFlag))
{
i = SortType - IDM_SORTNONE + 1;
if(AscendingFlag <= 0)
i += 10;
sprintf(szSortTypeOut,"%u",i);
WriteProfileString(szAppName,"Sort",szSortTypeOut);
}
PostQuitMessage(0);
return 0;
}
}
return(DefWindowProc(hwnd,messg,wParam,lParam));
}



  3 Responses to “Category : Windows 3.X Files
Archive   : DIRMGR.ZIP
Filename : DIRM.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/