"文件对话框" 给你一个hook机会:
void CMainFrame::OnFileDownload()
{ // let the user selects a file name
// which will be sent to a target.
// TODO: Add your command handler code here
char CurDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH,CurDir);
//
if (DownLoadFileName.IsEmpty())
DownLoadFileName=RFileList->m_arrNames[0];
// if m_arrNames[0] also ="" ,then dir=CurDir; fname=""
char drive[MAX_PATH];
char dir[MAX_PATH];
char fname[MAX_PATH];
char ext[10];
_splitpath(DownLoadFileName,drive,dir,fname,ext);
//
CFileDialog fd(TRUE);
fd.m_ofn.lpstrTitle="Down Load File";
fd.m_ofn.lpstrInitialDir=strcat(drive,dir);
fd.m_ofn.lpstrFile=strcat(fname,ext);
fd.m_ofn.lpstrFilter="Any file(*.*)\0*.*\0ARC file (*.arc)\0*.arc\0BMP file (*.bmp)\0*.bmp\0DLL file (*.dll)\0*.dll\0";
if (stricmp(ext,".arc")==0) fd.m_ofn.nFilterIndex=2;
else if (stricmp(ext,".bmp")==0) fd.m_ofn.nFilterIndex=3;
else if (stricmp(ext,".dll")==0) fd.m_ofn.nFilterIndex=4;
else fd.m_ofn.nFilterIndex=1;
fd.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fd.m_ofn.Flags|=OFN_ALLOWMULTISELECT;// must
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!
......
hook程序:
// 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);
}
if (Notify==CDN_FOLDERCHANGE)
{
HWND hLv=GetDlgItem(hWndParent,0x0461);//lst1
if(hLv) SendMessage(hLv,WM_COMMAND,0x7029,0);//ODM_WIEW_ICONS
}
break;
}
return 0;
}