创建窗口句柄错误,急!

ludingping 2008-03-31 11:54:09
我开发的是影院的票务系统,显示剧场的座位情况是用一个按钮控件来表示的。现在的问题是,座位有很多,就会创建很多很多的按钮,结果,在几天门票的视图切换时,就会出现创建窗口句柄的错误提示。请问有什么方法可以解决吗?
...全文
468 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnming 2008-04-02
  • 打赏
  • 举报
回复
使用绘图就可以了,判断坐标进行判断座位的选择

如果使用按钮的话,可能所有的操作都需要使用代理
另外速度会很慢
changjiangzhibin 2008-04-02
  • 打赏
  • 举报
回复
多调试,多设几个断点
ludingping 2008-04-02
  • 打赏
  • 举报
回复
不知道用Dispose,手动将不用的Button清除可行否?
daifuqiang 2008-04-02
  • 打赏
  • 举报
回复
窗口句柄过多.
建议不要使用Button来表示座位,而应该使用自己绘图的方法来处理。
Scarroot 2008-04-02
  • 打赏
  • 举报
回复
有没有用到多线程?是否是因为多线程造成这样的错误?
ludingping 2008-04-02
  • 打赏
  • 举报
回复
谢谢。也许是太浪费内存了。呵呵。
但GDI方式太麻烦了。要处理很多事情,本来只是一个项目用,我看还是重复使用算了。优化一下算法。
因为剧场最多也只是3千多座位。
whycom 2008-04-02
  • 打赏
  • 举报
回复
窗口数量也受到可用内存的限制
whycom 2008-04-02
  • 打赏
  • 举报
回复
就好像win32可以访问4G的内存,但你不能把你的程序写成4g大小
boblaw 2008-04-01
  • 打赏
  • 举报
回复
System.ComponentModel.Win32Exception: 创建窗口句柄时出错。
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
------------------------------------
不过楼主的问题,从理论上来说,10000个应该是足够了。
至于出错,出错消息是.net内部代码的问题,而非用户代码,我想问题主要是LZ的程序中使用了过多的控件资源。
可以考虑从以下几个方法来解决:
1. 改用GDI绘图代替Button.
2. 即使一定要使用Button,也可以在程序动态加载Button并及时释放资源,或者创建一定数量的Button重复利用,实话说,一个窗体同一时间能够显示多少个Button?
有一千个座位,就要创建1000个Button?创建1000个Button肯定是不能一起显示的,大多数的Button都是在无谓浪费消耗大量系统资源,如内存的分配和系统的消息处理。即使操作系统没有限制句柄数量,也不应该这样做。
boblaw 2008-04-01
  • 打赏
  • 举报
回复
不好意思,更正一下楼上的说法。
可以在注册表上查HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\
CurrentVersion\Windows\USERProcessHandleQuota
win2k,XP默认是10000个,2003没查。
最大支持应该是65535个,但是MSDN上又说该注册表项的设置范围为200至18000个。
boblaw 2008-04-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jinjazz 的回复:]
引用 3 楼 whycom 的回复:
window的窗口句柄数量是由限制的,最好用图片来模拟


这个限制可以忽略..我记得win95时代好像是65535或者更多,记不清,后来的windows几乎没有什么限制,应该是你代码的问题
[/Quote]
win2k应该在10000以下
ludingping 2008-04-01
  • 打赏
  • 举报
回复
座位情况,图片如下:
ludingping 2008-04-01
  • 打赏
  • 举报
回复
我用的是Button. 因为Button有些事件处理。不用自己的处理这些事件。


************** 异常文本 **************
System.ComponentModel.Win32Exception: 创建窗口句柄时出错。
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Control.CreateGraphicsInternal()
在 System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
在 System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
在 System.Windows.Forms.Control.WndProcException(Exception e)
在 System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
在 System.Windows.Forms.NativeWindow.Callback(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.Form.ShowDialog(IWin32Window owner)
在 System.Windows.Forms.Form.ShowDialog()
在 AuwaTicket.Client.SellManagement.Business.frmBookingOrderDetail.btnSelTicket_Click(Object sender, EventArgs e) 位置 F:\DavidLv\AuwaTicket\AuwaTicket.Client.SellManagement\Business\frmBookingOrderDetail.cs:行号 521
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e)
在 DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已加载的程序集 **************
mscorlib
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.832 (QFE.050727-8300)
基本代码: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
AuwaTicket.Client.SellManagement
程序集版本: 1.0.0.0
Win32 版本: 1.0.0.0
基本代码: file:///F:/DavidLv/AuwaTicket/AuwaTicket.Client.SellManagement/bin/Debug/AuwaTicket.Client.SellManagement.exe
----------------------------------------
System.Windows.Forms
程序集版本: 2.0.0.0
Win32 版本: 2.0.50727.832 (QFE.050727-8300)
基本代码: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
boblaw 2008-03-31
  • 打赏
  • 举报
回复
為什么要用Button,你用Button代表座位?

[Quote=引用楼主 ludingping 的帖子:]
结果,在几天门票的视图切换时,就会出现创建窗口句柄的错误提示。请问有什么方法可以解决吗?
[/Quote]
不看代碼不知道你說的是什么情況。或者說詳細點
scq2099yt 2008-03-31
  • 打赏
  • 举报
回复
错误原因和出错出的代码贴出来,我用VC实现这个打算在界面上画矩形表示座位状态
mine 2008-03-31
  • 打赏
  • 举报
回复
ding
fht123 2008-03-31
  • 打赏
  • 举报
回复
不错,把错误原因贴出来帮你分析分析.
jinjazz 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 whycom 的回复:]
window的窗口句柄数量是由限制的,最好用图片来模拟
[/Quote]

这个限制可以忽略..我记得win95时代好像是65535或者更多,记不清,后来的windows几乎没有什么限制,应该是你代码的问题
林小白 2008-03-31
  • 打赏
  • 举报
回复
感觉应该是你窗体中的控件问题.
whycom 2008-03-31
  • 打赏
  • 举报
回复
window的窗口句柄数量是由限制的,最好用图片来模拟
加载更多回复(1)

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