• 大小: 88KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-04
  • 语言: C/C++
  • 标签: CFolder  

资源简介

CFolderDialog MFC 继承CFiledialog 打开文件夹 老早都想做个这样的功能对话框. 今天刚好看到别人写的代码,就在此基础上增加了些想要的功能, 现分享给有需要的人. 增加功能: 支持输入目录 支持返回选中的文件夹 下次打开时自动使用上次的目录作为起始目录. 如果设置了程序注册表位置 SetRegistryKey(_T("LastFolder")),则下次打开时以最后一次目录为起点

资源截图

代码片段和文件信息

// FolderDialog.cpp : implementation file
//

#include “stdafx.h“

#include “FolderDialog.h“


#include 
#include 

CString CFolderDialog::LastPath;

// CFolderDialog
IMPLEMENT_DYNAMIC(CFolderDialog CFileDialog)

WNDPROC CFolderDialog::m_wndProc = NULL;



BEGIN_MESSAGE_MAP(CFolderDialog CFileDialog)

END_MESSAGE_MAP()



///static unsigned long sLastRtTime;

/***************************
当按下Enter 时
 *************************/

////安全的勾子函数注册



static HHOOK  sgHook;
static int    sgHookUseCnt = 0;



#define  FOLER_PROP    “MyFolderDialogProp“
#define  FOLER_PROPWND    “MyFolderDialogPropWnd“

HWND GetFolderTopWnd(HWND hwnd)
{
    HANDLE h;
    while(1)
    {
        h = GetProp(hwnd FOLER_PROP);
        if (h)
        {
            return hwnd;
        }
        hwnd = GetParent(hwnd);
        if (!hwnd)
        {
            break;
        }
    }
    return NULL;
}


static LRESULT CALLBACK MyKeyboardProc(int nCode      // hook code
                                       WPARAM wParam  // current-process flag
                                       LPARAM lParam   // message data
                                      )
{
    MSG *msg = (MSG *)lParam;

    if (msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN)
    {
        //sgIsKey = TRUE;
        HWND h = GetFolderTopWnd(msg->hwnd);
        if (h)
        {
            SetProp(h FOLER_PROP (void *)2);
        }


        //  TCHAR name[256]={0};
        //  GetClassName(msg->hwndname256);
        //
        //  CRect rc;
        //  GetClientRect(msg->hwndrc);

    }
    else if(msg->message == WM_LBUTTONDOWN)
    {
        HWND h = GetFolderTopWnd(msg->hwnd);
        if (h && GetDlgCtrlID(msg->hwnd) == IDOK)
        {
            SetProp(h FOLER_PROP (void *)1);
        }

    }

    LRESULT l = CallNextHookEx(sgHook nCode wParam lParam);

    return l;
}




// Function name    : WindowProcNew
// Description      : Call this function when user navigate into CFileDialog.
// Return type      : LRESULT
// Argument         : HWND hwnd
// Argument         : UINT message
// Argument         : WPARAM wParam
// Argument         : LPARAM lParam
LRESULT CALLBACK CFolderDialog::WindowProcNew(HWND hwnd UINT message WPARAM wParam LPARAM lParam)
{
    if(message ==  WM_COMMAND)
    {
        if(HIWORD(wParam) == BN_CLICKED)
        {
            if(LOWORD(wParam) == IDOK)
            {

                int  v = (int)GetProp(hwnd FOLER_PROP);

                if(v != 2)
                {
                    CFolderDialog *pDlg = (CFolderDialog *)::GetProp(hwnd FOLER_PROPWND);
                    if (pDlg)
                    {
                        pDlg->UpDatePath();
                    }
                    pDlg = (CFolderDialog *)::CWnd::FromHandle(hwnd);
                    if (pDlg)
                    {
                

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9373  2017-04-01 17:19  StadyFolderDialog\Debug\MyBotton.obj

     文件       6779  2017-04-01 17:35  StadyFolderDialog\FolderDialog.cpp

     文件        893  2017-04-01 17:41  StadyFolderDialog\FolderDialog.h

     文件       3777  2017-04-01 09:09  StadyFolderDialog\ReadMe.txt

     文件       1078  2017-04-01 09:09  StadyFolderDialog\res\StadyFolderDialog.ico

     文件        409  2017-04-01 09:09  StadyFolderDialog\res\StadyFolderDialog.rc2

     文件        557  2017-04-01 17:19  StadyFolderDialog\resource.h

     文件      34916  2017-04-01 17:19  StadyFolderDialog\StadyFolderDialog.aps

     文件       1168  2017-04-01 17:41  StadyFolderDialog\StadyFolderDialog.clw

     文件       2217  2017-04-01 09:09  StadyFolderDialog\StadyFolderDialog.cpp

     文件       4464  2017-04-01 17:42  StadyFolderDialog\StadyFolderDialog.dsp

     文件        557  2017-04-01 09:09  StadyFolderDialog\StadyFolderDialog.dsw

     文件       1445  2017-04-01 09:09  StadyFolderDialog\StadyFolderDialog.h

     文件     198656  2017-04-01 17:42  StadyFolderDialog\StadyFolderDialog.opt

     文件       1978  2017-04-01 17:41  StadyFolderDialog\StadyFolderDialog.plg

     文件        384  2017-04-01 17:42  StadyFolderDialog\StadyFolderDialog.positions

     文件       4628  2017-04-01 17:19  StadyFolderDialog\StadyFolderDialog.rc

     文件       2878  2017-04-01 17:19  StadyFolderDialog\StadyFolderDialogDlg.cpp

     文件       1442  2017-04-01 17:19  StadyFolderDialog\StadyFolderDialogDlg.h

     文件        219  2017-04-01 09:09  StadyFolderDialog\StdAfx.cpp

     文件       1054  2017-04-01 09:09  StadyFolderDialog\StdAfx.h

     目录          0  2017-04-01 17:41  StadyFolderDialog\Debug

     目录          0  2017-04-01 17:41  StadyFolderDialog\Release

     目录          0  2017-04-01 09:09  StadyFolderDialog\res

     目录          0  2017-04-01 17:42  StadyFolderDialog

     文件      24576  2017-04-01 17:43  StadyFolderDialog.exe

----------- ---------  ---------- -----  ----

               303448                    26


评论

共有 条评论