简体   繁体   English

是否可以/必须在单独的线程[MFC]中调用OnDraw

[英]Is it possible/necessary to have call to OnDraw in separate thread [MFC]

This is a MFC Doc/View application: 这是MFC Doc / View应用程序:
Is it possible/necessary to have call to OnDraw in separate thread of execution, ie worker thread? 是否有可能/必须在单独的执行线程(即工作线程)中调用OnDraw? In the software we building we have enormous problem with view in Doc/View application. 在我们构建的软件中,Doc / View应用程序中的视图存在巨大的问题。 That is, every time the view is scrolled the processing of this takes such long time that the application freezes. 也就是说,每次滚动视图时,处理时间都非常长,以至于应用程序冻结。
The bitmaps that need to be processed are rather large (over 1GB on average) 需要处理的位图相当大(平均超过1GB)
Thank you. 谢谢。

As specifically asked, the answer is "no". 如明确要求的那样,答案是“否”。 OnDraw must be called in the context of the main GUI thread. 必须在主GUI线程的上下文中调用OnDraw。 What you could do, is: 您可以做的是:

  • Mark the scrolled region as invalid (in "OnScroll") 将滚动区域标记为无效(在“ OnScroll”中)
  • Kick off another thread to extract a screen-sized bitmap from your over-large bitmap. 启动另一个线程以从超大位图中提取屏幕大小的位图。
  • OnDraw draws lots of question marks over the invalid region. OnDraw在无效区域上绘制许多问号。
  • The background thread posts a message to the main GUI thread when done. 完成后,后台线程将消息发布到主GUI线程。
  • The message handler marks the scrolled region as now having a backing bitmap (and calls "InvalidateRect" again to prompt another OnDraw). 消息处理程序将滚动区域标记为现在具有支持位图(并再次调用“ InvalidateRect”以提示另一个OnDraw)。
  • OnDraw just blits the extracted bitmap in place. OnDraw只是将提取的位图调到适当的位置。

(But splitting the gigantic bitmap into pieces would be a better idea.) (但是将巨大的位图分成几块是一个更好的主意。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM