zoukankan      html  css  js  c++  java
  • 创建窗口句柄时出错解决思路

    创建窗口句柄时出错
    未处理 System.OutOfMemoryException
      Message="创建窗口句柄时出错。"
      Source="System.Windows.Forms"
      StackTrace:
      在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
      在 System.Windows.Forms.Control.CreateHandle()
      在 System.Windows.Forms.Form.CreateHandle()
      在 System.Windows.Forms.Control.get_Handle()
      在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
      在 System.Windows.Forms.Control.Show()
      在 ShengTeng.HIS.View.NSDoctorsAdvice.DoctorsAdviceForm.HomePToolStripButton_Click(Object sender, EventArgs e)行号 740
      在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
      在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
      在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
      在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
      在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
      在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
      在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
      在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
      在 System.Windows.Forms.Control.WndProc(Message& m)
      在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
      在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
      在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
      在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
      在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
      在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
      在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
      在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
      在 System.Windows.Forms.Application.Run(Form mainForm)
      在 ShengTeng.HIS.STHIS.Program.Main() 位置Program.cs:行号 42
      在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
      在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      在 System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.NullReferenceException
      Message="未将对象引用设置到对象的实例。"
      Source="System.Windows.Forms"
      StackTrace:
      在 System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      在 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
      在 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
      在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
      InnerException:
    解决方案-属性-调试-把"启用非托管码调试"选上
    在看看
    ------解决方案--------------------
    这种问题,原因不好找的,尝试在Form的子类中重写一下CreateHandle,
    如果创建不成功,通过RecreateHandle,一般都会成功

    C# code
            protected override void CreateHandle()
            {
                if (!IsHandleCreated)
                {
                    try
                    {
                        base.CreateHandle();
                    } 
                    catch {}
                    finally
                    {
                        if (!IsHandleCreated)
                        {
                            base.RecreateHandle();
                        }
                    }
                }            
            } 

    摘录自http://www.myexception.cn/dotnet-framework/395508_2.html

  • 相关阅读:
    MVCCache2.应用程序缓存(Cache:1.输出缓存[2].应用程序缓存)
    接口和抽象类的区别和作用(功能、用途、好处)
    MVCCache1.输出缓存(Cache:[1].输出缓存2.应用程序缓存)
    JAVA中为什么要使用接口,继承接口不是还要重写方法吗?为什么不直接写那些方法呢?:::接口的最主要的作用是达到统一访问
    枚举的意义,用途,作用,用法,作用场景
    C++ compile multiple cpp and header files via I. cpp1.cpp cpp2.cpp o
    C++retrieve array via returned pointer,traverse the array pointer without the array size
    C++ pass array as pointer and sort in bubble
    C write and read file via FILE and open method in a+ or r mode
    C++ connection mysql and retrieve select sql result
  • 原文地址:https://www.cnblogs.com/qiyecao/p/3445223.html
Copyright © 2011-2022 走看看