几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » 程序设计 » vc编程
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-11-25, 09:53 PM   #1
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 【转帖】请问如何能够实现类似Editbox,listctrl,listbox这类控件的滚动条重画!

http://topic.csdn.net/t/20021026/08/1126453.html
请问如何能够实现类似Editbox,listctrl,listbox这类控件的滚动条重画!是重画该控件还是重画scorll
自画 SCROLLBAR, 而且是自己建的SCROLLBAR,而不是CWND内建的SCROLLBAR.

First you have to instantiate a couple of CScroll bars in your main frame:

class CMainFrame : public CFrameWnd {
protected:
CScrollbar m_wndHScroll;
CScrollBar m_wndVScroll;
???
};

Then, create the windows in the usual way, when your frame is created:

int CMainFrame::OnCreate(...)
{
???
CRect rc(0,0,0,0);
VERIFY(m_wndSBHorz.Create(WS_VISIBLE|WS_CHILD|SBS_HORZ,
rc, this, AFX_IDW_HSCROLL_FIRST));
VERIFY(m_wndSBVert.Create(WS_VISIBLE|WS_CHILD|SBS_VERT,
rc, this, AFX_IDW_HSCROLL_FIRST+1));
VERIFY(m_wndSBBox.Create(WS_VISIBLE|WS_CHILD|SBS_SIZEBOX,
rc, this,-1));
return 0;
}

Oh, I forgot to mention: you also have to create a scroll bar box, the little thingy that goes where the horizontal and vertical scroll bars meet, so you can size your window and avoid a blank spot.
Once you've created the scroll bars, there are several things to take care of. You have to size them, process notifications, and get the view to use them. The last part is easy. CScrollView provides a virtual function, GetScrollBarCtrl, which you can override.

CScrollBar* CPictureView::GetScrollBarCtrl(int nBar) const
{
CWnd* pParent = GetParent();
UINT nID = AFX_IDW_HSCROLL_FIRST;
if (nBar==SB_VERT)
nID++;
return (CScrollBar*)pParent->GetDlgItem(nID);
}

This gets the appropriate control from the parent using the convenient IDs AFX_IDW_HSCROLL_FIRST and AFX_IDW_HSCROLL_FIRST+1.
What about scroll notifications? When the user scrolls, the scroll bar sends a WM_HSCROLL or WM_VSCROLL to its parent, and it's up to you to do something. Well, fortunately, you're in luck because if you put your scroll bars in the frame as I have suggested, CFrameWnd already has OnHScroll and OnVScroll handlers that route WM_HSCROLL and WM_VSCROLL to the view:

// From winfrm.cpp
void CFrameWnd::OnHScroll(...)
{
CWnd* pActiveView = GetActiveView();
if (pActiveView != NULL) {
pActiveView->SendMessage(WM_HSCROLL, ...);
}
}

If the view is a scroll view—that is, if you have derived your view from CScrollView—it does the scrolling. You don't have to do anything to handle scroll messages; MFC does it automatically!
What about sizing? That's where you have to do a little work. To make everything fly, you must manage the positions of the scroll bars whenever your frame is resized. Remember, the scroll bars are children of the frame, not the view. Normally you'd handle sizing in OnSize, but for frame windows the place to do it is in CFrameWnd::RecalcLayout.

void CMainFrame::RecalcLayout(BOOL)
{
CFrameWnd::RecalcLayout();
CView* pView = GetActiveView();
if (pView) {
// adjust view and scrollbars...
}
}

The details are a tedious exercise in pixel arithmetic; Figure 3 reveals all. I modified the ImgView program from last month's column to produce the ugly blue scroll bars in Figure 4. You can get the code from the link at the top of this article.


Figure 4 Blue Scroll Bars

Before I leave the topic of scroll bars, I should point out that post Microsoft? Internet Explorer 4.0 versions of ComCtrl32.dll support something called "flat scroll bars." There's a special API you can use to initialize and create these scroll bars without the 3D-look. For more info, see "Flat Scroll Bars" in the User Interface Design and Development section of the Platform SDK ocumentation.

http://msdn.microsoft.com/library/d...atSB/FlatSB.asp

Whether you use scroll bar controls as I've shown here, or flat scroll bars, you still can only set the background color of the scroll bar, so I question what value all this has. How useful is it to change only the background color? Most apps that have custom-colored scroll bars have custom-colored thumb slider and buttons as well. For that you have to write your own scroll bar control from scratch. But really, a scroll bar is pretty simple. All it does is let the user drag a box, send messages like WM_HSCROLL and WM_VSCROLL, and handle others like SB_PAGEUP and SB_THUMBPOSITION. It's not that hard. Another possible change to a simpler option is to use a normal scroll bar and override WM_ PAINT. I personally have never tried this, but in theory it might work. If anyone has ever been brave enough to try, let me know.... Happy programming!
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 10:40 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多