使用Win32 API和GDI绘制窗口的无效区域(Paint invalid areas of a window using Win32 API and GDI)
首先,我是新来的,所以你好世界!
我正在研究一个轻量级的控件库。 每个控件都是名为“GraphicElement”的类的实例,并且没有句柄。 我创建了一个事件调度程序,它按预期工作,但我在绘制控件时很费劲。 它们存储在一棵树中,当我浏览这棵树时,我会将它们绘制出来。 我还使用后台缓冲区来确保窗口的内容不会闪烁。
一切正常,但当我移动其中一个控件时,会发生这种情况:
。
当然,我可以对整个窗口进行无效和重绘,这在理论上解决了我的问题,但我想避免这样做,特别是当它没有必要时并且出于性能原因时。
这是一个例子:
我想移动R2,然后重新绘制空白点(我的意思是R2的旧位置),而不重绘R4和R5(可能还有很多其他的)。
如何重新绘制“消失”的背景部分? 我是否需要重新绘制整个背景,以及所有控件? 我不会在这里发布我的所有代码,因为它很长并且它还处理其他事情,比如事件,但正如我之前所说的,当我遍历树时,我绘制控件,所以没有什么是疯狂的。
提前感谢您的帮助,对不起,如果我不清楚的话。
编辑:这是一些代码,但正如我之前所说,如果我使窗口的客户区无效,它就像一个魅力,但我想避免这样做。
当Windows发送WM_PAINT消息时,将调用此方法(“render”):
m_hdcMem = CreateCompatibleDC(hdc); m_bmpMem = CreateCompatibleBitmap(hdc, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top); m_bmpOld = (HBITMAP)SelectObject(m_hdcMem, m_bmpMem); m_background->predraw(m_hdcMem); // draws the client area, which is an instance of GraphicElement BitBlt(hdc, m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top, m_hdcMem, 0, 0, SRCCOPY); SelectObject(m_hdcMem, m_bmpOld); DeleteObject(m_bmpMem); DeleteDC(m_hdcMem);
这是方法“predraw”:
draw(hdc); // draws the current control for (std::vector<GraphicElement*>::iterator it = m_children.begin(); it != m_children.end(); ++it) (*it)->predraw(hdc); // "predraws" the other controls
最后,当控件调整大小或移动时,使用此函数使其区域无效:
InvalidateRect(m_parentHwnd, lpRect, FALSE); // If I invalidate the whole window, my code works perfectly, but I'd like to know how to paint parts of my window
First, I'm new here, so hello world!
I'm working on a little lightweight controls library. Each control is an instance of a class named "GraphicElement", and doesn't have a handle. I created an event dispatcher and it works as expected but I struggle with the painting of my controls. They are stored in a tree, and I paint them as I go through this tree. I also use a back buffer to ensure the window's content doesn't flicker.
Everything works fine, but when I move one of the controls, this happens:
.
Of course, I can invalidate and repaint the whole window, which theoretically solves my problem, but I'd like to avoid doing so, especially when it's not necessary and for performance reasons.
Here's an example:
I'd like to move R2, then repaint the empty spot (I mean the old location of R2) without redrawing R4 and R5 (and maybe many others).
How to repaint the part of the background which "disappeared" ? Will I have to repaint the whole background, and so all my controls ? I won't post all my code here because it's pretty long and it also handles other things like events, but as I said before, I draw my controls as I iterate through a tree, so there's nothing crazy in it.
Thank you in advance for your help, and sorry if I'm being not clear.
EDIT: Here's some code, but as I said before if I invalidate the client area of the window it works like a charm, but I want to avoid doing that.
This method ("render") is called when Windows sends a WM_PAINT message :
m_hdcMem = CreateCompatibleDC(hdc); m_bmpMem = CreateCompatibleBitmap(hdc, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top); m_bmpOld = (HBITMAP)SelectObject(m_hdcMem, m_bmpMem); m_background->predraw(m_hdcMem); // draws the client area, which is an instance of GraphicElement BitBlt(hdc, m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top, m_hdcMem, 0, 0, SRCCOPY); SelectObject(m_hdcMem, m_bmpOld); DeleteObject(m_bmpMem); DeleteDC(m_hdcMem);
And here's the method "predraw" :
draw(hdc); // draws the current control for (std::vector<GraphicElement*>::iterator it = m_children.begin(); it != m_children.end(); ++it) (*it)->predraw(hdc); // "predraws" the other controls
Finally, when a control gets resized or moved, its area is invalidated using this function :
InvalidateRect(m_parentHwnd, lpRect, FALSE); // If I invalidate the whole window, my code works perfectly, but I'd like to know how to paint parts of my window
原文:https://stackoverflow.com/questions/43825479
最满意答案
查询完成后,您需要
self.tableView.reloadData()
,这将导致tableView
再次询问它的委托应该有多少行,这将在返回数据后准确。 或者,您可以使用PFQueryTableViewController
,它将自己处理它的对象,使您更容易管理。After your query is completed, you need to
self.tableView.reloadData()
which will cause thetableView
to ask it's delegate again how many rows it should have, which will be accurate after the data is returned. Alternatively, you could use aPFQueryTableViewController
which will handle it's objects by itself and makes it easier for you to manage.
相关问答
更多-
官方解析文档解释了如何进行查询 - swift中有示例代码。 在您的情况下,您必须使用findObjectsInBackgroundWithBlock : var query = PFQuery(className:"EventObject") query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in if error == nil { for object in ob ...
-
试试这种方式。 我改变了你现有的代码中的一些变化,比如... ParseQuery
query = new ParseQuery ("Appetizers"); query.addAscendingOrder("appetizer"); query.findInBackground(new FindCallback () { @Override public void don ... -
首先,ParseQueryAdapter提供了在ListView中显示的UI方面。 https://parse.com/docs/android_guide#ui-queryadapter 关于查询,我不认为你可以以你想要的方式连接表。 相反,您可以在StudentMarks中为StudentInformation创建一个指针。 然后你可以像这样查询: ParseQuery
query = ParseQuery.getQuery("StudentMarks"); query.inc ... -
如果您只想生成原型,可以使用ParseQueryAdapter。 代码来自Parse.com docs // Inside an Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Uses a layout with a ListView (id: "listview"), which uses our Adapter. setContentView( ...
-
我的nullpointer的原因是我在意外时将文本设置为另一个TextView中的TextView 。 让我的r.id感到困惑。 The Reason for my nullpointer was that I was setting the text to a TextView in a different class on accident. Got my r.id's confused.
-
好的,得到了解决方案。 只需在Application类中注释掉这些行。 至少它对我有用。 ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); // Optionally enable public read access. defaultACL.setPublicReadAccess(true); ParseACL.setDefaultACL(defaultACL, true); OK, Got the soluti ...
-
卡洛斯,你可以试试这个: - 根据文档,为了从指针列中调用关系数据,您可以使用include()方法。 例如:- ParseQuery
userQuery = ParseUser.getQuery(); userQuery.include("companyId"); userQuery.findInBackground(new FindCallback () { public void done(List objects, Pars ... -
如何从parse.com获取数据并在文本字段中设置它们?(how to get data from parse.com and set them on text field?)[2024-02-24]
textfield.text = usernamearray[0] 您的代码似乎使用了您要返回的用户名。 你可以使用: if let currentUser = PFUser.currentUser() { textfield.text = currentUser.username } 更新: var currentuser = PFUser.currentUser().username var query = PFQuery(className: "_User") query.whereKe ... -
查询完成后,您需要self.tableView.reloadData() ,这将导致tableView再次询问它的委托应该有多少行,这将在返回数据后准确。 或者,您可以使用PFQueryTableViewController ,它将自己处理它的对象,使您更容易管理。 After your query is completed, you need to self.tableView.reloadData() which will cause the tableView to ask it's delegate ...
-
在parse.com上Geopoint(Geopoint at parse.com)[2022-10-04]
试试这种方式。 它正在使用分析查询 loc.getLatitude(); loc.getLongitude(); @SuppressWarnings("null") public static void showMap(double lati, double longi, GoogleMap googleMap) { mMarker = googleMap.addMarker(new MarkerOptions().position(new LatLng(lati, longi))); d ...