使用线程我无法将.jpg图像显示给文本控件 [英] Using Threads i am unable to display .jpg image to text control

查看:39
本文介绍了使用线程我无法将.jpg图像显示给文本控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在基于对话框的应用程序中创建线程,其中我在线程中调用一个函数,该函数应将.jpg图像显示给静态文本控件.但是我无法在使用线程的静态文本控件上显示它.我在以下代码中犯了什么错误,

无效Fun()
{
CreateThread(0,0,myThread,&myCounter,0,NULL);
}

DWORD WINAPI myThread(LPVOID lpParameter)
{
unsigned int&myCounter = *(((unsigned int *)lpParameter);
CRecognitionDlg * pDlg =(CRecognitionDlg *)lpParameter;
pDlg-> PictureCount = 0;
pDlg-> iCount = 0;
while(myCounter< 0xFFFFFFFF)
{
pDlg-> ShowFacesForEnrollement();
如果(pDlg-> sFlag == FALSE)
{
休息;
}
}

CloseHandle(myHandle);

返回0;
}
CPictureCtrl m_pFaceImages;
无效dlg ShowFacesForEnrollement()
{
m_pFaceImages.Load(CString(_T("Normal.jpg")));
}

在上面我做错了的代码中,任何人都可以帮帮我.

预先感谢.

Hello,

I am Crating a thread in dialog based application where i am calling a function in the thread which should display the .jpg image to the static text control. but i am unable to display it on the static text control using thread. what is mistake i am doing in the below code,

void Fun()
{
CreateThread(0, 0, myThread, &myCounter, 0, NULL);
}

DWORD WINAPI myThread(LPVOID lpParameter)
{
unsigned int& myCounter = *((unsigned int*)lpParameter);
CRecognitionDlg* pDlg = (CRecognitionDlg*)lpParameter;
pDlg->PictureCount = 0;
pDlg->iCount = 0;
while(myCounter < 0xFFFFFFFF)
{
pDlg->ShowFacesForEnrollement();
if (pDlg->sFlag == FALSE)
{
break;
}
}

CloseHandle(myHandle);

return 0;
}
CPictureCtrl m_pFaceImages;
void dlg ShowFacesForEnrollement()
{
m_pFaceImages.Load(CString(_T("Normal.jpg")));
}

in the above code where i am doing wrong can anyone help me out.

Thanks in advance.

推荐答案

无法从辅助线程访问GUI对象.
在这里,您创建了myThread并尝试从中访问CPictureCtrl.
我想CPictureCtrl是一个在静态窗口中显示图像的类.

如果图像加载消耗时间,则可以在加载后将消息发送到GUI进行显示,然后将其加载到工作线程中.
通常,消耗时间的非GUI操作是在工作线程中执行的.完成操作后,您可以将用户消息(指示从工作线程执行操作后的GUI更新)发送到GUI线程. GUI操作是从新用户消息的消息处理程序执行的.用户消息的消息处理程序将在GUI线程中执行.
Accessing GUI objects from a worker thread is not possible.
Here you created myThread and trying to access CPictureCtrl from it.
I suppose CPictureCtrl is a class to display an image in a static window.

If image loading consumes time, you can load it in a worker thread, after loading send a message to GUI to display it.
Normally non gui actions which consumes time are performed in a worker thread. After finishing operations, you can send a user message(which indicates GUI update after an action from worker thread) to GUI thread. GUI actions are performed from the message handler of new user message. Message handler for the user message will be executed in GUI thread.


这篇关于使用线程我无法将.jpg图像显示给文本控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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