首页  编辑  

调用查看源文件的功能

Tags: /C#/界面处理/WebBrowser/   Date Created:

using System . Runtime . InteropServices;

[ DllImport ( "User32.DLL" )]

public static extern int SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam);

[ DllImport ( "User32.DLL" )]

public static extern IntPtr FindWindowEx( IntPtr hwndParent,

    IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

public int IDM_VIEWSOURCE = 2139 ;

public uint WM_COMMAND = 0x0111 ;

private void Form1_Load( object sender , EventArgs e)    

{

   webBrowser1 . Navigate( "http://blog.sina.com.cn/zswang" );

}

private void button1_Click( object sender , EventArgs e)

{

    IntPtr vHandle = webBrowser1 . Handle;

   vHandle = FindWindowEx(vHandle, IntPtr . Zero, "Shell Embedding" , null );

   vHandle = FindWindowEx(vHandle, IntPtr . Zero, "Shell DocObject View" , null );

   vHandle = FindWindowEx(vHandle, IntPtr . Zero, "Internet Explorer_Server" , null );

   SendMessage(vHandle, WM_COMMAND, IDM_VIEWSOURCE, ( int )Handle);

}