文件对话框求助

Yellow_Tail 2015-05-03 12:43:24
我在MFC里添加了一个webbrowser控件,某个网页里面有一个上传文件的按钮,我点了之后,
会弹出来一个文件对话框,我想要hook它,以便能够在网页得到这个路径之前修改这个路径值。
请教大家,有没有什么方法?
...全文
149 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2015-05-04
  • 打赏
  • 举报
回复
这个 hook 只能针对系统的 cfiledialog, 不是自己建的对话框
Yellow_Tail 2015-05-03
  • 打赏
  • 举报
回复
在http://ask.csdn.net/ 上,有人回答说kook GetOpenFileName, 我hook了之后,写了几行代码调试,在我写的hook函数里下断点

CFileDialog cf(TRUE,NULL,NULL,0,NULL,this); 
 cf.DoModal();
 CString strFilePath=cf.GetPathName();
GetOpenFileName(NULL);
发现前3句没有断下来,最后一句可以断下来, 那看来不是HOOK 这个GetOpenFileName API了
Yellow_Tail 2015-05-03
  • 打赏
  • 举报
回复
引用 4 楼 schlafenhamster 的回复:
1 OnFileDownload() 这个是webbrowser的FileDownload事件处理函数吗 不是, 是个按钮 的 响应 不要自己再派生类了.
这个hook是不是只能针对自己建的对话框,对于不是按照你说的办法建的对话框,是不是就没有效果了?
schlafenhamster 2015-05-03
  • 打赏
  • 举报
回复
1 OnFileDownload() 这个是webbrowser的FileDownload事件处理函数吗 不是, 是个按钮 的 响应 2 cfiledialog里面有个成员结构体m_ofn,里面有个lpfnHook, 这个就是cfiledialog留给你的 hook 程序. 不要自己再派生类了.
Yellow_Tail 2015-05-03
  • 打赏
  • 举报
回复
引用 2 楼 schlafenhamster 的回复:
"文件对话框" 给你一个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; }
有几个问题: 1.void CMainFrame::OnFileDownload() 这个是webbrowser的FileDownload事件处理函数吗? 2.你加红部分的代码是代表,cfiledialog里面有个成员结构体m_ofn,里面有个lpfnHook,所以说这个hook只能在自己新建的 cfiledialog里实现吗?
schlafenhamster 2015-05-03
  • 打赏
  • 举报
回复
"文件对话框" 给你一个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; }

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