1. /********************************************************************
  2. created: 2008/07/22
  3. created: 22:7:2008 10:23
  4. filename: SelectDialog.h
  5. file base: SelectDialog
  6. file ext: h
  7. author: Hojjat Bohlooli - software@tarhafarinin.ir
  8.  
  9. purpose: select multiple file and folders together in browse dialog
  10. free for non commercial uses.
  11. *********************************************************************/
  12. #pragma once
  13.  
  14. #include <wtl/atlapp.h>
  15. #include <wtl/atldlgs.h>
  16. #include <wtl/atlctrls.h>
  17. #include <atlstr.h>
  18. #include <vector>
  19. #include <dlgs.h> // for (MULTI)FILEOPENORD
  20. #include <set>
  21.  
  22. using namespace std;
  23.  
  24. // CSelectDialog
  25. class CSelectDialog : public CFileDialogImpl<CSelectDialog>
  26. {
  27. //DECLARE_DYNAMIC(CSelectDialog)
  28.  
  29. public:
  30. CSelectDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
  31. LPCTSTR lpszDefExt = NULL,
  32. LPCTSTR lpszFileName = NULL,
  33. DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
  34. OFN_EXPLORER & (~OFN_SHOWHELP),
  35. LPCTSTR lpszFilter = NULL,
  36. HWND pParentWnd = NULL);
  37. virtual ~CSelectDialog();
  38.  
  39. BEGIN_MSG_MAP(CSelectDialog)
  40. CHAIN_MSG_MAP(CFileDialogImpl<CSelectDialog>)
  41. END_MSG_MAP()
  42.  
  43. public:
  44. virtual void OnInitDone(LPOFNOTIFY /*lpon*/);
  45. virtual void OnFolderChange(LPOFNOTIFY /*lpon*/);
  46. virtual BOOL OnFileOK(LPOFNOTIFY /*lpon*/);
  47. static LRESULT CALLBACK WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam);
  48. LRESULT OnSelChange(LPOFNOTIFY pnmh);
  49. //DECLARE_MESSAGE_MAP()
  50.  
  51. public:
  52. static CString m_strCurrendDirectory;
  53. static vector<CString> m_SelectedItemList; /*this list includes files and folders
  54. are selected by user. */
  55. static WNDPROC m_wndProc;
  56. };
  1. /********************************************************************
  2. created: 2008/07/22
  3. created: 22:7:2008 10:25
  4. filename: SelectDialog.cpp
  5. file base: SelectDialog
  6. file ext: cpp
  7. author: Hojjat Bohlooli - software@tarhafarinin.ir
  8.  
  9. purpose:
  10. *********************************************************************/
  11. #include "stdafx.h"
  12. #include "SelectDialog.h"
  13.  
  14. #pragma warning( push )
  15. #pragma warning( disable : 4311 4312 )
  16. // CSelectDialog
  17. CString CSelectDialog::m_strCurrendDirectory;
  18. vector<CString> CSelectDialog::m_SelectedItemList;
  19. WNDPROC CSelectDialog::m_wndProc = NULL;
  20.  
  21. CSelectDialog::CSelectDialog(BOOL bOpenFileDialog,
  22. LPCTSTR lpszDefExt,
  23. LPCTSTR lpszFileName,
  24. DWORD dwFlags,
  25. LPCTSTR lpszFilter,
  26. HWND hWndParent)
  27. :CFileDialogImpl<CSelectDialog>(
  28. bOpenFileDialog,
  29. lpszDefExt,
  30. lpszFileName,
  31. dwFlags | OFN_EXPLORER | OFN_HIDEREADONLY & (~OFN_SHOWHELP),
  32. lpszFilter,
  33. hWndParent)
  34. {
  35. dwFlags |= (OFN_ENABLEINCLUDENOTIFY | OFN_EXPLORER | OFN_HIDEREADONLY & (~OFN_SHOWHELP));
  36. };
  37.  
  38. CSelectDialog::~CSelectDialog()
  39. {
  40. };
  41. // CSelectDialog message handlers
  42. BOOL CSelectDialog::OnFileOK(LPOFNOTIFY /*lpon*/)
  43. {
  44. CWindow pWind = GetParent();
  45. if (pWind)
  46. {
  47. CWindow pWnd = pWind.GetDlgItem(lst2); //getting list
  48. if (pWnd == NULL)
  49. return FALSE;
  50.  
  51. m_SelectedItemList.clear(); // emptying list
  52.  
  53. CListViewCtrl wndLst1 = (CListViewCtrl)(pWnd.GetDlgItem());
  54.  
  55. int nSelected = wndLst1.GetSelectedCount();
  56. if (!nSelected) // nothing selected -- don't retrieve list
  57. return FALSE;
  58. CString strItemText, strDirectory = m_strCurrendDirectory;
  59. if (strDirectory.Right() != _T("\\"))
  60. strDirectory += _T("\\");
  61.  
  62. CString fileslist = _T("");
  63. pWind.SendMessage(CDM_GETSPEC, (WPARAM)MAX_PATH,
  64. (LPARAM)fileslist.GetBuffer(MAX_PATH));
  65. fileslist.ReleaseBuffer();
  66.  
  67. strItemText = strDirectory + fileslist;
  68. if(nSelected == && fileslist != _T(""))
  69. {
  70. m_SelectedItemList.push_back(strItemText);
  71. return TRUE;
  72. }
  73. }
  74. ::MessageBeep( MB_ICONQUESTION );
  75. return ; //don't let the dialog to close
  76. };
  77.  
  78. LRESULT CSelectDialog::OnSelChange(LPOFNOTIFY pnmh)
  79. {
  80. ATLASSERT(::IsWindow(m_hWnd));
  81. CString strFolderPath = _T("");
  82. SendMessage(pnmh->hdr.hwndFrom, CDM_GETFILEPATH, (WPARAM)MAX_PATH, (LPARAM)strFolderPath.GetBuffer(MAX_PATH));
  83. strFolderPath.ReleaseBuffer();
  84. DWORD newSelAttr = GetFileAttributes(strFolderPath);
  85.  
  86. CString strLog1;
  87. strLog1 = "======>1";
  88. strLog1 += strFolderPath;
  89. OutputDebugString(strLog1);
  90. if ((newSelAttr != 0xFFFFFFFF) && (newSelAttr & FILE_ATTRIBUTE_DIRECTORY))
  91. {
  92. strFolderPath = strFolderPath.Left(strFolderPath.ReverseFind('\\'));
  93. }
  94. else
  95. {
  96. PathRemoveFileSpec(strFolderPath.GetBuffer(MAX_PATH));
  97. strFolderPath.ReleaseBuffer();
  98. }
  99. if (m_strCurrendDirectory == "")
  100. {
  101. m_strCurrendDirectory = strFolderPath;
  102. }
  103.  
  104. return ;
  105. }
  106.  
  107. void CSelectDialog::OnFolderChange(LPOFNOTIFY /*lpon*/)
  108. {
  109. WCHAR szPath[MAX_PATH]={};
  110. //m_strCurrendDirectory = GetFolderPath();
  111. GetFolderPath(szPath,MAX_PATH);
  112. m_strCurrendDirectory.Format(_T("%s"),szPath);
  113. //CFileDialog::OnFolderChange();
  114. };
  115.  
  116. void CSelectDialog::OnInitDone(LPOFNOTIFY /*lpon*/)
  117. {
  118. WCHAR szPath[MAX_PATH]={};
  119. //m_strCurrendDirectory = GetFolderPath();
  120. //GetFolderPath(szPath,MAX_PATH);
  121. //m_strCurrendDirectory.Format(_T("%s"),szPath);
  122. CWindow pWind = GetParent();
  123.  
  124. ////HWND hWnd = pWind.m_hWnd;
  125.  
  126. //HideControl(edt1);
  127. //HideControl(cmb1);
  128. //HideControl(stc2);
  129.  
  130. ////HideControl(cmb13);
  131. ////HideControl(stc3);
  132.  
  133. //CRect rectCancel;
  134. //pWind.GetDlgItem(IDCANCEL).GetWindowRect(&rectCancel);
  135. //pWind.ScreenToClient(&rectCancel);
  136.  
  137. //CRect rectOK;
  138. //pWind.GetDlgItem(IDOK).GetWindowRect(&rectOK);
  139. //pWind.ScreenToClient(&rectOK);
  140. //pWind.GetDlgItem(IDOK).SetWindowPos(0,rectCancel.left - rectOK.Width(), rectCancel.top, 0,0, SWP_NOZORDER | SWP_NOSIZE);
  141.  
  142. //CRect rectList2;
  143. //pWind.GetDlgItem(lst1).GetWindowRect(&rectList2);
  144. //pWind.ScreenToClient(&rectList2);
  145. //pWind.GetDlgItem(lst1).SetWindowPos(0,0,0,rectList2.Width(), abs(rectList2.top - (rectCancel.top - 5)), SWP_NOMOVE | SWP_NOZORDER);
  146.  
  147. //CRect rectStatic;
  148. //pWind.GetDlgItem(stc3).GetWindowRect(&rectStatic);
  149. //pWind.ScreenToClient(&rectStatic);
  150. //pWind.GetDlgItem(stc3).SetWindowPos(0,rectCancel.left - 375,rectCancel.top + 5, rectStatic.Width(), rectStatic.Height(), SWP_NOZORDER);
  151.  
  152. //CRect rectEdit1;
  153. //pWind.GetDlgItem(cmb13).GetWindowRect(&rectEdit1);
  154. //pWind.ScreenToClient(&rectEdit1);
  155. //pWind.GetDlgItem(cmb13).SetWindowPos(0,rectCancel.left - 320,rectCancel.top, rectEdit1.Width() - 15, rectEdit1.Height(), SWP_NOZORDER);
  156.  
  157. //SetControlText(stc3, _T("Item name:"));
  158. SetControlText(IDOK, _T("存入云盘"));
  159.  
  160. m_wndProc = (WNDPROC)::SetWindowLong(pWind.m_hWnd, GWL_WNDPROC, (long)WindowProcNew);
  161. pWind.CenterWindow();
  162. SetForegroundWindow(pWind.m_hWnd);
  163. };
  164.  
  165. LRESULT CALLBACK CSelectDialog::WindowProcNew(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  166. {
  167. if (message == WM_COMMAND&& HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDOK)
  168. {
  169.  
  170. if (m_strCurrendDirectory == "")
  171. {
  172. goto Exit;
  173. }
  174.  
  175. m_SelectedItemList.clear();
  176.  
  177. HWND pWnd = ::GetDlgItem(hwnd,lst2);
  178. if (pWnd == NULL)
  179. {
  180. return FALSE;
  181. }
  182. CListViewCtrl wndLst1 = (CListViewCtrl)(::GetDlgItem(pWnd,));
  183.  
  184. int nSelected = wndLst1.GetSelectedCount();
  185. if (!nSelected) // nothing selected -- don't retrieve list
  186. return FALSE;
  187.  
  188. HWND pcmbWnd = ::GetDlgItem(hwnd, cmb13);
  189. if (pcmbWnd)
  190. ::SetWindowTextW(pcmbWnd, _T(""));
  191.  
  192. int nItem = wndLst1.GetNextItem(-,LVNI_SELECTED);
  193.  
  194. set<int> setSelected;
  195.  
  196. while((nSelected--) > )
  197. {
  198. setSelected.insert(nItem);
  199. BOOL bRet = wndLst1.SetItemState(nItem, ~LVIS_SELECTED , LVIS_SELECTED);
  200.  
  201. nItem = wndLst1.GetNextItem(nItem, LVNI_SELECTED);
  202. }
  203.  
  204. for (std::set<int>::iterator ite = setSelected.begin(); ite != setSelected.end(); ++ite)
  205. {
  206. wndLst1.SetItemState(*ite, LVIS_SELECTED, LVIS_SELECTED);
  207.  
  208. CString strFolderPath = _T("");
  209. SendMessage(hwnd, CDM_GETFILEPATH, (WPARAM)MAX_PATH, (LPARAM)strFolderPath.GetBuffer(MAX_PATH));
  210. strFolderPath.ReleaseBuffer();
  211. DWORD newSelAttr = GetFileAttributes(strFolderPath);
  212.  
  213. CString strLog1;
  214. strLog1 = "======>3";
  215. strLog1 += strFolderPath;
  216. OutputDebugString(strLog1);
  217.  
  218. wndLst1.SetItemState(*ite, ~LVIS_SELECTED, LVIS_SELECTED);
  219.  
  220. }
  221.  
  222. ::EndDialog(hwnd,IDOK);
  223. return NULL;
  224. }
  225.  
  226. Exit:
  227. return CallWindowProc(m_wndProc, hwnd, message, wParam, lParam);
  228. }
  229.  
  230. #pragma warning( pop )

文件文件夹混合多选对话框(修改GWL_WNDPROC)的更多相关文章

  1. Linux如何修改文件/文件夹内所有文件的权限

    一.修改文件权限 修改文件权限前,需要了解一下权限中的”rwx”与数字的对应关系,其中r=4,w=2,x=1. 例如:”drwxr-xr-x”,第一个”d”是代表文件夹,这里不用考虑,后面九个字符,每 ...

  2. Linux使用touch批量修改文件/文件夹时间戳

      Linux下touch是一个非常有用的命令. touch语法结构如下: touch [-acfm][-d <日期时间>][-r <参考文件或目录>][-t <日期时间 ...

  3. Python小代码_15_遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间

    遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间 import osimport datetime def print_tree(dir_path): for ...

  4. Android文件/文件夹选择器(支持多选操作),已封装为lib库,直接添加依赖即可。

    话不多少,先上图一览: 接下来我们开始写个app测试: 1.新建Android工程:FileSelectorTest 2.更改MainActivity: 在里面写四个textview模拟button, ...

  5. 【转】C#添加修改删除文件文件夹大全

    [转]C#添加修改删除文件文件夹大全 C#添加修改删除文件文件夹大全 StreamWriter sw = File.AppendText(Server.MapPath(".")+& ...

  6. 修改Atom 隐藏.gitignore忽略的文件/文件夹的配置

    参考链接:.gitignored files are hidden from tree view regardless of setting 假如Atom打开的文件夹有.gitignore 文件,会隐 ...

  7. windows文件关联、打开方式列表之修改注册表攻略

    这里全是修改注册表的方式.网上找了半天,有的仅有添加文件关联的方法,却没有添加到打开方式列表里面的方法:有的有添加到文件列表的方法,却是使 用控制面板->文件夹选项的.好难得才找齐所有,从添加文 ...

  8. linux下SVN忽略文件/文件夹的方法

    linux下SVN忽略文件/文件夹的方法 假设想忽略文件temp 1. cd到temp所在的目录下: 2. svn propedit svn:ignore . 注意:请别漏掉最后的点(.表示当前目录) ...

  9. 用C#操作文件/文件夹(删除,复制,移动)

    操作某一个文件/文件夹,需要一个文件的完整路径 一.使用File的静态方法进行文件操作 //使用file的静态方法进行复制 File.Copy(path, destpath); //使用File的静态 ...

随机推荐

  1. 【14.94%】【codeforces 611E】New Year and Three Musketeers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. Objective-C 数据类型 (一)

    数据类型分为三类:基本数据类型,对象类型,id类型. 基本数据类型:int ,float double char 对象类型:类,指针对象,协议 id类型:可以表示对象类型(在表示对象类型的时候 不需要 ...

  3. class helper 可能是从 Delphi 2007 增加的新语法

    class helper 可能是从 Delphi 2007 增加的新语法, 因为感觉不太实用, 直到今天才测试了一下. 试过之后才知道: 挺有意思的! 基本功能就是修改已存在的类. Txxx = cl ...

  4. Android的PVPlayer介绍

    1 Player的组成 OpenCore的Player的编译文件是pvplayer/Android.mk,将生成动态库文件 libopencoreplayer.so.这个库包括了双方面的内容:一方是P ...

  5. linux每个路由表的系统研究

        linux那里0~255干脆256张路由表.间0这并不表示unspec(未指定),253.254,255分别default.main.local表. 除了以上4张表外的其它表都是留给用户指定的 ...

  6. 在IIS上部署.net core的webapi项目 以及502.5错误的两种解决方法

    首先要在服务器上面安装.net core https://github.com/dotnet/core/tree/master/release-notes/download-archives 这里面有 ...

  7. codeforces Round #259(div2) D解决报告

    D. Little Pony and Harmony Chest time limit per test 4 seconds memory limit per test 256 megabytes i ...

  8. crossplatform---Nodejs in Visual Studio Code 01.简单介绍Nodejs

    1.开始 作者自己:开发人员,Asp.Net , html / js , restful , memcached , oracle ,windows , iis 目标读者:供自己以后回顾 2.我看No ...

  9. React HOC

    在React官网文档学习React HOC,整个看了一遍还是云里雾里的,于是按照官网文档,自己动手实践一下.官网地址:React 高阶组件 定义:高阶组件就是一个函数,且该函数接受一个组件作为参数,并 ...

  10. C和指针 (pointers on C)——第十二章:利用结构和指针

    第十二章 利用结构和指针 这章就是链表.先单链表,后双向链表. 总结: 单链表是一种使用指针来存储值的数据结构.链表中的每一个节点包括一个字段,用于指向链表的下一个节点. 有一个独立的根指针指向链表的 ...