处理到窗口(hwnd)如何为表单执行此操作 [英] Handle To the Window (hwnd) how to do this for a form

查看:65
本文介绍了处理到窗口(hwnd)如何为表单执行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想显示一个带有进度条的表单以供Windows应用中的显示服务器处理.如果我打开5个win表单,则必须在有史以来最靠前的位置显示此进度条窗口.
我该怎么办?有人可以告诉我如何使用此窗口的句柄(hwnd).等待您的答复.

问候
Shameen

Hello All

I want to show a form with a progress bar for display server processing in windows app.If i open 5 win forms i have to display this progress bar window for the top most where ever.
How can i do this?Can any one tell me how to use handle to the window (hwnd) to this problem.Waiting for your reply.

Regards
Shameen

推荐答案

您无需HWND即可执行此操作.请记住,使用HWND将立即使您的Forms应用程序不可移植.如果您正确编写Forms应用程序,它将在许多平台上运行而无需重新编译(在Mono下).一次使用HWND会破坏它.

最重要的是,您不需要它.

相反,您需要创建一个单独的线程,并使用进度条将进度通知UI.方法如下:

您无法从非UI线程调用与UI相关的任何操作.相反,您需要使用System.Windows.Threading.DispatcherInvokeBeginInvoke方法(对于Forms或WPF)或System.Windows.Forms.Control(仅对于Forms).

在我过去的答案中,您将找到有关其工作原理的详细说明和代码示例:
Control.Invoke()与Control.BeginInvoke() [ ^ ],
Treeview Scanner和MD5的问题 [如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

—SA
You never need HWND to do this. Remember, using HWND will immediately make your Forms application non-portable. If you write a Forms application accurately, it will run on many platforms without recompilation (under Mono). A single use of HWND will spoil it.

Most importantly, you don''t need it.

Instead, you need to create a separate thread and notify UI on progress using a progress bar. Here is how:

You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


这篇关于处理到窗口(hwnd)如何为表单执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