⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drive.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************/
/***									***/
/***	DRIVE.C     - Drive selection routines				***/
/***									***/
/***	Largely borrowed from ClarkC's COMMDLG FILEOPEN.C               ***/
/***									***/
/***									***/
/**************************************************************************/

#include <windows.h>
#include "smartmon.h"

#define cbCaption       64
#define _MAX_PATH	256
#define CBN_DRAW	0x8000	 /* Used with OFN_COMBODOWN */
#define dxSpace         4

extern WORD wWinVer;
extern HANDLE hInst;

static WORD dyItem = 0;
static WORD dyText;
WORD dxDirDrive = 0;
WORD dyDirDrive = 0;
HDC  hdcMemory = 0;
HBITMAP hbmpOrigMemBmp;
HBITMAP hbmpDirDrive = (HANDLE)NULL;
char CurDriveList[27] = {0};
WORD CurDriveCount;
WORD cCurDriveSel = -1;

static DWORD rgbWindowColor = 0xFF000000;  /* Not a valid RGB color */
static DWORD rgbWindowText  = 0xFF000000;
static DWORD rgbHiliteColor = 0xFF000000;
static DWORD rgbHiliteText  = 0xFF000000;
static DWORD rgbDDWindow    = 0xFF000000;
static DWORD rgbDDHilite    = 0xFF000000;

#define rgbSolidBlue	0x00FF0000

BOOL ChangeDrive( char );
void InitDriveBox( HWND );
void ListDrives( HWND );
char SimpleLower( char );
VOID StringLower( LPSTR );
int  GetDriveIndex( WORD, WORD );
HBITMAP LoadAlterBitmap( int, DWORD, DWORD );
void vDeleteDirDriveBitmap( void );
BOOL LoadDirDriveBitmap( void );
void MySetObjectOwner( HANDLE );
LONG RgbInvertRgb( LONG );
void SetRGBValues( void );
void ResetDriveBox( HWND );

/**************************************************************************/
/***                                                                    ***/
/***	ChangeDrive							***/
/***                                                                    ***/
/**************************************************************************/

BOOL ChangeDrive( char chDrv )
{
    char cCurDrive;
    BOOL rc = FALSE;

    chDrv |= 0x60;
    cCurDrive = get_current_drive();
    set_current_drive( chDrv - 'a' );

    if ( is_CDROM_drive( chDrv - 'a' ) )
	if ( !is_valid_CD() )
	    goto cd_failed;

    if ( chDrv == get_current_drive() )
	return TRUE;

cd_failed:

    set_current_drive( cCurDrive - 'a' );
    return FALSE;
}


/**************************************************************************/
/***                                                                    ***/
/***	SetRGBValues							***/
/***                                                                    ***/
/**************************************************************************/

void SetRGBValues()
{
    rgbWindowColor = GetSysColor( COLOR_WINDOW );
    rgbWindowText  = GetSysColor( COLOR_WINDOWTEXT );
    rgbHiliteColor = GetSysColor( COLOR_HIGHLIGHT );
    rgbHiliteText  = GetSysColor( COLOR_HIGHLIGHTTEXT );
}


void InitDriveBitmap()
{
    HBITMAP hbmpTemp;
    HDC hdcScreen;

    //
    // Create a DC that is compatible with the screen and find the
    // handle of the null bitmap
    //
    SetRGBValues();
    hdcScreen = GetDC( 0 );
    hdcMemory = CreateCompatibleDC( hdcScreen );
    hbmpTemp = CreateCompatibleBitmap( hdcMemory, 1, 1 );
    hbmpOrigMemBmp = SelectObject( hdcMemory, hbmpTemp );
    SelectObject( hdcMemory, hbmpOrigMemBmp );
    DeleteObject( hbmpTemp );
    MySetObjectOwner( hdcMemory );
    ReleaseDC( 0, hdcScreen );

    LoadDirDriveBitmap();
}


/**************************************************************************/
/***                                                                    ***/
/***	InitDriveBox							***/
/***                                                                    ***/
/**************************************************************************/

void InitDriveBox( HWND hWnd )
{
    if ( wWinVer >= 0x030A )
	SendDlgItemMessage( hWnd, IDD_DRIVEID, CB_SETEXTENDEDUI,
	    (WPARAM)1, (LPARAM)0);
    else if ( GetSysModalWindow() )
	/* Windows 3.00, sysmodal bug.	clarkc	 2 May 1991 */
	EnableWindow( GetDlgItem(hWnd, IDD_DRIVEID), FALSE );

    ResetDriveBox( hWnd );
}


/**************************************************************************/
/***                                                                    ***/
/***	ResetDriveBox							***/
/***									***/
/**************************************************************************/

void ResetDriveBox( HWND hWnd )
{
    int i;
    HWND hCtl;

    SetRGBValues();
    LoadDirDriveBitmap();

    CurDriveCount = count_valid_drives( CurDriveList );

    //
    // If the current drive selection is gone, (say someone removed
    // a network drive from a DOS session), select the current drive.
    //
    if ( cCurDriveSel != -1 ) {
	for ( i = 0; i < CurDriveCount; i++ )
	    if ( cCurDriveSel == CurDriveList[i+1] )
		goto drive_still_good;
    }

    cCurDriveSel = get_current_drive() - 'a';

drive_still_good:

    hCtl = GetDlgItem( hWnd, IDD_DRIVEID );
    InvalidateRect( hCtl, (LPRECT)NULL, TRUE );

    ListDrives( hWnd );

    PostMessage( hWnd, WM_COMMAND, IDD_DRIVEID, MAKELPARAM(hCtl, CBN_SELCHANGE) );
}


