Home > Software engineering >  Questions about MFC for disk drive type
Questions about MFC for disk drive type

Time:09-27

Computer small white, just in learning MFC, copy the contents of the textbook wrote some code, but the results have a question, the code is as follows:
CPP:
//SelectDiskDriverDlg. CPP: implementation file
//

# include "stdafx. H"
# include "SelectDiskDriver. H"
# include "SelectDiskDriverDlg. H"
# include "afxdialogex. H"
#include

# ifdef _DEBUG
# define new DEBUG_NEW
# endif
//for application "about" menu item CAboutDlg dialog

The class CAboutDlg: public CDialogEx
{
Public:
CAboutDlg ();

//data dialog
# ifdef AFX_DESIGN_TIME
Enum {IDD=IDD_ABOUTBOX};
# endif

Protected:
Virtual void DoDataExchange (CDataExchange * symbol;//support DDX/DDV

//implementation
Protected:
DECLARE_MESSAGE_MAP ()
};

CAboutDlg: : CAboutDlg () : CDialogEx (IDD_ABOUTBOX)
{
}

Void CAboutDlg: : DoDataExchange (CDataExchange * symbol)
{
CDialogEx: : DoDataExchange (symbol);
}

BEGIN_MESSAGE_MAP (CAboutDlg CDialogEx)
END_MESSAGE_MAP ()


//CSelectDiskDriverDlg dialog



CSelectDiskDriverDlg: : CSelectDiskDriverDlg (pParent/*=NULL CWnd * */)
: CDialogEx (IDD_SELECTDISKDRIVER_DIALOG, pParent)
, m_DriveType (_T (" "))
{
M_hIcon=AfxGetApp () - & gt; LoadIcon (IDR_MAINFRAME);
}

Void CSelectDiskDriverDlg: : DoDataExchange (CDataExchange * symbol)
{
CDialogEx: : DoDataExchange (symbol);
DDX_Control (symbol, IDC_COMBO_DRIVE m_drive);
DDX_Text (symbol, IDC_STATIC1 m_DriveType);
}

BEGIN_MESSAGE_MAP (CSelectDiskDriverDlg CDialogEx)
ON_WM_SYSCOMMAND ()
ON_WM_PAINT ()
ON_WM_QUERYDRAGICON ()
ON_CBN_SELCHANGE (IDC_COMBO_DRIVE, & amp; CSelectDiskDriverDlg: : OnCbnSelchangeComboDrive)
END_MESSAGE_MAP ()


//CSelectDiskDriverDlg message handler

BOOL CSelectDiskDriverDlg: : OnInitDialog ()
{
CDialogEx: : OnInitDialog ();

//will "about... "Menu item added to the system menu,

//IDM_ABOUTBOX must be in the system command range,
ASSERT ((IDM_ABOUTBOX & amp; 0==IDM_ABOUTBOX xfff0));
ASSERT (IDM_ABOUTBOX & lt; 0 xf000);

CMenu * pSysMenu=GetSystemMenu (FALSE);
If (pSysMenu!=NULL)
{
BOOL bNameValid;
Cstrings strAboutMenu;
BNameValid=strAboutMenu. LoadString (IDS_ABOUTBOX);
ASSERT (bNameValid);
if (! StrAboutMenu. IsEmpty ())
{
PSysMenu - & gt; The AppendMenu (MF_SEPARATOR);
PSysMenu - & gt; AppendMenu (MF_STRING IDM_ABOUTBOX, strAboutMenu);
}
}

//set this dialog ICONS, when the application is the main window is not a dialog, the framework will automatically
//do this
SetIcon (m_hIcon, TRUE);//set the large icon
SetIcon (m_hIcon, FALSE);//set the small icon

//TODO: add additional initialization code in the
Size_t alldrive=: : GetLogicalDriveStrings (0, NULL);

_TCHAR * driverstr;
Driverstr=new _TCHAR [alldrive + sizeof (_T (" ")));

Size_t twosize=GetLogicalDriveStrings (alldrive driverstr);

Cstrings DriveLetter;
for (int i=0; i {
DriveLetter=driverstr + I * 4 + 4;
M_drive. InsertString (I, DriveLetter GetBuffer ());
}
M_drive. SetCurSel (0);
Return TRUE;//unless set focus to the control, return TRUE
}

Void CSelectDiskDriverDlg: : OnSysCommand (UINT nID, LPARAM LPARAM)
{
If ((nID & amp; 0 xfff0)==IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
DlgAbout. DoModal ();
}
The else
{
CDialogEx: : OnSysCommand (nID, lParam);
}
}

//if the dialog box to add a minimize button, you need the following code
//to draw the icon, to use the document/view model of MFC application,
//it will be done automatically by the framework,

Void CSelectDiskDriverDlg: : OnPaint ()
{
If (IsIconic ())
{
CPaintDC dc (this);//for drawing device context

The SendMessage (WM_ICONERASEBKGND, reinterpret_cast & lt; WPARAM> (dc) GetSafeHdc ()), 0);

//make the icon is centered within the workspace rectangular
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect rect;
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;

//draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
CDialogEx: : OnPaint ();
}
}

//when the user drag minimize window system call this function to obtain the cursor
//show,
HCURSOR CSelectDiskDriverDlg: : OnQueryDragIcon ()
{
Return static_cast & lt; HCURSOR> (m_hIcon);
}


Void CSelectDiskDriverDlg: : OnCbnSelchangeComboDrive ()
{
//TODO: add the control notification handler code
Cstrings strDrive;
M_drive. GetWindowTextW (strDrive);
Int retCode=: : GetDriveType (strDrive GetBuffer ());
The switch (retCode)
{
Case DRIVE_UNKNOWN:
M_DriveType="drive types: unknown";
break;
Case DRIVE_NO_ROOT_DIR:
M_DriveType="error" drive types: the root directory.
break;
Case DRIVE_REMOVABLE:
M_DriveType="drive types: removable disk drive".
break;
Case DRIVE_FIXED:
M_DriveType="drive types: fixed disk drive".
break;
Case DRIVE_REMOTE:
M_DriveType="drive types: network disk drive".
break;
Case DRIVE_CDROM:
M_DriveType="drive types: cd-rom";
break;
Case DRIVE_RAMDISK:
M_DriveType="drive types: RAM";
break;
Default:
M_DriveType="drive types: unknown";
break;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related