实现文件拖放的一种简洁方法

Python创建一个GUI(Tkinter)选择文件的界面获取文件路径 阅读详情
1、自已编写专用的类,程序复杂、维护麻烦;2、必须要将文件拖到对话框中的编辑控件上,拖动的文件名才被接受,而标准的WINDOWS程序只须将文件拖放到对话框即可被接受;3、只能接受一个拖放的文件。本文要介绍的这种方法只须调用一个WINDOWS API函数DragQueryFile即可实现文件的拖放操作,而且完全克服了上述3点不足。下面先介绍一下这个函数。

---- DragQueryFile原型为:

UINT DragQueryFile( HDROP    hDrop,                    UINT      iFile,                    LPTSTR   lpszFile,                    UINT      cch )

---- 其中hDrop是指向拖动文件结构的句柄;

---- iFile 是以0开始的被托动文件的序号,因为一次可能拖动多个文件。当此参数

---- 设为0xFFFFFFFF,则函数返回拖动文件的数量;

---- lpszFile 是指向文件名的缓冲区;

---- cch 是文件名缓冲区的大小,即文件名的字符数。

---- 明确了该函数的参数后,编程就是一件很简单的事情了。以下给出一个完整的实例,程序运行后弹出一个对话框,可以拖动任意数量的文件或目录到上面,松开鼠标后,程序先显示拖放文件的数量,然后将拖放的文件名全部显示在一个List Box控件中。具体步骤如下:

  1. 建立一个基于对话框的工程drop,然后其它选项全部用缺省值。
  2. 选中IDD_DROP_DIALOG对话框中Extended Styles的Accept files属性。
  3. 给IDD_DROP_DIALOG对话框添加一个List Box 控件IDC_LIST1。
  4. 在ClassWizard中给CdropDlg类添加成员变量m_list,类型为ClistBox。
  5. 给CdropDlg类中增加处理WINDOWS消息WM_DROPFILES的函数,接受系统给出的默认名字OnDropFiles,然后输入以下代码:
