滚动CWnd派生类 [英] scrolling a CWnd derived class

查看:77
本文介绍了滚动CWnd派生类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我只需要一些理论上的理解.

我已经创建了一个CWnd派生的控件.它被注册.它出现在对话框中.在控件中,我有几行数据(基本上是一个网格).数据行多于控件可以显示的行.当我向下滚动

SetScrollPos(SB_VERT,vertScrollInfo.nPos +1);

所有行都应按原样向上移动,但是,应在最底行显示的新行却没有.

在滚动后触发绘制(通过尝试调整大小或类似操作)时,将使用原始视图重新绘制控件.

我在代码中的任何地方都没有给出CWnd的垂直大小,这正是我怀疑的问题.

我尝试SetWindowPos无济于事.

如果您能指出正确的方向,我将不胜感激.谢谢.

I think I just need some theoretical understanding here.

I have a CWnd derived control I''ve created. It gets registered. It appears in a dialog. In the control I have lines of data (basically a grid). There are more lines of data than control can display. When I scroll down

SetScrollPos(SB_VERT, vertScrollInfo.nPos + 1);

all the lines move upward as they should, however, the new line that should be displayed in the bottom-most row does not.

When the paint is triggered after the scroll (by attempting to resize or something similar), the control is repainted with the original view.

Nowhere in my code did I give the vertical size of the CWnd which is what I''m suspecting is the problem.

I tried SetWindowPos to no avail.

If you could point me in the right direction I would appreciate it. Thanks.

推荐答案

您需要从视口的顶部到底部重新绘制,即应根据数据向下的距离查看数据行您已经滚动了.
You need to repaint from the top to the bottom of the viewport, that is the lines of data that should be seen depending on how far down the data you have scrolled.


糟糕,我从未设置视口.我会调查的.谢谢
Oops, I never set my viewport. I''ll look into that. Thanks,


看看我的代码,我确实考虑了视口
Looking at my code I did take into account the viewport
CRect rectClip;
dc.GetClipBox(&rectClip);
CRect rectBitmap=rectClip;
CBitmap bitmap;
CBitmap* pOldBitmap=NULL;
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc,rectBitmap.Width(),rectBitmap.Height());
pOldBitmap=dcMem.SelectObject(&bitmap); 
dcMem.SetMapMode(dc.GetMapMode());
dcMem.SetWindowExt(dc.GetWindowExt());
dcMem.SetViewportExt(dc.GetViewportExt());
dcMem.SetWindowOrg(rectClip.left,rectClip.top); 
COLORREF clrWindowBkgrnd = static_cast<COLORREF>(GetSysColor(COLOR_WINDOW));
dcMem.FillSolidRect(rectBitmap,clrWindowBkgrnd); 
Draw(dcMem);
dc.BitBlt(rectClip.left,rectClip.top,rectClip.Width(),rectClip.Height(),&dcMem,rectClip.left,rectClip.top,SRCCOPY);
dcMem.SelectObject(pOldBitmap);



Draw(dcMem)是我完成所有网格绘制的地方.

但是我什么都没给窗户加上它的原始尺寸.我需要吗?



Draw(dcMem) is where I have all the grid painting being accomplished.

But nowhere did I give the window its original size. Do I need to?


这篇关于滚动CWnd派生类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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