OK. 接下來, 我們要將Logic Inspector中的內容抓取出來. 下面的代碼展示瞭如何獲取IE控件中的內容. 在文章的附件中會有完整的代碼.
- EnumWindows(new EnumWindowsProc(EvalWindow), IntPtr.Zero);
- foreach (IntPtr hwnd in ipHwnds)
- {
- StringBuilder sb = new StringBuilder(256);
- GetWindowText(hwnd, sb, 256);
- IntPtr hwndIPIE = IntPtr.Zero;
- IntPtr parentHwnd = hwnd;
- String className = String.Empty;
- while (!className.Equals("Internet Explorer_Server"))
- {
- EnumChildProc childProc = new EnumChildProc(EnumChildWindows);
- EnumChildWindows(parentHwnd, childProc, ref hwndIPIE);
- className = GetClassName(hwndIPIE);
- parentHwnd = hwndIPIE;
- }
- IHTMLDocument2 htmlDoc = IEDOMFromhWnd(hwndIPIE);
- String htmlText = htmlDoc.body.parentElement.outerHTML;
- StreamWriter sw = new StreamWriter(String.Format("d:\\{0}.html", sb.ToString()));
- sw.Write(htmlText);
- sw.Close();
- }
以下是從Logic Inspector 抓取的內容:
- <html>
- <head>
- <title>Logic Inspector</title>
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type"></meta>
- </head>
- <frameset id="idframeset" framespacing="2" border="2" cols="50%,50%">
- <FRAME id=overallFrame src="res://1033\ipdsintl.dll/InspectorOverallFrames.html" scrolling=yes>
- <FRAME id=fieldFrame src="res://1033\ipdsintl.dll/InspectorFieldFrames.html" scrolling=yes>
- </frameset>
- </html>
很明顯, Logic Inspector 由2個Frame組成: "overallFrame" 和 "fieldFrame". 從名字即可知道"overallFrame"指代Logic Inspector的左半部, "fieldFrame" 指代Logic Inspector的右半部.
如果你足夠細心, 就會發現一個奇妙的地方. 這2個Frame的source居然是從一個dll中讀取的. 而這個ipdsintl.dll就是揭開InfoPath 祕密的重點.
IPDSINTL.DLL -- InfoPath 的資源文件
首先我們要找到IPDSINTL.DLL到底在哪. 從它的上級目錄"1033"來看, 這個文件應該在Microsoft Office文件夾下. 如我所料, 它確實是老老實實呆在這的:
%ProgramFiles%\Microsoft Office\Office12\1033\IPDSINTL.DLL
把這個DLL拖到Visual Studio中, 可以看到其實它是InfoPath重要的資源文件.
還記得2個frame的路徑嗎? 趕緊看看HTML文件夾下的內容吧:
在這裏不僅找到了2個Frame的source, 還有InfoPath所用控件的定義. 接下來的任務就是修改相應的文件, 並且保存回DLL. 再用新的DLL覆蓋原來的DLL. 相信這是每個程序員都能做的事, 我就不贅述了.
使用附件中的"INSPECTORFIELD.HTML"文件覆蓋IPDSINTL.DLL相應的文件, 可以得到如下效果:
"Copy Text" 可以複製當前Logic Inspector 的文字內容至剪貼板.
"Copy HTML" 可以複製當前Logic Inspector 的HTML內容至剪貼板.
Conclusion
發現了IPDSINTL.DLL後, 我們不僅僅能修改Logic Inspector, 連InfoPath內置的控件也可以修改了. 接下來就需要大家發揮自己的想象力了~