更新列表框视觉C ++ [英] update listbox visual c++

查看:73
本文介绍了更新列表框视觉C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个可视化的c ++窗体,并包括一个用于显示消息的列表框,以便用户知道程序在哪里.我的问题是,列表框仅在程序结束时显示消息.

如何更新/刷新/重绘列表框?


我的代码:

I buil a visual c++ form and i included a listbox for fisplaying message so the user knows where the program is. My problem is that the listbox only show the messages when the program ends.

How can i update/refresh/redraw my listbox?


My Code:

if(cliente==NULL)
{
    listBox1->Items->Add( String::Format("Autopatch iniciado pela 1 vez...") );
    listBox1->Items->Add( String::Format("A criar configuracoes...") );
    listBox1->Items->Add( String::Format("Pode demorar vários minutos...") );
}
f2=fopen("caminho.txt","w");
lister(caminho_actual);
 fflush(f2);
fclose(f2);
f2=fopen("caminho.txt","r");
cliente=fopen("cliente.dat","w");

推荐答案

关于Windows的有趣的事情之一是可见元素(GUI控件之类的东西)需要处理消息才能正确运行.

任何基于Windows GUI的应用程序都需要确保及时运行消息处理循环,以使其正常运行.某些应用程序使用单独的GUI线程来执行此操作(使用基于MFC/Dialog的应用程序可免费获得该功能.

您显示的代码看起来像是在应用程序的主线处理,打开文件等中一样.如果您的代码在完成之前从未进入空闲状态或返回到消息循环,则将看到该行为您报告.

我无法告诉您如何构造代码而又看不到更多内容.但是,您可以通过在合理的时间调用
One of the funny things about Windows is that the visible elements (GUI Controls, stuff like that) need to process messages in order to operate correctly.

Any Windows GUI based application needs to ensure that the message processing loop is run in a timely fashion to allow that to work. Some applications do that with a separate GUI thread (something you get for free with an MFC / Dialog based application.

The code you show looks like it''s in the main line processing of your application, opening files, etc. If your code never enters an idle state or returns to the message loop until it''s finished, you will see the behavior you report.

I cannot tell you how to structure your code without seeing lots more of it. However, you can force the message processing loop to run by calling
void ProcessWindowMessages()
{
	MSG msg;
	
	while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))	// let them see the message before we go into longer term wait
	{
		TranslateMessage(&msg);							// translate it
		DispatchMessage(&msg);							// and let windows dispatch it to WinProc
	}
}

来强制消息处理循环运行,就像每次在列表框中添加内容之后一样.并不是说这是最好的处理方法,而是取决于应用程序设计的好方法.

at reasonable time, like after each time you put something in the listbox. Not that this is the best way to do things but it is often a good way depending on the design of your application.


将项目添加到列表框中后,可以在其上调用UpdateWindow框以强制其重画.例如:
After you add items to your listbox, you can call UpdateWindow on that box to force it to redraw. For example:
listbox1->UpdateWindow();


希望有帮助.


Hope that helps.


这篇关于更新列表框视觉C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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