如何在CFiledialog运行以后动态修改,文件过滤条件,如,修改选中第几个下拉选择项增加、减少下拉选择项

解决方案 »

  1.   

    派生 CFileDialog,处理 m_ofn.lpstrFilter
      

  2.   

    m_ofn有个成员:
    LPOFNHOOKPROC lpfnHook
    使用它可以动态改变filter。以前的代码一下找不到了。你看看书吧
      

  3.   

    大概是:
    fd.m_ofn.lpfnHook=DNHookProc;
    //
    ///////////////////////////////////////////////////////
    // for CFileDialog down load 
    // in debug version there is an error : ASSERT(m_p...==NULL)
    UINT CALLBACK DNHookProc(HWND hDlg,UINT uMsg,WPARAM wPar,LPARAM lPar)
    { // hdlg is a child 
    HWND hWndParent;
    CWinApp *pApp=AfxGetApp();
    HICON hIcon;
    HWND        hw; // SHELLDll_defView
    HWND        hcw;// SysListView32
    DWORD       dwStyle;
    //
    if (hDlg == NULL) return 0;
    // from "_AfxCommDlgProc()" of the file "dlgcomm.cpp"
    _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
    if (pThreadState->m_pAlternateWndInit != NULL)
    // not  pThreadState->m_pAlternateWndInit->SubclassWindow(hWnd);
    pThreadState->m_pAlternateWndInit = NULL;
    //
    hWndParent=GetParent(hDlg);// needed
       switch (uMsg)
       {
          case WM_INITDIALOG:
    hIcon=pApp->LoadIcon(IDI_ICONDN);
    SendMessage(hWndParent,WM_SETICON,(WPARAM)0,(LPARAM)hIcon);
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
    DestroyIcon(hIcon);
      break;
          case WM_NOTIFY:
        LPOFNOTIFY lpon=(LPOFNOTIFY)lPar; 
    UINT Notify=lpon->hdr.code;
    if (Notify==CDN_TYPECHANGE ||
    Notify==CDN_SELCHANGE  )
    { // after window shown
    hw=GetDlgItem(hWndParent,0x0461);// SHELLDll_defView
    hcw=GetDlgItem(hw,1);// SysListView32
    dwStyle=GetWindowLong(hcw,GWL_STYLE);
    // change multi-selection of ListView
    if (lpon->lpOFN->nFilterIndex==4) // "dll"
    {
    dwStyle &= ~LVS_SINGLESEL;// Multi
    }
    else
    {
    dwStyle |= LVS_SINGLESEL;// Single
    }
    SetWindowLong(hcw,GWL_STYLE,dwStyle);
    }
      break;
       }
       return 0;
    }
      

  4.   

    没办法,需求就是这样
    为了解决此问题,确实写了派生类,试图重载Domodal,结果发现不行
    初始时是指定了m_ofn.lpstrFilter,但是有要求在查找过程中,突然想新增类型或减少类型
    看到msdn上有提到过nfhookProc,与发消息有关,但是发消息老是不对LPOFNHOOKPROC lpfnHook能否给个例子?? 
      

  5.   


            CFileDialog fileDlg(TRUE,".a",cs,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"文件类型1 (*.a)|*.a|文件类型2(*.b)|*.b|所有文件  (*.*)|*.*||");
    fileDlg.m_ofn.lpstrTitle = "打开";
    fileDlg.m_ofn.lpstrInitialDir = ".\\aa\\";
    fileDlg.DoModal();这样就可以在弹出的文件对话框中有多个类型的选择了。
      

  6.   

    schlafenhamster
    先谢谢了可能我昨天晚上打开时没有刷新,没看到你回复的例子我先看看
    Thanks
      

  7.   

    schlafenhamster 的回复大家值得珍藏!========================================
    提界面问题,UIPower有问必答!
    界面论坛:http://www.uipower.com/bbsCSDN近期采访了UIPower的CEO阙海忠,
    视频地址:http://live.csdn.net/Issue961/LivePlay.aspx
      

  8.   

    能再问下钩子函数怎么把WM_InitDialog消息或者我不想拦截的消息发回去呢
    我这里不处理,好象原来的消息丢了
      

  9.   

    schlafenhamster:不想拦截的消息不要管。 我也不想多余处理啊
    但是,OnInitDialog()就是进不去,不执行
    用了DefWindowProc(...)也不行,想不通
      

  10.   

    CComboBox* pCmb1 = (CComboBox*)(GetParent()->GetDlgItem(cmb1));  
    if (nFind == CB_ERR && bCheck)
    {
           pCmb1->InsertString(iType, szFilter[iType]);
    }可不可以在这里做些处理呢??
     
    这样新增的虽然可以加到下拉列表框,但是选择新增类型时会死掉,在前面修改m_ofn.lpstrFilter值也是一样
      

  11.   

    恩,谢谢大家了
    问题解决了,OnInitDialog()就是进不去,采用其他折中办法
      

  12.   

    可能初始化不对
    fd.m_ofn.Flags|=OFN_EXPLORER;  // default by Afx
    //fd.m_ofn.Flags|=OFN_ENABLEHOOK;// default by Afx
    fd.m_ofn.lpfnHook=DNHookProc;//="_AfxCommDlgProc" see"dlgcomm.cpp" <>NULL!
      

  13.   

    询问楼主是怎么解决的这个问题啊?我现在也有动态更改Filter的需求搞不定啊