(1)这是一个显示插入电脑U盘信息的程序,在进行U盘的检测和扫描的主函数中,有2个error不知道怎么解决,我是MFC对话框写的,主要问题在控件的描述这里。
(2)主函数如下:
void CU_disk_detection_scanningDlg::OnEnChangeEdit1()
{
// TODO: 如果该控件是 RICHEDIT 控件,它将不
// 发送此通知,除非重写 CDialogEx::OnInitDialog()
// 函数并调用 CRichEditCtrl().SetEventMask(),
// 同时将 ENM_CHANGE 标志“或”运算到掩码中。
// TODO: 在此添加控件通知处理程序代码
}
char CU_disk_detection_scanningDlg::FirstDriveFromMask(ULONG unitmask) //获取盘符 //不允许成员函数重新声明
{
char i;
//char unitmask;
for(i = 0;i < 26;i++)
{
if(unitmask &0x1)
break;
unitmask = unitmask >>1;
}
return i;
}
LRESULT CU_disk_detection_scanningDlg::WindowProc(UINT message,WPARAM wparam,LPARAM lparam)
{
CString detectMsg;
char wParam ;
char lParam ;
switch (message)
{
//WM_DEVICECHANGE,系统硬件改变发出来的系统消息
case WM_DEVICECHANGE:
{
PDEV_BROADCAST_HDR lpdb=(PDEV_BROADCAST_HDR)lparam;
switch (wParam) //char wParam;
{
case WM_DEVICECHANGE:
break;
case DBT_DEVICEARRIVAL: //设备检测结束,并且可以使用......
{
if(lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME) //逻辑卷
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
switch(lpdbv->dbcv_flags)
{
case 0: //U盘
{
CString decDriver;
//char FirstDriveFromMask;
CString m_editControl;
//char setWindowText;
decDriver = FirstDriveFromMask(lpdbv->dbcv_unitmask);
detectMsg.Format(_T("检测到U盘:[%s]插入!"),decDriver.GetBuffer(0));
m_editControl.setWindowText(detectMsg);
}
break;
case DBTF_MEDIA: //光盘
break;
}
}
}
break;
case DBT_DEVICEREMOVECOMPLETE: //设备卸载或者拔出
{
if(lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME) //逻辑卷
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
switch(lpdbv->dbcv_flags)
{
case 0: //U盘
{
CString decDriver;
//char wParam;
//CString FirstDriveFromMask;
CString m_editControl;
decDriver = FirstDriveFromMask(lpdbv->dbcv_unitmask); //第一个驱动器来自掩码 //应用指针
detectMsg.Format(_T("检测到U盘:[%s]拔出!"),decDriver.GetBuffer(0));
m_editControl.setWindowText(detectMsg);
}
break;
case DBTF_MEDIA: //光盘
break;
}
}
}
break;
}
}
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}
头文件如下:
// U_disk_detection_scanningDlg.h : 头文件
//
#pragma once
// CU_disk_detection_scanningDlg 对话框
class CU_disk_detection_scanningDlg : public CDialogEx
{
// 构造
public:
CU_disk_detection_scanningDlg(CWnd* pParent = NULL); // 标准构造函数
LRESULT CU_disk_detection_scanningDlg::WindowProc(UINT message,WPARAM wparam,LPARAM lparam);
//CString FirstDriveFromMask;
//CString m_editControl;
// 对话框数据
enum { IDD = IDD_U_DISK_DETECTION_SCANNING_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
//CEdit m_editControl;
// 实现
protected:
HICON m_hIcon;
// 生成的消息映射函数
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnEnChangeEdit1();
char FirstDriveFromMask(ULONG unitmask);
};
(3)报错信息
(4)尝试过找回m_editControl在.h文件中的定义,但是没有跳转到.h文档中。