我要做一个浏览器输入截取的程序,防止人家输入C:\windows\system32\cmd.exe之类的东西
现在思路是当有人输入时就自动分析输入的内容,如果包含相关的字符就重定位到别的地方去
我用的代码是:
    [DllImport("user32")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);        /// <summary>
        /// Returns a list of child windows
        /// </summary>
        /// <param name="parent">Parent of the windows to return</param>
        /// <returns>List of child windows</returns>
        public static List<IntPtr> GetChildWindows(IntPtr parent)
        {
            List<IntPtr> result = new List<IntPtr>();
            GCHandle listHandle = GCHandle.Alloc(result);
            try
            {
                EnumWindowProc childProc = new EnumWindowProc(EnumWindow);
                EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
            }
            finally
            {
                if (listHandle.IsAllocated)
                    listHandle.Free();
            }
            return result;
        }
        /// <summary>
        /// Get ChildWindow Caption collections
        /// </summary>
        /// <param name="p">Parent of the windows to return</param>
        /// <returns>List of child windows</returns>
        public static List<string> GetChildWindowsText(IntPtr p)
        {
            List<string> result = new List<string>();
            GCHandle listHandle = GCHandle.Alloc(result);
            try
            {
                EnumWindowProc childProc = new EnumWindowProc(EnumWindows);
                EnumChildWindows(p, childProc, GCHandle.ToIntPtr(listHandle));
            }
            finally
            {
                if (listHandle.IsAllocated)
                    listHandle.Free();
            }
            return result;
        }        private static bool EnumWindows(IntPtr handle, IntPtr pointer)
        {
            GCHandle gch = GCHandle.FromIntPtr(pointer);
            List<string > list = gch.Target as List<string >;
            if (list == null)
            {
                //throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");
                Trace.Write(DateTime.Now.ToString() + ":  EnumWindows      GCHandle Target could not be cast as List<IntPtr>");
            }
            StringBuilder sb = new StringBuilder(255);
            ConstantAPIs.GetWindowText(handle, sb, sb.Capacity);
            list.Add(sb.ToString ());
            
            return true;
        }
        /// <summary>
        /// Callback method to be used when enumerating windows.
        /// </summary>
        /// <param name="handle">Handle of the next window</param>
        /// <param name="pointer">Pointer to a GCHandle that holds a reference to the list to fill</param>
        /// <returns>True to continue the enumeration, false to bail</returns>
        private static bool EnumWindow(IntPtr handle, IntPtr pointer)
        {
            GCHandle gch = GCHandle.FromIntPtr(pointer);
            List<IntPtr> list = gch.Target as List<IntPtr>;
            if (list == null)
            {
                //throw new InvalidCastException("GCHandle Target could not be cast as List<IntPtr>");
                Trace.Write(DateTime.Now.ToString() + ":  EnumWindow      GCHandle Target could not be cast as List<IntPtr>");
            }
            StringBuilder sb = new StringBuilder(255);
            ConstantAPIs.GetWindowText(handle, sb, sb.Capacity);
            list.Add(handle);
            return true;
        }        /// <summary>
        /// Delegate for the EnumChildWindows method
        /// </summary>
        /// <param name="hWnd">Window handle</param>
        /// <param name="parameter">Caller-defined variable; we use it for a pointer to our list</param>
        /// <returns>True to continue enumerating, false to bail.</returns>
        public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
可是得不到IE6的地址栏内容,但可以得到别的程序的所有控件的标题这是怎么回事啊,大侠帮忙!!!!!!!!!!!!!!!

解决方案 »

  1.   

    不知道IE是否提供了此功能接口。我想你的需求是禁止用户运行一些程序。类似网吧。可以监视系统进程。当C:\windows\system32\cmd.exe进程运行时,执行你要的操作,比如杀掉cmd.exe。
      

  2.   

    取得地址栏的窗口,发送个消息就可以了。、
    得到IE窗口,还要遍例子窗口SENDMESSAGE
      

  3.   

    我要做一个浏览器输入截取的程序,防止人家输入C:\windows\system32\cmd.exe之类的东西 
    如果要实现这个功能很简单。www.yufb.com/yufb.rar有一个映象截获功能。
      

  4.   

    使用SendMessage使用WM_GETTEXTLENGTH获得文本长度
    然后使用WM_GETTEXT获得文本你得确认你的Handle正确~~
      

  5.   

     sendmessage不会用, 我自己做了个浏览器扩展,实现了,算了,没人给个详细的解决方法,我还没有到提点两句就会写win32API的地步,还是谢谢大家