本文介绍了如何使用backgroundworker线程调用API GetWindowRect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用backgroundworker线程调用API GetWindowRect?

任何人都可以给我一个演示,坦克〜!



how to use backgroundworker thread call the API GetWindowRect?
can anybody give me a demo,tanks~!

[DllImport("user32.dll")]
    private static extern int GetWindowRect(int hwnd, ref Rect lpRect);

    private void bgw_DoWork(object sender, DoWorkEventArgs e)
    {

        while (bgw.WorkerSupportsCancellation)
        {
            GetWindowRect(hWnd,ref lpRect);
        }


    }





问题的重要性不在于定义hWnd和lpRect,

i只是给出一个演示。

API GetWindowRect必须基于GUI线程,但backgroundworker是另一个不基于GUI线程的线程。

如何解决这个问题,任何人都可以正确编译。

即使我使用System.Windows.Forms.Control.Invoke方法,

但该方法只有两个重载,一个没有参数,

另一个参数是对象数组。

如何在对象数组中使用ref params?



the question importance is not at define hWnd and lpRect,
i just give a demo.
the API GetWindowRect must based on GUI thread,but backgroundworker is another thread not based on GUI thread.
how can solve this quetion, can anybody compilation right.
even though i use System.Windows.Forms.Control.Invoke method,
but the method only have two overload,one is not have params,
another's params is object array.
how can i use ref params in object array?

推荐答案


[DllImport("user32.dll")]
private static extern int GetWindowRect(int hwnd, ref System.Drawing.Rectangle lpRect);





系统.Drawing.Rectangle lpRect = new Rectangle();

GetWindowRect(hWnd,ref lpRect);



System.Drawing.Rectangle lpRect = new Rectangle();
GetWindowRect(hWnd,ref lpRect);


这篇关于如何使用backgroundworker线程调用API GetWindowRect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 22:15