home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
bootsec
/
bootsec.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
25KB
|
662 lines
//****************************************************************************
// File: BOOTSEC.C
//
//
// Purpose: The main module. Brings up a private dialog, that prompts
// the user for a drive letter. When the user chooses "Get
// Info", BOOTSEC determines what kind of drive it is, and then if
// appropriate, reads the boot sector of the drive, and displays
// all the information from the bootsector in the dialog.
//
// Functions:
// WinMain() - initializes app and processes message loop
// ActualDlgProc - the actual Dialog Procedure
// AboutDlgProc - Dialog procedure for the About box
// ClassDlgProc - the Window Proc for the Private Dialog
// NewEditProc - the subclassed Edit window procedure
// ReadBootSector - read the boot sector via INT 25
// ShowDriveInfo - display the boot sector structure
// GetPictRect - get a rect to display a drive icon
// IsCDRomDrive - is it a CD-ROM drive?
// IsNetDrive - is it a network drive?
// SetAllLabels - show a given string in all the labels
// MyGetDriveType - return the type of drive
//
// Development Team:
//
// Joe Long, June 1993
//
//
// Written by Microsoft Product Support Services, Windows Developer Support
// Copyright (c) 1992 Microsoft Corporation. All rights reserved.
//****************************************************************************
#include "windows.h"
#include "bootsec.h"
#include "memory.h"
#include "resource.h"
#define CBSECTORSIZE 512
// global vars
int iDriveType; // what kind of drive is selected
HINSTANCE hInst; // the instance handle
FARPROC lpfnOldEditProc; // the original edit procedure
char szErrorBuf[64]; // a buffer to load error strings
// exported function
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
BOOL FAR PASCAL __export ActualDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
BOOL FAR PASCAL __export AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
long FAR PASCAL __export ClassDlgProc(HWND hDlg, UINT message, WPARAM wParam , LPARAM lParam);
long FAR PASCAL __export NewEditProc(HWND hEdit, UINT message, WPARAM wParam , LPARAM lParam);
//helper functions
BOOL ReadBootSector(int iDrive, PSTR pBuf);
void ShowDriveInfo(HWND hDlg, BOOTSECTOR *bs);
void GetPictRect(HWND hWnd, LPRECT lpRect);
BOOL IsCDRomDrive(int iDrive);
WORD IsNetDrive(int iDrive);
void SetAllLabels(HWND hDlg, LPSTR szText);
int MyGetDriveType(BOOTSECTOR *bs);
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
****************************************************************************/
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wc;
HWND hwnd;
DLGPROC dlgProc;
hInst = hInstance;
if (!hPrevInstance)
{
memset(&wc,NULL, sizeof(WNDCLASS));
wc.lpfnWndProc = ClassDlgProc;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MAIN));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = COLOR_WINDOW + 1;
wc.lpszClassName = "BootSectorClass";
RegisterClass(&wc);
}
dlgProc = (DLGPROC)MakeProcInstance(ActualDlgProc, hInst);
hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAINDIALOG), 0, dlgProc);
ShowWindow(hwnd,nCmdShow);
while (GetMessage(&msg,NULL,0,0))
{
// if we want to be able to use the TAB key
// to move between controls, the ENTER
// key to execute the default button,
// the ESCAPE key to dismiss the dialog,
// or any other dialog - type functionality,
// we must call IsDialogMessage()
if (!IsDialogMessage(hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
FreeProcInstance((FARPROC)dlgProc);
return msg.wParam;
}
/****************************************************************************
ClassDlgProc(HWND hDlg, UINT message, WPARAM wParam , LPARAM lParam)
PURPOSE:
this function gets placed between the dialog and the DefDlgProc because
1. its a private dialog
and
2. we specified a DLGPROC for the third parameter
of the CreateDialog() call.
we could handle all of the messages here (except for the WM_INITDIALOG
message which is not sent to non-dialogs, or we can pass the messages
off to DefDlgProc(), which will then call our dialog procedure
ActualDlgProc(), given below
****************************************************************************/
long FAR PASCAL __export ClassDlgProc(HWND hDlg, UINT message, WPARAM wParam , LPARAM lParam)
{
return DefDlgProc(hDlg, message, wParam, lParam);
}
/****************************************************************************
ActualDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
PURPOSE:
The procedure for the application that does most of the work.
This is the function that we passed in as the last parameter to the
CreateDialog() call. We do this so that we can get the WM_INITDIALOG
message, which is not passed to the WndProc of a Private Dialog.
We subclass the edit control so that we can restrict input to capital
letters, the backspace key, and the TAB key.
****************************************************************************/
BOOL FAR PASCAL __export ActualDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static HDC hMemDC;
static HBITMAP hBitmap, hbmOld;
switch (message)
{
case WM_INITDIALOG:
{
HDC hdc;
HWND hwndEdit;
HMENU hSysMenu;
hSysMenu = GetSystemMenu(hDlg, FALSE);
// disable the "maximize" option in the system menu
EnableMenuItem(hSysMenu, 4, MF_GRAYED|MF_DISABLED|MF_BYPOSITION);
// disable the "size" option of the system menu
EnableMenuItem(hSysMenu, 2, MF_GRAYED|MF_DISABLED|MF_BYPOSITION);
// subclass the edit control so that we
// can restrict input to letter only
hwndEdit = GetDlgItem(hDlg, IDC_DRIVE);
if (hwndEdit)
lpfnOldEditProc = (FARPROC)SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG)NewEditProc);
// limit the text of the edit control to 1 character
SendMessage(hwndEdit, EM_LIMITTEXT, 1, 0L);
// put a reasonable default into the edit control
SetWindowText(hwndEdit, "C");
hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_DRIVES));
hdc = GetDC(NULL);
hMemDC = CreateCompatibleDC(hdc);
ReleaseDC(NULL, hdc);
hbmOld = SelectObject(hMemDC, hBitmap);
iDriveType = BM_NONE;
return FALSE; // didn't set the focus
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT rect;
BeginPaint(hDlg, &ps);
GetPictRect(hDlg