亚洲欧美第一页_禁久久精品乱码_粉嫩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精品国产乱| 激情综合网天天干| 国产欧美一区二区精品性色| 成人免费视频一区| 亚洲欧美电影院| 欧美日韩国产精品成人| 日韩电影免费一区| 久久久www成人免费毛片麻豆| 国产成人夜色高潮福利影视| 国产精品美女一区二区| 色先锋aa成人| 日本成人中文字幕在线视频| 精品国产伦一区二区三区免费| 国产麻豆午夜三级精品| 国产精品蜜臀av| 欧美精品精品一区| 国产九九视频一区二区三区| 国产成人午夜精品影院观看视频 | 欧美一级二级三级蜜桃| 久久精品国产亚洲a| 国产清纯美女被跳蛋高潮一区二区久久w | 国产午夜精品一区二区三区视频| 欧美一级在线视频| 国产69精品一区二区亚洲孕妇| 亚洲女女做受ⅹxx高潮| 欧美一区二区在线免费播放| 国产成人在线视频网站| 亚洲综合一二三区| 久久精品人人做人人综合| 色综合天天做天天爱| 欧美a一区二区| 国产精品视频第一区| 911精品国产一区二区在线| 国产一二三精品| 亚洲国产视频直播| 国产人成亚洲第一网站在线播放 | 欧美色精品天天在线观看视频| 琪琪一区二区三区| 国产精品乱人伦一区二区| 欧美色国产精品| 99久久er热在这里只有精品66| 日韩电影在线免费| 一区二区三区在线免费观看| 亚洲精品一区二区三区99| 在线观看日韩精品| 成人在线视频首页| 免费观看在线综合色| 综合分类小说区另类春色亚洲小说欧美| 91麻豆精品国产91久久久久久久久| 成人午夜免费av| 蜜臀久久99精品久久久久宅男| 亚洲丝袜另类动漫二区| 久久精品男人天堂av| 精品久久久久一区| 欧美精品高清视频| 欧美性色综合网| 91免费观看国产| 国产福利不卡视频| 国产一区美女在线| 久久精品国产99久久6| 天堂在线亚洲视频| 亚洲午夜视频在线观看| 亚洲青青青在线视频| 日本一区二区成人| 国产精品视频第一区| 国产女人18毛片水真多成人如厕| 欧美刺激脚交jootjob| 欧美一级二级三级乱码| 欧美女孩性生活视频| 欧美日韩在线精品一区二区三区激情| 色婷婷久久久综合中文字幕| bt欧美亚洲午夜电影天堂| 国产成人8x视频一区二区| 国产乱子伦一区二区三区国色天香| 久久er99精品| 国产在线一区二区| 国产一区二区三区高清播放| 国产一区二区在线看| 国产在线视频一区二区三区| 国产精品资源站在线| 国产91丝袜在线18| eeuss鲁片一区二区三区在线看| 99这里只有久久精品视频| 99热99精品| 日本精品视频一区二区| 欧美偷拍一区二区| 欧美色网一区二区| 欧美二区三区91| 日韩一卡二卡三卡| 久久综合九色综合久久久精品综合| 久久综合久久综合久久| 国产精品乱码妇女bbbb| 亚洲乱码中文字幕综合| 午夜欧美视频在线观看| 久色婷婷小香蕉久久| 国产91综合一区在线观看| 91同城在线观看| 欧美丰满一区二区免费视频| 精品少妇一区二区三区免费观看| 久久久国产精品不卡| 18成人在线观看| 亚洲大片在线观看| 九一九一国产精品| av在线免费不卡| 欧美三级电影网站| 精品久久久久久久人人人人传媒| 国产拍揄自揄精品视频麻豆 | 亚洲五码中文字幕| 麻豆91精品视频| 成人av在线播放网址| 欧美日韩一区不卡| 久久久久国产精品麻豆| 亚洲激情综合网| 久久电影网站中文字幕| 91小视频在线| 欧美精品一区二区三区久久久| 亚洲人妖av一区二区| 全国精品久久少妇| eeuss国产一区二区三区| 欧美一区二区三区在线观看 | 18欧美乱大交hd1984| 日本成人中文字幕| 91猫先生在线| 国产亚洲精品aa午夜观看| 亚洲制服欧美中文字幕中文字幕| 日韩国产一区二| 99精品国产99久久久久久白柏| 日韩一区二区三区精品视频| 亚洲色图在线视频| 国产在线精品一区二区不卡了| 日本黄色一区二区| 国产精品丝袜91| 久久国产三级精品| 欧美偷拍一区二区| 亚洲欧美在线视频观看| 久久超碰97中文字幕| 欧美日韩一区二区三区视频 | 久久久国产午夜精品| 五月天一区二区三区| 99精品久久久久久| 国产人妖乱国产精品人妖| 久久99在线观看| 欧美乱妇23p| 亚洲精品成人少妇| 91精品国产91久久久久久最新毛片| 久久精品一区蜜桃臀影院| 亚洲视频每日更新| 久久精品国产**网站演员| 欧美日本在线播放| 亚洲激情自拍视频| 色吧成人激情小说| 日韩欧美在线不卡| 亚洲一区在线免费观看| av动漫一区二区| 884aa四虎影成人精品一区| 亚洲成人动漫一区| 精品精品欲导航| 一区二区三区不卡视频| 久久久久国产免费免费| 午夜天堂影视香蕉久久| 欧美一区二区三区在线电影| 粉嫩久久99精品久久久久久夜| 精品国产一区二区三区忘忧草| 在线综合+亚洲+欧美中文字幕| 欧美性感一区二区三区| 欧美日韩成人综合在线一区二区| 欧美性生活影院| 欧美日韩视频不卡| 91精品麻豆日日躁夜夜躁| 91精品国产色综合久久不卡电影 | 三级久久三级久久| 日本欧美韩国一区三区| 国产乱对白刺激视频不卡| 成人一级片在线观看| 色狠狠一区二区| 日韩写真欧美这视频| 久久亚洲欧美国产精品乐播 | a亚洲天堂av| 91久久奴性调教| 日韩精品一区二区三区视频播放| 久久久美女毛片| 一片黄亚洲嫩模| 紧缚捆绑精品一区二区| 成人av集中营| 欧美一卡二卡三卡| 国产精品成人网| 日韩和欧美一区二区| 国产精品自拍毛片| 欧美最新大片在线看| www国产成人免费观看视频 深夜成人网| 国产精品久久久久婷婷| 婷婷成人激情在线网| 波多野结衣欧美| 精品三级av在线| 亚洲一区二区综合|