智慧讲台中的windows探测U盘

Posted qianbo_insist

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了智慧讲台中的windows探测U盘相关的知识,希望对你有一定的参考价值。

目的

目的是在做智慧讲台中去探测U盘的插入和拔出,并且能够得到所有的磁盘目录和文件
程序如下所示:

#include <iostream>
#include <windows.h>
#include <dbt.h>
#include <stdio.h>
#include <math.h>
LRESULT CALLBACK WndProc(HWND h, UINT msg, WPARAM wp, LPARAM lp)

	if (msg == WM_DEVICECHANGE) 
		if ((DWORD)wp == DBT_DEVICEARRIVAL) 
			DEV_BROADCAST_VOLUME* p = (DEV_BROADCAST_VOLUME*)lp;
			if (p->dbcv_devicetype == DBT_DEVTYP_VOLUME) 
				int l = (int)(log(double(p->dbcv_unitmask)) / log(double(2)));
				printf("c盘入系统\\n", 'A' + l);
			
		
		else if ((DWORD)wp == DBT_DEVICEREMOVECOMPLETE) 
			DEV_BROADCAST_VOLUME* p = (DEV_BROADCAST_VOLUME*)lp;
			if (p->dbcv_devicetype == DBT_DEVTYP_VOLUME) 
				int l = (int)(log(double(p->dbcv_unitmask)) / log(double(2)));
				printf("%c盘出系统\\n", 'A' + l);
			
		
		return TRUE;
	
	else return DefWindowProc(h, msg, wp, lp);

int main() 
	WNDCLASS wc;
	ZeroMemory(&wc, sizeof(wc));
	wc.lpszClassName = TEXT("myusbmsg");
	wc.lpfnWndProc = WndProc;

	RegisterClass(&wc);
	HWND h = CreateWindow(TEXT("myusbmsg"), TEXT(""), 0, 0, 0, 0, 0,
		0, 0, GetModuleHandle(0), 0);
	MSG msg;
	while (GetMessage(&msg, 0, 0, 0) > 0) 
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	

磁盘文件列表

获取磁盘文件列表的class,获取所有文件之后查询ppt文件就行,ppt文件作为智慧讲台的课件。

#include <string>
#include <vector>
#include "io.h"
#include <iostream>
#include "opencv2/core.hpp"

using namespace std;
using namespace cv;
struct face_db_name

	//所有人的姓名
	// 初始化为0
	int label = 0;
	vector<string> _files;
	vector<string> _names;
	vector<int> _lables;
	vector<Mat> _feather;
	vector<int>& getlables()
	
		return _lables;
	
	void pushlables(int number)
	
		_lables.push_back(number);
	
;


	//列出子文件夹的所有文件,并设定回调函数
void listfiles(std::string dir, std::string namefolder,face_db_name &dbname);
void listfolder(std::string dir, std::vector<string> & names);
void searchfile(string folder, face_db_name & dbname);



#include "filesystem.h"



//人名的文件夹
void listfiles(std::string dir, std::string namefolder, face_db_name &dbname)

	intptr_t handle;
	_finddata_t findData;

	string dirfilter = dir + "/" + namefolder + "/" + "*.*";
	handle = _findfirst(dirfilter.c_str(), &findData);    // 查找目录中的第一个文件
	if (handle == -1)
	
		cout << "Failed to find first file!\\n";
		return;
	
	dbname._names.push_back(namefolder);
	//face_desc desc;
	//desc.name = namefolder;//子文件夹的名称为人名
	int label = (int)dbname._names.size();
	do
	
		if (!(findData.attrib & _A_SUBDIR))
		
			String filename = dir + "/" + namefolder + "/" + findData.name;
			dbname._files.push_back(filename);
			//Mat res = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
			//int getface = 0;
			//std::vector<cv::Rect> faces;

			//Mat face = detect(res, getface, faces);
			//if (getface == 1) //如果检测到人脸
			
				//dbname._feather.push_back(face);
				//dbname._lables.push_back(label);
			
		
	 while (_findnext(handle, &findData) == 0);    // 查找目录中的下一个文件
													//cout << "Done!\\n";
	_findclose(handle);    // 关闭搜索句柄



//从dir目录中中寻找其中的目录,每一个目录subdir代表一个人,包含了单个人的多张照片
void listfolder(std::string dir, std::vector<string> & names)

	intptr_t handle;
	_finddata_t findData;

	string dirfilter = dir + "/" + "*.*";
	handle = _findfirst(dirfilter.c_str(), &findData);    // 查找目录中的第一个文件
	if (handle == -1)
	
		cout << "Failed to find first file!\\n";
		return;
	

	do
	
		if (findData.attrib & _A_SUBDIR)
			//&& strcmp(findData.name, ".") != 0
			//&& strcmp(findData.name, "..") != 0
			//)    // 是否是子目录并且不为"."或".."
		
			if (findData.name[0] != '.')
			
				names.push_back(findData.name);
			
		
		else //否则是文件
		
			//子文件
			//face_desc_vec.files.push_back(findData.name);
		
	 while (_findnext(handle, &findData) == 0);    // 查找目录中的下一个文件
	_findclose(handle);    // 关闭搜索句柄


void searchfile(string folder, face_db_name & dbname)

	std::vector<string> vecs;
	listfolder(folder.c_str(), vecs);

	//face_db_name dbname;
	auto iter = vecs.begin();
	while (iter != vecs.end())
	
		//文件夹名称就是人名
		string name = *iter;
		cout << name << endl;
		//string mfolder = folder + "/" + name;

		listfiles(folder, name,dbname);
		iter++;
	

以上是关于智慧讲台中的windows探测U盘的主要内容,如果未能解决你的问题,请参考以下文章

智慧讲台必须支持的协议

智慧讲台:office 文件 pdf 文件 转成 png图片

DBA云讲台 | 在武汉——疫情一线民企掌门人的担当与思考

费曼讲台学习方法论

DBA云讲台 | 暖聚云端共话变革,迎接疫后“春天”

大牛讲台|Visier Feature Developer 带你入门Angular2