c ++多线程窗口GUI(访问表单) [英] c++ multithreaded windows GUI (accessing the forms)

查看:144
本文介绍了c ++多线程窗口GUI(访问表单)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的控制台应用程序,使用windows sockets来作为服务器和客户端之间的代理。我决定做一个图形界面,用于实时观看所有的输入/输出数据包(如一个非常简单的wireshark)。

I've written a simple console application using windows sockets to work as a proxy between a server and a client. I decided to make a graphical interface for watching all the in/outgoing packets real time (like a very simple wireshark).

服务器和客户端之间的连接运行与消息循环不同的线程。当服务器/客户端发送数据包时,我想立即显示(例如添加到一个简单的文本控件)。

The connection between the server and the client runs on a different thread than the message loop. When the server/client sends a packet, I would like that to be displayed (for example added to a simple text control) immediately.

但是因为我不能从其他线程访问表单,而不是消息循环的线程,我不知道如何处理这个。

But since I can not access the forms from other thread than the thread where the message loop is I dont know how to handle this.

我发现了几个解决方案:
- 托管c ++
- C ++ / CLI
- C#,
但不使用.NET平台。 (我真的很新这个GUI主题,所以我甚至不确定你可以使用Windows窗体没有.NET)

I've found several solutions in: - Managed c++ - C++/CLI - C#, but not any without using .NET platform. (I really new to this GUI topic so I am not even sure you can use windows forms without .NET)

也许QT + C + +可以处理这个问题,但任何其他解决方案比?如果不是可以用C#/ Java编写一个用于本地C ++代码的包装器?

Maybe QT + C++ could handle this problem, but any other solution than that? If not is it possible to write a wrapper in C# / Java for the native C++ code?

必须有许多使用C / C ++编写的应用程序,

There must be many applications written in C/C++ which using a GUI, what is the general way to do that?

推荐答案

你绝对正确,你不能在不同的线程访问一个窗口。使用:: PostMessage Win32 API命令(或者,如果你使用Win32周围的包装器库,无论那个包装器中最终调用PostMessage的函数)处理这个消息的正确方法。以下是Microsoft有关消息队列的有用链接:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644928(v = vs.85).aspx

You are absolutely correct that you cannot access a window in a different thread. The proper way to handle this to post a message using the ::PostMessage Win32 API command (or, if you are using a wrapper library around Win32, whatever function in that wrapper that eventually calls PostMessage). Here's a useful link from Microsoft regarding message queues: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644928(v=vs.85).aspx

这篇关于c ++多线程窗口GUI(访问表单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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