Category : C Source Code
Archive   : MEWELDT.ZIP
Filename : DESKDLG.C
Output of file : DESKDLG.C contained in archive : MEWELDT.ZIP
/* */
/* File : DESKDLG.C */
/* */
/* Purpose : Dialog procs for the DESKTOP demo program. */
/* */
/* History : */
/* */
/* (C) Copyright 1989 Marc Adler/Magma Systems All Rights Reserved */
/*===========================================================================*/
#if MSC
#include
#include
#elif TC
#include
#include
#endif
#include
#include
#include
#include
#include "window.h"
#include "keys.h"
#include "rc.h"
#include "desktop.h"
static WORD idCurrDlg;
int pascal GenericDialogDriver(WORD idDlg, int (pascal *pfnDlg)())
{
WORD hModule;
HDLG hDlg;
if ((hModule = OpenResourceFile(DESKTOP_RESFILE)) == FALSE)
{
MessageBox("Can't open DESKTOP.RES", NULL, NULL, "Error", MB_OK);
return FALSE;
}
if ((hDlg = LoadDialog(hModule, idDlg, hMain, (PFBOOL) pfnDlg)) == NULLHWND)
{
MessageBox("Can't load the dialog box", NULL, NULL, "Error", MB_OK);
return FALSE;
}
CloseResourceFile(hModule);
idCurrDlg = idDlg;
return DialogBox(hDlg);
}
/****************************************************************************/
/* */
/* CHANGE-DIRECTORY DIALOG PROC */
/* */
/****************************************************************************/
int pascal ChgDirDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
char buf[MAXPATHLEN];
switch (message)
{
case WM_INITDIALOG :
SetDlgItemText(hDlg, ID_EDIT, getcwd(buf, sizeof(buf)));
SendDlgItemMessage(hDlg, ID_EDIT, EM_SETSEL, 0, -1L);
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button
*/
GetDlgItemText(hDlg, ID_EDIT, buf, sizeof(buf));
if (buf[0] && chdir(buf) >= 0)
{
RefreshDirectory();
EndDialog(hDlg, wParam);
}
else
{
MessageBox("Cannot change to directory", buf, NULL, "Error",
MB_OK | MB_ICONEXCLAMATION);
}
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
/*
Return FALSE if you did not process the message. This gives the default
dialog proc a crack at handling it. Note - do NOT call any DefWindowProc
here; returning FALSE does the same thing.
*/
return FALSE;
}
int pascal CreateDirDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
char buf[MAXPATHLEN];
switch (message)
{
/*
We don't handle the WM_INITDIALOG message, but we if we wanted to, we
could fill all of the controls with various datum.
*/
case WM_INITDIALOG :
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button
*/
GetDlgItemText(hDlg, ID_EDIT, buf, sizeof(buf));
if (buf[0] && mkdir(buf) >= 0)
{
RefreshDirectory();
EndDialog(hDlg, wParam);
}
else
MessageBox("Cannot create directory", buf, NULL, "Error",
MB_OK | MB_ICONEXCLAMATION);
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
return FALSE;
}
int pascal VolumeDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
char buf[MAXPATHLEN];
char cmd[80];
extern char *GetVolumeName(char *);
switch (message)
{
/*
We don't handle the WM_INITDIALOG message, but we if we wanted to, we
could fill all of the controls with various datum.
*/
case WM_INITDIALOG :
if (GetVolumeName(buf))
{
SetDlgItemText(hDlg, ID_EDIT, buf);
SendDlgItemMessage(hDlg, ID_EDIT, EM_SETSEL, 0, -1L);
}
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button
*/
GetDlgItemText(hDlg, ID_EDIT, buf, sizeof(buf));
if (buf[0])
ChangeVolumeName(buf);
EndDialog(hDlg, TRUE);
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
return FALSE;
}
int pascal RenameDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
return CopyDialogProc(hDlg, message, wParam, lParam);
}
int pascal CopyDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
char buf[MAXPATHLEN];
char buf2[MAXPATHLEN];
switch (message)
{
case WM_INITDIALOG :
strncpy(buf, szFileNames[DirWndInfo.idxCurrSel], 12);
buf[12] = '\0';
SetDlgItemText(hDlg, ID_EDIT, buf);
SendDlgItemMessage(hDlg, ID_EDIT, EM_SETSEL, 0, -1L);
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button
*/
GetDlgItemText(hDlg, ID_EDIT, buf, sizeof(buf));
GetDlgItemText(hDlg, ID_EDIT2, buf2, sizeof(buf));
if (buf[0])
{
if (idCurrDlg == DLG_COPY)
CopyFiles(buf, buf2);
else
RenameFiles(buf, buf2);
RefreshDirectory();
EndDialog(hDlg, wParam);
}
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
return FALSE;
}
int pascal DeleteDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
char buf[MAXPATHLEN];
switch (message)
{
case WM_INITDIALOG :
strncpy(buf, szFileNames[DirWndInfo.idxCurrSel], 12);
buf[12] = '\0';
SetDlgItemText(hDlg, ID_EDIT, buf);
SendDlgItemMessage(hDlg, ID_EDIT, EM_SETSEL, 0, -1L);
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button
*/
GetDlgItemText(hDlg, ID_EDIT, buf, sizeof(buf));
if (buf[0] == '[')
{
char *s = strchr(buf, ']');
if (s)
{
*s = '\0';
if (rmdir(buf+1) == 0)
{
RefreshDirectory();
EndDialog(hDlg, wParam);
}
else
MessageBox("Cannot delete the directory", buf, NULL, "Error",
MB_OK | MB_ICONEXCLAMATION);
}
}
else if (buf[0])
{
DeleteFiles(buf);
RefreshDirectory();
EndDialog(hDlg, wParam);
}
else
MessageBox("Cannot delete that file", buf, NULL, "Error",
MB_OK | MB_ICONEXCLAMATION);
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
return FALSE;
}
int pascal RunDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
char buf[MAXPATHLEN];
switch (message)
{
case WM_INITDIALOG :
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button
*/
GetDlgItemText(hDlg, ID_EDIT, buf, sizeof(buf));
if (buf[0] && system(buf) == 0)
{
RefreshDirectory();
EndDialog(hDlg, wParam);
}
else
MessageBox("Cannot run that file", buf, NULL, "Error",
MB_OK | MB_ICONEXCLAMATION);
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
return FALSE;
}
/****************************************************************************/
/* */
/* VIEW-PARTIAL DIALOG PROC */
/* */
/****************************************************************************/
int pascal PartialDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
char spec[MAXPATHLEN];
switch (message)
{
/*
We don't handle the WM_INITDIALOG message, but we if we wanted to, we
could fill all of the controls with various datum.
*/
case WM_INITDIALOG :
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case IDOK :
/*
The user pressed the OK button
*/
GetDlgItemText(hDlg, ID_EDIT, spec, sizeof(spec));
if (spec[0])
{
strcpy(szFileSpec, spec);
if (DirWndInfo.flags & VIEW_ALL)
CheckMenuItem(GetMenu(hMain), ID_VIEW_ALL, MF_UNCHECKED|MF_BYCOMMAND);
else if (DirWndInfo.flags & VIEW_PROGRAMS)
CheckMenuItem(GetMenu(hMain), ID_VIEW_PROGRAMS, MF_UNCHECKED|MF_BYCOMMAND);
CheckMenuItem(GetMenu(hMain), ID_VIEW_PARTIAL, MF_CHECKED|MF_BYCOMMAND);
DirWndInfo.flags &= ~(VIEW_PROGRAMS | VIEW_ALL);
DirWndInfo.flags |= VIEW_PARTIAL;
RefreshDirectory();
}
EndDialog(hDlg, wParam);
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
return FALSE;
}
/****************************************************************************/
/* */
/* FORMAT and SYS DIALOG PROCS (combined) */
/* */
/****************************************************************************/
int pascal FormatDialogProc(hDlg, message, wParam, lParam)
HWND hDlg;
WORD message;
WORD wParam;
DWORD lParam;
{
int drive;
char buf[MAXPATHLEN];
switch (message)
{
/*
We don't handle the WM_INITDIALOG message, but we if we wanted to, we
could fill all of the controls with various datum.
*/
case WM_INITDIALOG :
CheckRadioButton(hDlg, 'A', 'A', 'B');
return TRUE;
case WM_COMMAND :
switch (wParam)
{
case 'A' :
case 'B' :
CheckRadioButton(hDlg, wParam, 'A', 'B');
break;
case IDOK :
/*
The user pressed the OK button
*/
if (IsDialogButtonChecked(hDlg, 'A'))
drive = 'A';
else if (IsDialogButtonChecked(hDlg, 'B'))
drive = 'B';
else
EndDialog(hDlg, TRUE);
sprintf(buf, "%s %c:",
(idCurrDlg == DLG_FORMAT) ? "format" : "sys", drive);
if (system(buf) == 0)
EndDialog(hDlg, TRUE);
else
MessageBox((idCurrDlg == DLG_FORMAT) ? "Cannot format the drive"
: "Cannot sys the drive",
NULL, NULL, "Error", MB_OK | MB_ICONEXCLAMATION);
break;
case IDCANCEL :
/*
The user pressed the CANCEL button
*/
EndDialog(hDlg, wParam);
break;
} /* switch */
return TRUE;
}
/*
Return FALSE if you did not process the message. This gives the default
dialog proc a crack at handling it. Note - do NOT call any DefWindowProc
here; returning FALSE does the same thing.
*/
return FALSE;
}
int pascal SystemDialogProc(HWND hDlg, WORD message, WORD wParam, DWORD lParam)
{
return FormatDialogProc(hDlg, message, wParam, lParam);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/