/**************************************************************************/
/***                                                                    ***/
/***	ListDrives							***/
/***                                                                    ***/
/**************************************************************************/

void ListDrives( HWND hWnd )
{
    short i;
    char cBuffer[_MAX_PATH];
    HWND hCmb = GetDlgItem( hWnd, IDD_DRIVEID );
    WORD iCurrentDrive, iCurrentDriveType;

    SendMessage( hCmb, WM_SETREDRAW, FALSE, 0L );
    SendMessage( hCmb, CB_RESETCONTENT, 0, 0L );

    for( i = 0; i < CurDriveCount; i++ ) {

	iCurrentDrive = (WORD)CurDriveList[i+1];

	/* Note: it is very important that the uppercase 'A' be used for the
	 *	 drive letter in cBuffer[0], as the Novell Netware driver
	 *	 will GP Fault if you pass in a lowercase drive letter.
	 *	 30 October 1991	 Clark Cyr
	 */
	cBuffer[0] = (char) (iCurrentDrive + 'A');
	cBuffer[1] = ':';
	cBuffer[2] = '\0';

	iCurrentDriveType = GetDriveType( iCurrentDrive );
	if ( iCurrentDriveType < 2)  /* Is it a phantom?  Skip it! */
	    continue;

	if ( (iCurrentDriveType != DRIVE_REMOVABLE) &&
	     !((iCurrentDriveType == DRIVE_REMOTE) &&
	       is_CDROM_drive(iCurrentDrive)) ) {
	    if ( ChangeDrive(cBuffer[0]) ) {
		if ( iCurrentDriveType != DRIVE_REMOTE ) {
		    cBuffer[2] = ' ';
		    get_volume_label( iCurrentDrive, (LPSTR)(cBuffer+3) );
		    OemToAnsi( (LPSTR)cBuffer, (LPSTR)cBuffer );
		} else {
		    WORD iSel;
		    char szTempField[cbCaption];

		    /* Set the first character to zero.  If the drive is
		     * disconnected, the call to WNetGetConnection() will
		     * return a value other than WN_SUCCESS, but the string
		     * will be valid.  If the string isn't altered, wsprintf
		     * will just place the null string after the space.
		     * 18 July 1991    ClarkC
		     */
		    szTempField[0] = '\0';
		    iSel = cbCaption;
		    WNetGetConnection( (LPSTR)cBuffer, (LPSTR)szTempField,
			(LPWORD)&iSel);
		    wsprintf( (LPSTR)(cBuffer+2), " %s", (LPSTR)szTempField );
		}
	    }
	}

	StringLower( (LPSTR)cBuffer );
	SendMessage( hCmb, CB_INSERTSTRING, (WPARAM)i,
	    (LPARAM)(LPSTR)cBuffer);
	SendMessage( hCmb, CB_SETITEMDATA, (WPARAM) i, (LPARAM)(DWORD)(
	    GetDriveIndex( iCurrentDrive, iCurrentDriveType ) ) );
	if ( iCurrentDrive == cCurDriveSel )
	   SendMessage( hCmb, CB_SETCURSEL, (WPARAM) i, 0 );
    }

    SendMessage( hCmb, WM_SETREDRAW, (WPARAM)TRUE, 0L );
    ChangeDrive( (char)(CurDriveList[0] + 'a') );
}


/**************************************************************************/
/***                                                                    ***/
/***	SimpleLower							***/
/***                                                                    ***/
/**************************************************************************/

char SimpleLower( char chChar )
{
    _asm {
	mov	al, chChar
	cmp	al,'A'
	jb	NoChange
	cmp	al,'Z'
	ja	NoChange
	add	al,'a'-'A'
NoChange:
    }
}


/**************************************************************************/
/***                                                                    ***/
/***	StringLower							***/
/***                                                                    ***/
/**************************************************************************/

VOID StringLower( LPSTR lpsz )
{
    if ( lpsz )
	while ( *lpsz ) {
	    *lpsz = SimpleLower( *lpsz );
	    lpsz++;
        }
}


/**************************************************************************/
/***                                                                    ***/
/***	GetDriveIndex							***/
/***                                                                    ***/
/**************************************************************************/

int GetDriveIndex( WORD wDrive, WORD wDriveType )
{
    register short i = HARDDRVBMP;

    if ( wDriveType == 1 )	/* Drive doesn't exist! */
	return(0);

    if ( is_CDROM_drive( wDrive ) )
	i = CDDRVBMP;

    else if ( wDriveType == DRIVE_REMOVABLE )
	i = FLOPPYBMP;

    else if ( wDriveType == DRIVE_REMOTE )
	i = NETDRVBMP;

    else if ( is_RAM_drive( wDrive ) )
	i = RAMDRVBMP;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -