VC如何实现托拽

从程序外面,托动一个文件到应用程序界面,如何得到这个文件的路径并且激发一个处理消息?  
   
  另外,已经知道一个大字符串,现在要统计里面某一个字母的个数,如何统计?如果用While循环的话,要1分种,不现实,有没有什么速度快一点的方法?  
   
  谢谢 问题点数:50、回复次数:9Top

src="/Include/Board.htm?Tags=" frameborder="0" scrolling="no">

1 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2006-09-07 14:42:52 得分 15

1.An   application   that   calls   DragAcceptFiles   with   the   fAccept   parameter   set   to   TRUE   has   identified   itself   as   able   to   process   the   WM_DROPFILES   message   from   File   Manager.    
  在窗口创建时调用DragAcceptFiles(TRUE);然后程序处理WM_DROPFILE消息  
  2.循环要一秒钟,什么字符串这么大?CString.Find?Top

2 楼SoLike(思危)回复于 2006-09-07 14:43:00 得分 0

在窗口中响应   WM_DROPFILES   消息Top

3 楼baojian88888(机器人)回复于 2006-09-07 14:45:15 得分 5

拖文件:  
  先给窗口设置WS_EX_ACCEPTFILES风格,然后处理   WM_DROPFILES   消息Top

4 楼SoLike(思危)回复于 2006-09-07 14:45:20 得分 20

Dragging   Files  
   
  Dragging   Files   can   be   supported   relatively   easily   as   follows  
   
                  *   Add   a   OnDropFiles(HDROP   hDropInfo)   handler   to   your   Dialog.   You'll   probably   have   to   add   this   manually,   as   ClassWizard   doesn't   seen   to   support   the   WM_DROPFILES   message   for   dialogs.  
   
          Make   the   following   changes  
   
  1)   In   your   .h   file   add   the   OnDropFiles   to   the   AFX_MSG   section  
   
                                  //   Generated   message   map   functions  
                                  //{{AFX_MSG(A2hDialog)  
                                  ...  
                                  afx_msg   void   OnDropFiles(HDROP   hDropInfo);  
                                  ...  
                                  //}}AFX_MSG  
                                  DECLARE_MESSAGE_MAP()  
   
   
          2)   In   your   .cpp   file   add   the   ON_WM_DROPFILES()   handler   to   the   AFX_MSG_MAP   section  
   
                                  BEGIN_MESSAGE_MAP(MyDialog,   CDialog)  
                                          //{{AFX_MSG_MAP(MyDialog)  
                                          ...  
                                          ON_WM_DROPFILES()  
                                          ...  
                                          //}}AFX_MSG_MAP  
                                  END_MESSAGE_MAP()  
   
   
                  Strangely,   after   doing   (1)   and   (2)   the   results   become   visible   in   the   ClassWizard.  
   
          3)  
                  Use   ClassWizard   to   add   an   OnCreate()   handler   to   your   dialog.   in   this   add   the   call    
   
                                  this->DragAcceptFiles(TRUE);  
   
                  This   enables   Drag   and   drop   of   files   on   your   Dialog's   window.   You   can   check   this   by   dragging   files   over   your   Window.   If   the   cursor   is   a   "no   entry"   sign   (circle   with   a   line   through   it)   it's   not   working.   If   the   cursor   changes   to   a   file/folder   icon   with   a   "+"   on   it,   you're   in   business.    
   
          4)   Manually   add   the   OnDropFiles   method   to   look   something   as   follows   :-  
   
  void   MyDialog::OnDropFiles(HDROP   hDropInfo)  
  {  
   
          HDROP   m_hDropInfo   =   hDropInfo;  
          CString   Filename;  
   
          if   (m_hDropInfo)   {  
   
                  int   iFiles   =   DragQueryFile(m_hDropInfo,   (UINT)-1,   NULL,   0);  
   
                  for   (int   i=0;   i<ifiles;   i++)   {  
   
                          char*   pFilename   =   Filename.GetBuffer(_MAX_PATH);  
                          DragQueryFile(m_hDropInfo,   i,   pFilename,   _MAX_PATH);  
   
                          //   do   whatever...  
   
                  }       //   for   each   files...  
          }               //   if   DropInfo  
   
          DragFinish(m_hDropInfo);  
   
          m_hDropInfo   =   0;  
   
  }       //   End   of   OnDropFiles  
   
  Top

5 楼dch4890164(巴拉克)回复于 2006-09-07 14:45:32 得分 0

楼上两位正确,鉴定完毕,飘过!Top

6 楼kilojin(梅子黄时雨,我在编程时)回复于 2006-09-07 14:47:42 得分 0

一个Log文件,大约10M,现在要统计里面某一个类别Log的数量,LogKey是有的,不过,太多,Find   循环统计,要很长时间  
  我记得Ultraedit里面,有这个功能,一下子就统计出来了,不知道如何实现的  
  Top

7 楼Mackz(在相互)回复于 2006-09-07 16:40:10 得分 5

主要的时间应该在读取文件上了,映射一下。比较必需要循环的,提高效率的方法是在查找上,比如模式匹配。Top

8 楼codewarrior(会思考的草)回复于 2006-09-07 16:59:23 得分 5

关于拖动可以看我的blog.  
  速度快主要是要优化算法,使用映射文件可能会好一点.Top

9 楼immc1979(毛毛虫)回复于 2006-12-06 14:09:31 得分 0

标记一个 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值