亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? testdlg.cpp

?? 一本在講述USB驅動程式的書 及其范例原碼
?? CPP
字號:
// testDlg.cpp : implementation file
// Copyright (C) 1999 by Walter Oney
// All rights reserved

// This is the interesting program in the PNPEVENT sample, wherein I illustrate how
// a user-mode application tracks the PnP events associated with arrival and departure
// of devices. The key points here are these:
//
//	1.	At WM_INITDIALOG time, we register for notification of events involving an
//		interface GUID that our hardware (actually the PNPEVENT sample driver) uses.
//		We also call EnumerateExistingDevices to locate all existing PNPEVENT devices
//		so we can treat them all as having just arrived. (In general, this is what you'd
//		want to do. However, to keep this sample as simple as possible, we actually
//		ignore the 2d and subsequent instances of the PNPEVENT device.)
//
//	2.	We handle the WM_DEVICECHANGE message, which is how the system packages notifications
//		about hardware devices. We handle the various notifications as follows (this is the
//		order in which they'd occur when you run the test suggested in PNPEVENT.HTM):
//
//		a.	DBT_DEVICEARRIVAL for the interface: call OnNewDevice to display a message and
//			open a handle to the device. In addition, register to receive notifications
//			about this handle.
//
//		b.	DBT_DEVIQEQUERYREMOVE for the handle: ask permission to remove the device. If
//			this fails, we return a code that is supposed to block removal of the device
//			(but doesn't actually, in my experience).
//
//		c.	DBT_DEVICEREMOVECOMPLETE and DBT_DEVICEREMOVEPENDING for the handle: In
//			Windows 2000 or XP, unregister the handle notification. Doing this here would
//			destabilize Windows 98 and maybe 98SE or ME. Then close the handle
//
//		d.	DBT_DEVICEREMOVECOMPLETE for the interface: display a message.

#include "stdafx.h"
#include "test.h"
#include "testDlg.h"

typedef DWORD ULONG_PTR;
typedef DWORD DWORD_PTR;
#include "setupapi.h"
#pragma comment(lib, "setupapi")

#define _SYS_GUID_OPERATORS_
#include <initguid.h>
#include "..\sys\guids.h"
#include <winioctl.h>
#include "..\sys\ioctls.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BOOL win98;

///////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog

CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlg::IDD, pParent)
	{							// CTestDlg::CTestDlg
	//{{AFX_DATA_INIT(CTestDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_hInterfaceNotification = NULL;
	m_hHandleNotification = NULL;
	m_hDevice = INVALID_HANDLE_VALUE;

	OSVERSIONINFO vi = {sizeof(OSVERSIONINFO)};
	GetVersionEx(&vi);
	win98 = vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS;
	}							// CTestDlg::CTestDlg

CTestDlg::~CTestDlg()
	{							// CTestDlg::CTestDlg
	if (m_hDevice != INVALID_HANDLE_VALUE)
		CloseHandle(m_hDevice);
	}							// CTestDlg::CTestDlg

void CTestDlg::DoDataExchange(CDataExchange* pDX)
	{							// CTestDlg::DoDataExchange
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlg)
	DDX_Control(pDX, IDB_SENDEVENT, m_ctlSendevent);
	DDX_Control(pDX, IDC_EVENTS, m_ctlEvents);
	//}}AFX_DATA_MAP
	}							// CTestDlg::DoDataExchange

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDB_SENDEVENT, OnSendevent)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	ON_WM_DEVICECHANGE()
END_MESSAGE_MAP()

///////////////////////////////////////////////////////////////////////////////

VOID CTestDlg::EnumerateExistingDevices(const GUID* guid)
	{							// CTestDlg::EnumerateExistingDevices
	HDEVINFO info = SetupDiGetClassDevs((GUID*) guid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
	if (info == INVALID_HANDLE_VALUE)
		return;

	SP_INTERFACE_DEVICE_DATA ifdata;
	ifdata.cbSize = sizeof(ifdata);
	DWORD devindex;
	for (devindex = 0; SetupDiEnumDeviceInterfaces(info, NULL, (GUID*) guid, devindex, &ifdata); ++devindex)
		{						// for each device
		DWORD needed;
		SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &needed, NULL);

		PSP_INTERFACE_DEVICE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
		if (!detail)
			continue;
		detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
		if (!SetupDiGetDeviceInterfaceDetail(info, &ifdata, detail, needed, NULL, NULL))
			{						// can't get detail info
			free((PVOID) detail);
			continue;
			}						// can't get detail info

		CString devname = detail->DevicePath;
		free((PVOID) detail);
		OnNewDevice(devname, guid);
		}						// for each device

	SetupDiDestroyDeviceInfoList(info);
	}							// CTestDlg::EnumerateExistingDevices

