qDebug function char FirstDriveFromMask( ULONG unitmask )



尝试在QT中制作项目,我需要检测任何新的USB设备并在main.cpp中返回字母。

我在谷歌上找到了这个,它应该可以工作,但我不知道如何通过调用函数 char FirstDriveFromMask(ULONG unitmask(来打印驱动程序字母.cpp使用简单的 qDebug((。

你能帮我吗?

void Main_OnDeviceChange( HWND hwnd, WPARAM wParam, LPARAM lParam )
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
TCHAR szMsg[80];
switch(wParam )
{
case DBT_DEVICEARRIVAL:
// Check whether a CD or DVD was inserted into a drive.
if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
if (lpdbv -> dbcv_flags & DBTF_MEDIA)
{
StringCchPrintf( szMsg, sizeof(szMsg)/sizeof(szMsg[0]),
TEXT("Drive %c: Media has arrived.n"),
FirstDriveFromMask(lpdbv ->dbcv_unitmask) );
MessageBox( hwnd, szMsg, TEXT("WM_DEVICECHANGE"), MB_OK );
}
}
break;
case DBT_DEVICEREMOVECOMPLETE:
// Check whether a CD or DVD was removed from a drive.
if (lpdb -> dbch_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
if (lpdbv -> dbcv_flags & DBTF_MEDIA)
{
StringCchPrintf( szMsg, sizeof(szMsg)/sizeof(szMsg[0]),
TEXT("Drive %c: Media was removed.n" ),
FirstDriveFromMask(lpdbv ->dbcv_unitmask) );
MessageBox( hwnd, szMsg, TEXT("WM_DEVICECHANGE" ), MB_OK );
}
}
break;
default:
/*
Process other WM_DEVICECHANGE notifications for other
devices or reasons.
*/
;
}
}
/*------------------------------------------------------------------
FirstDriveFromMask( unitmask )
Description
Finds the first valid drive letter from a mask of drive letters.
The mask must be in the format bit 0 = A, bit 1 = B, bit 2 = C,
and so on. A valid drive letter is defined when the
corresponding bit is set to 1.
Returns the first drive letter that was found.
--------------------------------------------------------------------*/
char FirstDriveFromMask( ULONG unitmask )
{
char i;
for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)
break;
unitmask = unitmask >> 1;
}
return( i + 'A' );
}

要么是这个:

#include <QDebug>
///
qDebug() <<
"Drive" << FirstDriveFromMask(lpdbv ->dbcv_unitmask)  << ": Media has arrived";

或者格式更好一点

qDebug() <<
QString("Drive %1: Media has arrived").arg(FirstDriveFromMask(lpdbv ->dbcv_unitmask));

如果该输出转到默认调试控制台而不是Windows,则必须遵循答案:Qt qDebug((在Windows shell中不起作用,并在 project.pro 文件中进行了小的更改:

CONFIG += console

相关内容

  • 没有找到相关文章

最新更新