/********************************************************************
created: 2008/07/22
created: 22:7:2008 10:23
filename: SelectDialog.h
file base: SelectDialog
file ext: h
author: Hojjat Bohlooli - software@tarhafarinin.ir purpose: select multiple file and folders together in browse dialog
free for non commercial uses.
*********************************************************************/
#pragma once #include <wtl/atlapp.h>
#include <wtl/atldlgs.h>
#include <wtl/atlctrls.h>
#include <atlstr.h>
#include <vector>
#include <dlgs.h> // for (MULTI)FILEOPENORD
#include <set> using namespace std; // CSelectDialog
class CSelectDialog : public CFileDialogImpl<CSelectDialog>
{
//DECLARE_DYNAMIC(CSelectDialog) public:
CSelectDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
OFN_EXPLORER & (~OFN_SHOWHELP),
LPCTSTR lpszFilter = NULL,
HWND pParentWnd = NULL);
virtual ~CSelectDialog(); BEGIN_MSG_MAP(CSelectDialog)
CHAIN_MSG_MAP(CFileDialogImpl<CSelectDialog>)
END_MSG_MAP() public:
virtual void OnInitDone(LPOFNOTIFY /*lpon*/);
virtual void OnFolderChange(LPOFNOTIFY /*lpon*/);
virtual BOOL OnFileOK(LPOFNOTIFY /*lpon*/);
static LRESULT CALLBACK WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam);
LRESULT OnSelChange(LPOFNOTIFY pnmh);
//DECLARE_MESSAGE_MAP() public:
static CString m_strCurrendDirectory;
static vector<CString> m_SelectedItemList; /*this list includes files and folders
are selected by user. */
static WNDPROC m_wndProc;
};
/********************************************************************
created: 2008/07/22
created: 22:7:2008 10:25
filename: SelectDialog.cpp
file base: SelectDialog
file ext: cpp
author: Hojjat Bohlooli - software@tarhafarinin.ir purpose:
*********************************************************************/
#include "stdafx.h"
#include "SelectDialog.h" #pragma warning( push )
#pragma warning( disable : 4311 4312 )
// CSelectDialog
CString CSelectDialog::m_strCurrendDirectory;
vector<CString> CSelectDialog::m_SelectedItemList;
WNDPROC CSelectDialog::m_wndProc = NULL; CSelectDialog::CSelectDialog(BOOL bOpenFileDialog,
LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags,
LPCTSTR lpszFilter,
HWND hWndParent)
:CFileDialogImpl<CSelectDialog>(
bOpenFileDialog,
lpszDefExt,
lpszFileName,
dwFlags | OFN_EXPLORER | OFN_HIDEREADONLY & (~OFN_SHOWHELP),
lpszFilter,
hWndParent)
{
dwFlags |= (OFN_ENABLEINCLUDENOTIFY | OFN_EXPLORER | OFN_HIDEREADONLY & (~OFN_SHOWHELP));
}; CSelectDialog::~CSelectDialog()
{
};
// CSelectDialog message handlers
BOOL CSelectDialog::OnFileOK(LPOFNOTIFY /*lpon*/)
{
CWindow pWind = GetParent();
if (pWind)
{
CWindow pWnd = pWind.GetDlgItem(lst2); //getting list
if (pWnd == NULL)
return FALSE; m_SelectedItemList.clear(); // emptying list CListViewCtrl wndLst1 = (CListViewCtrl)(pWnd.GetDlgItem()); int nSelected = wndLst1.GetSelectedCount();
if (!nSelected) // nothing selected -- don't retrieve list
return FALSE;
CString strItemText, strDirectory = m_strCurrendDirectory;
if (strDirectory.Right() != _T("\\"))
strDirectory += _T("\\"); CString fileslist = _T("");
pWind.SendMessage(CDM_GETSPEC, (WPARAM)MAX_PATH,
(LPARAM)fileslist.GetBuffer(MAX_PATH));
fileslist.ReleaseBuffer(); strItemText = strDirectory + fileslist;
if(nSelected == && fileslist != _T(""))
{
m_SelectedItemList.push_back(strItemText);
return TRUE;
}
}
::MessageBeep( MB_ICONQUESTION );
return ; //don't let the dialog to close
}; LRESULT CSelectDialog::OnSelChange(LPOFNOTIFY pnmh)
{
ATLASSERT(::IsWindow(m_hWnd));
CString strFolderPath = _T("");
SendMessage(pnmh->hdr.hwndFrom, CDM_GETFILEPATH, (WPARAM)MAX_PATH, (LPARAM)strFolderPath.GetBuffer(MAX_PATH));
strFolderPath.ReleaseBuffer();
DWORD newSelAttr = GetFileAttributes(strFolderPath); CString strLog1;
strLog1 = "======>1";
strLog1 += strFolderPath;
OutputDebugString(strLog1);
if ((newSelAttr != 0xFFFFFFFF) && (newSelAttr & FILE_ATTRIBUTE_DIRECTORY))
{
strFolderPath = strFolderPath.Left(strFolderPath.ReverseFind('\\'));
}
else
{
PathRemoveFileSpec(strFolderPath.GetBuffer(MAX_PATH));
strFolderPath.ReleaseBuffer();
}
if (m_strCurrendDirectory == "")
{
m_strCurrendDirectory = strFolderPath;
} return ;
} void CSelectDialog::OnFolderChange(LPOFNOTIFY /*lpon*/)
{
WCHAR szPath[MAX_PATH]={};
//m_strCurrendDirectory = GetFolderPath();
GetFolderPath(szPath,MAX_PATH);
m_strCurrendDirectory.Format(_T("%s"),szPath);
//CFileDialog::OnFolderChange();
}; void CSelectDialog::OnInitDone(LPOFNOTIFY /*lpon*/)
{
WCHAR szPath[MAX_PATH]={};
//m_strCurrendDirectory = GetFolderPath();
//GetFolderPath(szPath,MAX_PATH);
//m_strCurrendDirectory.Format(_T("%s"),szPath);
CWindow pWind = GetParent(); ////HWND hWnd = pWind.m_hWnd; //HideControl(edt1);
//HideControl(cmb1);
//HideControl(stc2); ////HideControl(cmb13);
////HideControl(stc3); //CRect rectCancel;
//pWind.GetDlgItem(IDCANCEL).GetWindowRect(&rectCancel);
//pWind.ScreenToClient(&rectCancel); //CRect rectOK;
//pWind.GetDlgItem(IDOK).GetWindowRect(&rectOK);
//pWind.ScreenToClient(&rectOK);
//pWind.GetDlgItem(IDOK).SetWindowPos(0,rectCancel.left - rectOK.Width(), rectCancel.top, 0,0, SWP_NOZORDER | SWP_NOSIZE); //CRect rectList2;
//pWind.GetDlgItem(lst1).GetWindowRect(&rectList2);
//pWind.ScreenToClient(&rectList2);
//pWind.GetDlgItem(lst1).SetWindowPos(0,0,0,rectList2.Width(), abs(rectList2.top - (rectCancel.top - 5)), SWP_NOMOVE | SWP_NOZORDER); //CRect rectStatic;
//pWind.GetDlgItem(stc3).GetWindowRect(&rectStatic);
//pWind.ScreenToClient(&rectStatic);
//pWind.GetDlgItem(stc3).SetWindowPos(0,rectCancel.left - 375,rectCancel.top + 5, rectStatic.Width(), rectStatic.Height(), SWP_NOZORDER); //CRect rectEdit1;
//pWind.GetDlgItem(cmb13).GetWindowRect(&rectEdit1);
//pWind.ScreenToClient(&rectEdit1);
//pWind.GetDlgItem(cmb13).SetWindowPos(0,rectCancel.left - 320,rectCancel.top, rectEdit1.Width() - 15, rectEdit1.Height(), SWP_NOZORDER); //SetControlText(stc3, _T("Item name:"));
SetControlText(IDOK, _T("存入云盘")); m_wndProc = (WNDPROC)::SetWindowLong(pWind.m_hWnd, GWL_WNDPROC, (long)WindowProcNew);
pWind.CenterWindow();
SetForegroundWindow(pWind.m_hWnd);
}; LRESULT CALLBACK CSelectDialog::WindowProcNew(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_COMMAND&& HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDOK)
{ if (m_strCurrendDirectory == "")
{
goto Exit;
} m_SelectedItemList.clear(); HWND pWnd = ::GetDlgItem(hwnd,lst2);
if (pWnd == NULL)
{
return FALSE;
}
CListViewCtrl wndLst1 = (CListViewCtrl)(::GetDlgItem(pWnd,)); int nSelected = wndLst1.GetSelectedCount();
if (!nSelected) // nothing selected -- don't retrieve list
return FALSE; HWND pcmbWnd = ::GetDlgItem(hwnd, cmb13);
if (pcmbWnd)
::SetWindowTextW(pcmbWnd, _T("")); int nItem = wndLst1.GetNextItem(-,LVNI_SELECTED); set<int> setSelected; while((nSelected--) > )
{
setSelected.insert(nItem);
BOOL bRet = wndLst1.SetItemState(nItem, ~LVIS_SELECTED , LVIS_SELECTED); nItem = wndLst1.GetNextItem(nItem, LVNI_SELECTED);
} for (std::set<int>::iterator ite = setSelected.begin(); ite != setSelected.end(); ++ite)
{
wndLst1.SetItemState(*ite, LVIS_SELECTED, LVIS_SELECTED); CString strFolderPath = _T("");
SendMessage(hwnd, CDM_GETFILEPATH, (WPARAM)MAX_PATH, (LPARAM)strFolderPath.GetBuffer(MAX_PATH));
strFolderPath.ReleaseBuffer();
DWORD newSelAttr = GetFileAttributes(strFolderPath); CString strLog1;
strLog1 = "======>3";
strLog1 += strFolderPath;
OutputDebugString(strLog1); wndLst1.SetItemState(*ite, ~LVIS_SELECTED, LVIS_SELECTED); } ::EndDialog(hwnd,IDOK);
return NULL;
} Exit:
return CallWindowProc(m_wndProc, hwnd, message, wParam, lParam);
} #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. cordova APP 检查更新

    原文:cordova APP 检查更新 //升级程序 .factory('UpdateService', function ($rootScope, $cordovaAppVersion, $cord ...

  2. Android 它们的定义View

    安卓开发过程,安卓官方控制有时来自往往不能满足我们的需求.这一次,我必须定义自己.下面我们就来看看他们的定义View: package com.example.myview; import andro ...

  3. 线性方程组的求解(C++)

    1. 最佳求解方案 Most efficient way to solve a system of linear equations 求解形如 Ax=b 的最佳方式 将 A 分解为三角矩阵,A=M1⋅ ...

  4. WPF 超长文本的来回滚动

    原文:WPF 超长文本的来回滚动 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Vblegend_2013/article/details/8362 ...

  5. 获取当前电脑的cpu使用率、内存使用率

    https://www.cnblogs.com/Chary/p/7771365.html http://www.cnblogs.com/zl1991/p/4679461.html 要关注几个类 Per ...

  6. 使用xtrabackup实现MySQL主从复制

    环境描写叙述 主从环境 项目 Master Slave OS版本号 SuSE 11sp1 x86_64 SuSE 11sp1 x86_64 MySQL版本号 官方版本号5.5.37 官方版本号5.5. ...

  7. SSH深度历险记(九) Struts2+DWZ+Uploadify多文件(文件和图片等。)上传

    在gxpt_uas系统,为了实现文件(文件和图片等.,灵活配置)批量上传到mongodb,在学习的过程中,知道mongodb,功能,实现思路:在DWZ的基础上參考官方的实例结合现有的GXPT来实现,期 ...

  8. hdu4614 二分法+段树

    意甲冠军:给你1-n花瓶   .起初,所有的空,今天,有两种操作模式, 1:从花瓶a開始插入b朵花          假设不能插进去  输出字符串  否则输出最多插入的起点和终点: 2:把a-b的花瓶 ...

  9. WCF服务的IIS托管(应用程序)

    基本思路 建立与发布参考网站托管 在IIS中某一网站,选择添加应用程序   访问服务uri:http://localhost/wcfAppTest/Service1.svcwcfAppTest/Ser ...

  10. 基于IdentityServer4的单点登录——项目基本结构与流程

    组成 IdentityServer,Api和Client(客户端,asp .net core)本文以官方demo:https://github.com/IdentityServer/IdentityS ...