///////////////////////////////////////////////////////////////////////////////

BOOL CTestDlg::HandleDeviceChange(DWORD evtype, PDEV_BROADCAST_DEVICEINTERFACE dip)
	{							// CTestDlg::HandleDeviceChange
	CString devname = dip->dbcc_name;

	switch (evtype)
		{						// process device interface notification

	case DBT_DEVICEARRIVAL:
		OnNewDevice(devname, &dip->dbcc_classguid);
		break;

	case DBT_DEVICEREMOVECOMPLETE:
		{						// DBT_DEVICEREMOVECOMPLETE
		CString msg;
		msg.Format(_T("Device %s removed"), (LPCTSTR) devname);
		m_ctlEvents.AddString(msg);
		break;
		}						// DBT_DEVICEREMOVECOMPLETE

		}						// process device interface notification

	return TRUE;
	}							// CTestDlg::HandleDeviceChange

///////////////////////////////////////////////////////////////////////////////


BOOL CTestDlg::HandleDeviceChange(DWORD evtype, PDEV_BROADCAST_HANDLE dhp)
	{							// CTestDlg::HandleDeviceChange

	if (dhp->dbch_handle != m_hDevice)
		return TRUE;			// notification for some other handle

	switch (evtype)
		{						// process handle notification

	case DBT_DEVICEQUERYREMOVE:
		if (MessageBox(_T("Okay to remove the device?"), _T("Removal Query"), MB_YESNO) != IDYES)
			return BROADCAST_QUERY_DENY;

		// Note that we fall through there because we may not get additional notifications

	case DBT_DEVICEREMOVECOMPLETE:
	case DBT_DEVICEREMOVEPENDING:
		MessageBox(_T("Closing Handle"));

		// Deregistering the notification handle here will destablize Win98. Reader
		// Fred Chumaceiro discovered that it's okay to deregister outside the context
		// of a WM_DEVICECHANGE that refers to the same notification handle, though.

		if (m_hHandleNotification && !win98)
			{					// deregister notification handle
			UnregisterDeviceNotification(m_hHandleNotification);
			m_hHandleNotification = NULL;
			}					// deregister notification handle

		if (m_hDevice != INVALID_HANDLE_VALUE)
			CloseHandle(m_hDevice);
		m_hDevice = INVALID_HANDLE_VALUE;
		
		m_ctlSendevent.EnableWindow(FALSE);
		break;
		
		}						// process handle notification

	return TRUE;
	}							// CTestDlg::HandleDeviceChange

///////////////////////////////////////////////////////////////////////////////

void CTestDlg::OnDestroy() 
	{							// CTestDlg::OnDestroy
	// Per Fred Chumaceiro: it's safe to deregister the notification handles in Win98
	// while the window still exists.

	if (m_hInterfaceNotification)
		UnregisterDeviceNotification(m_hInterfaceNotification);
	if (m_hHandleNotification)
		UnregisterDeviceNotification(m_hHandleNotification);

	CDialog::OnDestroy();
	}							// CTestDlg::OnDestroy

///////////////////////////////////////////////////////////////////////////////

