// these two line hooks GetSaveFileName api calls to our own implementation { CAPIHook hkGetSaveFileNameA( "comdlg32.dll", "GetSaveFileNameA", (PROC)Hook_GetSaveFileNameA, FALSE); CAPIHook hkGetSaveFileNameW( "comdlg32.dll", "GetSaveFileNameW", (PROC)Hook_GetSaveFileNameW, FALSE);
// as we hooked the common dialog, no save as prompt dialog pops up pIE->ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER, NULL, NULL); // god save me! this line involves so much work...
}// this bracket ends the two CAPIHook variable
DLGPROC g_pfnOldHook; // the original dialog hook provided by IE
// notifies ie that we chose another file type OFNOTIFY ofn; ofn = *pOFN; ofn.hdr.code = CDN_TYPECHANGE; g_pfnOldHook(hdlg, uiMsg, wParam, (LPARAM)&ofn);
// Closes the dialog before anyone see it! HWND hParent = GetParent(hdlg); PostMessageW(hParent, WM_COMMAND, IDOK, NULL); return rev; } }
// call IE's original hook function return g_pfnOldHook(hdlg, uiMsg, wParam, lParam); }
BOOL APIENTRY Hook_GetSaveFileNameA(LPOPENFILENAMEA pOF) { MessageBox(NULL, "this piece of code has not been tested, please contact the developer.", NULL, MB_OK);
pFilter += strlen(pFilter) + 1; int nExt = strlen(pFilter); char* pExt = new char(nExt+1); for(int i = 0; i < nExt; i++) pExt[i] = tolower(pFilter[i]);
GetTempPath(_MAX_PATH, szTempMhtFile);
strcat(szTempMhtFile, "NEXTMP.mht");
// these two line hooks GetSaveFileName api calls to our own implementation
{
CAPIHook hkGetSaveFileNameA(
"comdlg32.dll",
"GetSaveFileNameA",
(PROC)Hook_GetSaveFileNameA,
FALSE);
CAPIHook hkGetSaveFileNameW(
"comdlg32.dll",
"GetSaveFileNameW",
(PROC)Hook_GetSaveFileNameW,
FALSE);
pGetSaveFileNameA = (PFNGETSAVEFILENAMEA)(PROC) hkGetSaveFileNameA;
pGetSaveFileNameW = (PFNGETSAVEFILENAMEW)(PROC) hkGetSaveFileNameW;
// as we hooked the common dialog, no save as prompt dialog pops up
pIE->ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER, NULL, NULL);
// god save me! this line involves so much work...
}// this bracket ends the two CAPIHook variable
DLGPROC g_pfnOldHook; // the original dialog hook provided by IE
UINT_PTR CALLBACK OFNMyHookProc(
HWND hdlg, // handle to child dialog box
UINT uiMsg, // message identifier
WPARAM wParam, // message parameter
LPARAM lParam // message parameter
)
{
if(uiMsg == WM_INITDIALOG)
{
// hide it :-)
HWND hParent = GetParent(hdlg);
RECT rc;
GetWindowRect(hParent, &rc);
OffsetRect(&rc, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
MoveWindow(hParent, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
else if(uiMsg == WM_NOTIFY)
{
LPOFNOTIFY pOFN = (LPOFNOTIFY)lParam;
if(pOFN->hdr.code == CDN_INITDONE)
{
// so init is done, and ie has got enough information
UINT_PTR rev = g_pfnOldHook(hdlg, uiMsg, wParam, lParam);
// notifies ie that we chose another file type
OFNOTIFY ofn;
ofn = *pOFN;
ofn.hdr.code = CDN_TYPECHANGE;
g_pfnOldHook(hdlg, uiMsg, wParam, (LPARAM)&ofn);
// Closes the dialog before anyone see it!
HWND hParent = GetParent(hdlg);
PostMessageW(hParent, WM_COMMAND, IDOK, NULL);
return rev;
}
}
// call IE's original hook function
return g_pfnOldHook(hdlg, uiMsg, wParam, lParam);
}
BOOL APIENTRY Hook_GetSaveFileNameA(LPOPENFILENAMEA pOF)
{
MessageBox(NULL, "this piece of code has not been tested, please contact the developer.", NULL, MB_OK);
g_pfnOldHook = (DLGPROC)pOF->lpfnHook;
pOF->lpfnHook = OFNMyHookProc;
if(pOF->nMaxFile <= strlen(szTempMhtFile))
{
pOF->nMaxFile = strlen(szTempMhtFile) + 1;
return FNERR_BUFFERTOOSMALL;
}
strcpy(pOF->lpstrFile, szTempMhtFile);
pOF->Flags |= OFN_EXTENSIONDIFFERENT;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath(szTempMhtFile, drive, dir, fname, ext);
if(pOF->nMaxFileTitle)
{
if(pOF->nMaxFileTitle <= strlen(fname) + strlen(ext))
{
pOF->nMaxFileTitle = strlen(fname) + strlen(ext) + 1;
return FNERR_BUFFERTOOSMALL;
}
strcpy(pOF->lpstrFileTitle, _bstr_t(fname));
strcat(pOF->lpstrFileTitle, _bstr_t(ext));
}
pOF->nFileOffset = strlen(drive) + strlen(dir);
pOF->nFileExtension = pOF->nFileOffset + strlen(fname) + 1;
int nIndex = 0;
LPCSTR pFilter = pOF->lpstrFilter;
bool bFound = false;
while(strlen(pFilter))
{
nIndex ++;
pFilter += strlen(pFilter) + 1;
int nExt = strlen(pFilter);
char* pExt = new char(nExt+1);
for(int i = 0; i < nExt; i++)
pExt[i] = tolower(pFilter[i]);
if(strstr(pExt, "*.mht"))
{
delete[] pExt;
bFound = true;
break;
}
delete[] pExt;
pFilter += nExt + 1;
}
assert(bFound);
pOF->nFilterIndex = nIndex;
return pGetSaveFileNameA(pOF);
}
BOOL APIENTRY Hook_GetSaveFileNameW(LPOPENFILENAMEW pOF)
{
g_pfnOldHook = (DLGPROC)pOF->lpfnHook;
pOF->lpfnHook = OFNMyHookProc;
if(pOF->nMaxFile <= strlen(szTempMhtFile))
{
pOF->nMaxFile = strlen(szTempMhtFile) + 1;
return FNERR_BUFFERTOOSMALL;
}
wcscpy(pOF->lpstrFile, _bstr_t(szTempMhtFile));
pOF->Flags |= OFN_EXTENSIONDIFFERENT;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath(szTempMhtFile, drive, dir, fname, ext);
if(pOF->nMaxFileTitle)
{
if(pOF->nMaxFileTitle <= strlen(fname) + strlen(ext))
{
pOF->nMaxFileTitle = strlen(fname) + strlen(ext) + 1;
return FNERR_BUFFERTOOSMALL;
}
wcscpy(pOF->lpstrFileTitle, _bstr_t(fname));
wcscat(pOF->lpstrFileTitle, _bstr_t(ext));
}
pOF->nFileOffset = strlen(drive) + strlen(dir);
pOF->nFileExtension = pOF->nFileOffset + strlen(fname) + 1;
int nIndex = 0;
LPCWSTR pFilter = pOF->lpstrFilter;
bool bFound = false;
while(wcslen(pFilter))
{
nIndex ++;
pFilter += wcslen(pFilter) + 1;
int nExt = wcslen(pFilter);
wchar_t* pExt = (wchar_t*)malloc(sizeof(wchar_t)*(nExt+1));
for(int i = 0; i <= nExt; i++)
pExt[i] = towlower(pFilter[i]);
if(wcsstr(pExt, L".mht"))
{
free(pExt);
bFound = true;
break;
}
free(pExt);
pFilter += nExt + 1;
}
assert(bFound);
pOF->nFilterIndex = nIndex;
return pGetSaveFileNameW(pOF);
}
1. <object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object> 2. 调用方法:
WebBrowser.ExecWB nCmdID, nCmdExecOpt, [pvaIn], [pvaOut] 3. 参数说明:
(a).nCmdID
OLECMDID_OPEN = 1,
OLECMDID_NEW = 2,
OLECMDID_SAVE = 3,
OLECMDID_SAVEAS = 4,
OLECMDID_SAVECOPYAS = 5,
OLECMDID_PRINT = 6,
OLECMDID_PRINTPREVIEW = 7,
OLECMDID_PAGESETUP = 8,
OLECMDID_SPELL = 9,
OLECMDID_PROPERTIES = 10,
OLECMDID_CUT = 11,
OLECMDID_COPY = 12,
OLECMDID_PASTE = 13,
OLECMDID_PASTESPECIAL = 14,
OLECMDID_UNDO = 15,
OLECMDID_REDO = 16,
OLECMDID_selectALL = 17,
OLECMDID_CLEARselectION = 18,
OLECMDID_ZOOM = 19,
OLECMDID_GETZOOMRANGE = 20
OLECMDID_updateCOMMANDS = 21
OLECMDID_REFRESH = 22
OLECMDID_STOP = 23
OLECMDID_HIDETOOLBARS = 24
OLECMDID_SETPROGRESSMAX = 25
OLECMDID_SETPROGRESSPOS = 26
OLECMDID_SETPROGRESSTEXT = 27
OLECMDID_SETTITLE = 28
OLECMDID_SETDOWNLOADSTATE = 29
OLECMDID_STOPDOWNLOAD = 30
上面的关键词都可以在浏览器的菜单里面找到对应的选项﹐大家一看就明白的﹗
(b).nCmdExecOpt
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_PROMPTUSER = 1,
LECMDEXECOPT_DONTPROMPTUSER = 2,
OLECMDEXECOPT_SHOWHELP = 3
对于这个参数﹐一般来说﹐选1就可以了。4.常用:
WebBrowser.ExecWB(1,1) 打开
WebBrowser.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
WebBrowser.ExecWB(4,1) 保存网页
WebBrowser.ExecWB(6,1) 打印
WebBrowser.ExecWB(7,1) 打印预览
WebBrowser.ExecWB(8,1) 打印页面设置
WebBrowser.ExecWB(10,1) 查看页面属性
WebBrowser.ExecWB(15,1) 好像是撤销,有待确认
WebBrowser.ExecWB(17,1) 全选
WebBrowser.ExecWB(22,1) 刷新
WebBrowser.ExecWB(45,1) 关闭窗体无提示5.示例﹕
(a)调用IE的”另存为”功能的示例﹕
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<A href="javascript:WebBrowser.ExecWB(4,1);">Save-存储</A>(b)经过改写的登陆模式
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<body onload="showModalDialog('login_access.asp',0,'Status:NO;dialogWidth:418px;dialogHeight:288px');document.all.WebBrowser.ExecWB(45,1);">
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开>
<input name=Button onClick=document.all.WebBrowser.ExecWB(2,1) type=button value=关闭所有>
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为>
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>
<input name=Button onClick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性>
<input name=Button onClick=document.all.WebBrowser.ExecWB(17,1) type=button value=全选>
<input name=Button onClick=document.all.WebBrowser.ExecWB(22,1) type=button value=刷新>
<input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭> http://hi.baidu.com/calfsoft/blog/item/6355ee1b0bc364d4ad6e75e7.html