void CDropDlg::OnDropFiles(HDROP hDropInfo) {	char *lpszFileName=new char[512],cFileCount[10];	int nFileCount,i;	nFileCount=::DragQueryFile    (hDropInfo,0xFFFFFFFF,NULL,512);	::AfxMessageBox(itoa(nFileCount,cFileCount,10));	for (i=0;i

---- 注意程序中的::DragFinish (hDropInfo);语句是必不可少的,它用于释放WINDOWS为处理文件拖放而分配的内存。

---- 运行此程序可以看到,拖动的文件只要一进入对话框的边界,鼠标上立刻会现一个“+”,在对话框上的任意位置释放鼠标,拖放的文件都会被接受,完全解决了《用MFC实现文件拖放到编辑框》必须将文件拖到编辑框的不足;而且拖放是通过调用WINDOWS API函数实现的,因此程序非常健壮,几乎没有什么维护量。程序在INDOWS98、vc++5.0下通过。

用tkinter实线图片拖动 个人编写的小程序,实现拓片在GUI的拖动,十分盈动好用 立即下载

相关推荐

Python-PySimpleGUI一个建立在tkinter之上简单但功能强大的GUI

PySimpleGUI 一个建立在tkinter之上简单但功能强大的GUI

34-鼠标拖拽文件功能

直接拖动部分文件或者文件夹到tkinter窗口,实现快速添加文件功能。例1:活用lambda在处理方法传入多个函数.

***** 984

xilinx zynq-7000 linux下rs422串口通信测试步骤

这几天使用xilinx的zynq-7000系列调试rs422串口,期间遇到不少问题,好在最终调试完成,在这里记录一下调试步骤。 我用的soc型号是xc7z100,板载了2个rs422外设,PS端有2个uart控制器,uart0用于连接rs232并作为console控制台输出,uart1连接rs422。 rs422和主板连线原理图如下: 其中422_TXD1_3V3 和422_RXD1_3V3 为数据发送和接收引脚,422_TXD_DE1_3V3为发送使能引脚,422_RXD_REn1_...

dongyunke的博客 5914

C#中将某一文件拖向应用程序后打开或进行其它操作的实现

作者:PeterXu  来源:Blog.CSDN  Blog: http://blog.csdn.net/peterreg/版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。本文地址:http://blog.csdn.net/peterreg/archive/2008/04/04/2248815.aspx在我们的日常应用中,经常可以将

PeterXu的专栏 1717

STM32F411CEU6实战:用W25Q64存储多张图片,在240x240 LCD上轮播显示(附源码)

本文详细介绍了如何使用STM32F411CEU6通过SPI接口管理W25Q64 Flash中的多张图片,并在240x240 LCD上实现平滑轮播显示。内容涵盖硬件配置、图片存储方案设计、轮播系统实现及性能优化技巧,特别针对SPI传输优化和多图存储管理提供了实用解决方案。附源码,适合嵌入式开发者参考。

weixin_32025789的博客 316

智能车实战——从ADC采集到PWM控制,让电磁车精准循迹

本文详细介绍了电磁循迹智能车的实现原理与实战技巧,涵盖从ADC信号采集、PWM控制到PID算法整定的全流程。通过STM32代码示例解析电感信号处理、差比和偏差计算及电机驱动等关键技术,帮助开发者快速掌握智能车精准循迹的核心方法,提升电磁车竞赛项目的开发效率。

weixin_29192211的博客 308

tkinter拖拽读取文件

首先要下载windnd库 pip install windnd import tkinter as tk import windnd from tkinter.messagebox import showinfo def dragged_files(files): msg = '\n'.join((item.decode('gbk') for item in files)) showinfo("拖拽文件路径",msg) if __name__ == '__main__':

devil6636252的博客 5608

幸狐RV1106开发板实战:5分钟搞定Yolo8模型部署(附避坑指南)

本文详细介绍了在幸狐RV1106开发板上快速部署YOLOv8模型的实战流程。通过RKNN-Toolkit2工具链,将ONNX模型转换为RV1106 NPU专用的RKNN格式,并完成交叉编译与上板运行。文章重点分享了环境搭建、模型转换的关键步骤以及常见的避坑指南,帮助开发者高效实现边缘AI目标检测应用。

weixin_28677451的博客 926

DRAG 实现文件拖放的一种简洁方法

实现文件拖放的一种简洁方法  本文要介绍的这种方法只须调用一个WINDOWS API函数DragQueryFile即可实现文件的拖放操作,而且完全克服了上述3点不足。下面先介绍一下这个函数。  ---- DragQueryFile原型为:  UINT DragQueryFile (HDROP hDrop, UINT iFile, LPTSTR lpszFile, UINTcch)

Sayesan的专栏 1187

Codex智能体从零搭建:环境配置、代码管理与MCP扩展实战

AI智能体(Agent)作为连接大语言模型与实际应用的关键技术,通过感知、决策与执行框架,将AI能力融入具体工作流。其核心原理在于利用提示工程、上下文管理与工具调用,将自然语言指令转化为可执行操作。在软件开发领域,AI智能体能够显著提升代码生成、项目管理和自动化任务的效率。通过Model Context Protocol(MCP)等标准化协议,智能体可以安全、结构化地集成外部工具与服务,实现能力扩展。本文聚焦于Codex这一AI驱动的代码助手平台,详细解析其环境配置、代码索引、记忆系统等核心模块,并深入探讨

weixin_34220179的博客 601

科研问答:医药类本科生(临床、中医、中药与护理)本科阶段是否需要开展科研学习?

医药类本科生(临床、中医、中药与护理)本科阶段是否需要开展科研学习?

MD Code 1525

实现文件拖放的一种简洁方法 (转)

实现文件拖放的一种简洁方法 (转)[@more@]实现文件拖放的一种简洁方法 湖北省襄樊市电信局计算机中心 张洪征 ---- 读了南京海军指挥学院黄向明同志在贵报上发表的《用MFC实现文件拖放到编辑框》一文获益匪浅,同时...

ciya3282的博客 81

【机器学习-18】特征筛选:提升模型性能的关键步骤

我们将介绍不同类型的特征筛选方法,包括基于统计的方法、基于模型的方法和嵌入式方法等,并详细解释每种方法的原理和适用场景。通过特征筛选,我们可以减少数据集的维度,降低模型的复杂度,提高模型的泛化能力,并加速模型的训练过程。通过选择适当的特征筛选方法,我们可以减少模型的复杂度,提高模型的泛化能力,并加速模型的训练过程。然而,并非所有的特征都对模型的性能提升有所贡献,有些特征甚至可能是冗余的、噪声较大的或者与目标变量无关的。我们的目标是通过特征筛选选择出对欺诈检测最有用的特征,以提高模型的预测精度。

qq_38614074的博客 1万+

vc++中实现文件拖放功能

<br />实现文件拖放的一种简洁方法     <br />   本文要介绍的这种方法只须调用一个WINDOWS    API函数DragQueryFile即可实现文件的拖放操作,而且完全克服了上述3点不足。下面先介绍一下这个函数。     <br />   ----    DragQueryFile原型为:     <br />    <br />   UINT    DragQueryFile    (HDROP    hDrop,    UINT    iFile,    LPTSTR    lpsz

scollins的专栏 1629

“EXB文件的格式和编程“

首先,打开文件并读取文件头,然后解析文件头中的元数据信息。接下来,循环读取数据块,每次读取块头部分,解析块的大小和类型,并读取相应大小的块数据。文件头(Header):EXB文件通常包含一个文件头,用于存储关于文件的元数据信息。读取EXB文件时,首先需要解析文件头,以了解文件的属性和数据结构。总结起来,EXB文件是一种常见的二进制数据文件格式,在编程中处理EXB文件需要了解其基本结构和元数据信息。通过以上代码,您可以根据自己的需求扩展处理其他类型的数据块,或者根据EXB文件的具体规范进行解析和处理。

HackCyberX的博客 1547

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: C++大师Lippman:我对中国程序员的忠告
下一篇: 再谈用MFC实现文件拖放到编辑框
普通网友
博客等级 码龄22年 1万+粉丝 3156原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址