BOOL CTestDlg::OnDeviceChange(UINT nEventType, DWORD dwData)
	{							// CTestDlg::OnDeviceChange
	if (!dwData)
		return TRUE;

	_DEV_BROADCAST_HEADER* p = (_DEV_BROADCAST_HEADER*) dwData;

	if (p->dbcd_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
		return HandleDeviceChange(nEventType, (PDEV_BROADCAST_DEVICEINTERFACE) p);
	else if (p->dbcd_devicetype == DBT_DEVTYP_HANDLE)
		return HandleDeviceChange(nEventType, (PDEV_BROADCAST_HANDLE) p);
	else
		return TRUE;
	}							// CTestDlg::OnDeviceChange

///////////////////////////////////////////////////////////////////////////////

BOOL CTestDlg::OnInitDialog()
	{							// CTestDlg::OnInitDialog
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	DEV_BROADCAST_DEVICEINTERFACE filter;
	filter.dbcc_size = sizeof(filter);
	filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
	filter.dbcc_classguid = GUID_DEVINTERFACE_PNPEVENT;
	m_hInterfaceNotification = RegisterDeviceNotification(m_hWnd, &filter, 0);

	EnumerateExistingDevices(&GUID_DEVINTERFACE_PNPEVENT);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
	}							// CTestDlg::OnInitDialog

///////////////////////////////////////////////////////////////////////////////

VOID CTestDlg::OnNewDevice(const CString& devname, const GUID* guid)
	{							// CTestDlg::OnNewDevice
	CString msg;

	if (m_hDevice != INVALID_HANDLE_VALUE)
		{						// only supports 1 instance
		msg.Format(_T("This test program can only handle one instance of PNPEVENT at a time.\n"
			"Therefore, the arrival of a new instance named \n%s is being ignored."),
			(LPCTSTR) devname);
		MessageBox(msg, "Warning", MB_OK | MB_ICONEXCLAMATION);
		return;
		}						// only supports 1 instance

	msg.Format(_T("Device %s arrived"), (LPCTSTR) devname);
	m_ctlEvents.AddString(msg);

	msg = devname;

	msg.SetAt(2, _T('.'));

	m_hDevice = CreateFile(msg, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (m_hDevice == INVALID_HANDLE_VALUE)
		{
		MessageBox("Unable to open handle to device", "Error", MB_OK | MB_ICONHAND);
		return;
		}

	// Per Fred Chumaceiro: it should be safe to deregister a stale notification handle
	// now, since the current WM_DEVICECHANGE doesn't pertain to it.

	if (m_hHandleNotification)
		UnregisterDeviceNotification(m_hHandleNotification);

	DEV_BROADCAST_HANDLE filter = {0};
	filter.dbch_size = sizeof(filter);
	filter.dbch_devicetype = DBT_DEVTYP_HANDLE;
	filter.dbch_handle = m_hDevice;
	m_hHandleNotification = RegisterDeviceNotification(m_hWnd, &filter, 0);
	
	m_ctlSendevent.EnableWindow(TRUE);
	}							// CTestDlg::OnNewDevice

///////////////////////////////////////////////////////////////////////////////
// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTestDlg::OnPaint() 
	{							// CTestDlg::OnPaint
	if (IsIconic())
		{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
		}
	else
		CDialog::OnPaint();
	}							// CTestDlg::OnPaint

///////////////////////////////////////////////////////////////////////////////

HCURSOR CTestDlg::OnQueryDragIcon()
	{							// CTestDlg::OnQueryDragIcon
	return (HCURSOR) m_hIcon;
	}							// CTestDlg::OnQueryDragIcon

///////////////////////////////////////////////////////////////////////////////

void CTestDlg::OnSendevent() 
	{							// CTestDlg::OnSendevent
	if (m_hDevice == INVALID_HANDLE_VALUE)
		return;
	DWORD junk;
	DeviceIoControl(m_hDevice, IOCTL_GENERATE_EVENT, NULL, 0, NULL, 0, &junk, NULL);
	}							// CTestDlg::OnSendevent

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美综合视频在线观看| 一区二区成人在线视频| 精品视频免费在线| 91看片淫黄大片一级在线观看| 精品无人区卡一卡二卡三乱码免费卡| 亚洲欧美日韩小说| 亚洲色图另类专区| 一区二区三区日韩精品| 亚洲三级在线播放| 亚洲一区在线观看视频| 亚洲小说欧美激情另类| 亚洲成国产人片在线观看| 性做久久久久久免费观看欧美| 亚洲国产精品精华液网站| 亚洲韩国精品一区| 午夜影院久久久| 免费三级欧美电影| 国产综合一区二区| 国产a区久久久| 国产一区二三区好的| 精品一区二区三区蜜桃| 国产v综合v亚洲欧| 欧美在线观看视频一区二区| 欧美日韩国产精品成人| 欧美日韩一级二级三级| 欧美草草影院在线视频| 国产精品水嫩水嫩| 综合电影一区二区三区| 日韩主播视频在线| 成人一区二区在线观看| 欧美性一区二区| 久久精品亚洲国产奇米99| 亚洲欧洲精品一区二区三区| 天堂蜜桃91精品| 成人午夜大片免费观看| 欧美三区在线观看| 久久九九久久九九| 中文字幕一区二区在线观看| 日本一区二区免费在线 | 日韩视频一区在线观看| 国产伦精品一区二区三区免费| 老色鬼精品视频在线观看播放| 久久精品国产亚洲aⅴ| 久久99精品国产麻豆不卡| 精品午夜久久福利影院 | 最近日韩中文字幕| ...xxx性欧美| 亚洲尤物视频在线| 天天色天天操综合| 国内精品伊人久久久久av一坑| 国产91精品久久久久久久网曝门| 99视频精品全部免费在线| 不卡视频在线观看| 精品视频在线视频| 欧美成人福利视频| 91福利区一区二区三区| 91网站黄www| 五月天激情综合网| 成人av综合一区| 日韩欧美在线影院| 欧美激情中文字幕一区二区| 亚洲黄色尤物视频| 国产乱码精品一区二区三区av| 日本欧美肥老太交大片| 国产一区二区0| 色综合天天综合网天天看片| 7777精品伊人久久久大香线蕉完整版| 久久久久久免费网| 亚洲www啪成人一区二区麻豆| 日韩高清不卡一区二区| 日韩av中文字幕一区二区三区| 国产电影精品久久禁18| 在线免费不卡视频| 久久久久99精品国产片| 一个色综合网站| 午夜精品免费在线观看| 亚洲欧美电影一区二区| 久久成人综合网| 欧洲精品在线观看| 国产午夜精品久久久久久久 | 亚洲欧洲日产国产综合网| 琪琪久久久久日韩精品| 91视视频在线直接观看在线看网页在线看| 欧美日韩在线精品一区二区三区激情| 2023国产精品视频| 亚洲成人黄色小说| 91日韩在线专区| 91免费版在线| 欧美喷水一区二区| 亚洲色图制服诱惑| 国产福利一区二区| 欧美成人艳星乳罩| 亚洲一级二级三级| 91在线精品一区二区三区| 精品sm捆绑视频| 日韩精品电影在线| 欧美三区在线观看| 亚洲国产精品一区二区久久恐怖片 | 一区二区三区美女| 99视频精品在线| 国产精品二三区| 成人免费毛片片v| 国产日韩欧美综合在线| 国产农村妇女毛片精品久久麻豆| 亚洲一区在线观看视频| 在线精品亚洲一区二区不卡| 国产精品久久久久久久久免费丝袜| 寂寞少妇一区二区三区| 欧美成人三级电影在线| 免费观看一级欧美片| 日本精品一区二区三区高清 | 国产精品99久久久| 欧美精品 国产精品| 洋洋av久久久久久久一区| 国产99久久久精品| 久久九九影视网| 久久精品视频在线看| 欧美久久一区二区| 美女精品自拍一二三四| 日韩欧美高清在线| 久久 天天综合| 国产欧美日韩精品一区| 99精品热视频| 亚洲与欧洲av电影| 91精品国产综合久久精品性色 | 一区二区三区资源| 欧美性感一类影片在线播放| 樱桃视频在线观看一区| 欧美日本国产视频| 精品一区二区三区日韩| 国产精品网站在线| 欧美又粗又大又爽| 日本网站在线观看一区二区三区| 91精品国产综合久久香蕉的特点| 日韩精品五月天| 精品午夜一区二区三区在线观看| 欧美一级久久久久久久大片| 一区二区免费看| 欧美一级夜夜爽| 亚洲欧美日韩小说| 色哟哟一区二区在线观看| 婷婷久久综合九色国产成人| 欧美精品粉嫩高潮一区二区| 精品一区二区久久久| 日韩丝袜情趣美女图片| 成人在线综合网站| 日韩欧美一级在线播放| 午夜国产精品影院在线观看| 成人av电影免费观看| 欧美一区二区三区视频免费| 三级欧美韩日大片在线看| 国产日韩视频一区二区三区| 在线观看免费亚洲| 国产乱子轮精品视频| 亚洲综合色网站| 久久精品在线免费观看| 在线不卡的av| 99re这里只有精品视频首页| 日本欧美一区二区| 亚洲综合在线第一页| 欧美视频一二三区| 免费不卡在线观看| 一区二区三区高清在线| 国产欧美中文在线| 欧美成人性战久久| 欧美女孩性生活视频| 91在线无精精品入口| 国产一区二区三区免费看| 香蕉久久一区二区不卡无毒影院 | 91久久精品网| 成人网男人的天堂| 亚洲日本免费电影| 亚洲欧洲精品一区二区三区不卡| 久久亚洲一级片| 91精品国产综合久久精品app| 91免费版在线看| 成人av电影观看| 国产v综合v亚洲欧| 丁香亚洲综合激情啪啪综合| 久久99久久精品欧美| 男人的天堂亚洲一区| 亚洲六月丁香色婷婷综合久久 | 国产精品理论在线观看| 日韩精品一区二区三区蜜臀 | 狠狠色综合色综合网络| 香蕉成人伊视频在线观看| 亚洲一区二区免费视频| 精品99999| 国产制服丝袜一区| 日韩精品一卡二卡三卡四卡无卡| 国产专区综合网| 亚洲制服丝袜av| 亚洲欧美日韩小说| 亚洲高清免费在线| 日韩电影网1区2区| 亚洲午夜激情av| 国产成人亚洲综合a∨婷婷图片| 国产精品一区在线观看乱码| 麻豆成人91精品二区三区| 亚洲高清视频中文字幕|