当前位置:网站首页>MFC window scroll bar usage
MFC window scroll bar usage
2022-07-01 03:45:00 【Three Belle Wenzi】
Hello friends , I haven't updated my official account for several days , Because Wenzi went home to eat zongzi .
Today I want to share with you the usage of a window scroll bar . You'll wonder what a scroll bar is ? A scroll bar is a scrollable bar , As shown in the figure :

This is the scroll bar , So what's its function ? You can think about a fixed size interface , You have a lot of space , When there is no gap in the interface , At this time, you need a scroll bar to help expand the interface , Don't say anything , Look at the renderings first :

This is the effect of not using the interface scroll bar , We can see that there are 24 Button , this 24 Buttons are fixed , Then the width and height of the interface are fixed , Next, let's take a look at the renderings with scrollbars :

You can see the horizontal scroll bar and vertical scroll bar appear on the interface , You can pull the scroll bar up and down to expand the interface vertically , You can also pull the scroll bar left and right to expand the interface horizontally . however , One problem is : When you pull the scroll bar , The interface is unresponsive , It is because our code does not add the event function of the scroll bar , You need to add the response function of the scroll bar in the code of this interface .
The way to add a scroll bar to the interface is :
Select interface ;
Click interface properties , Put... In the attribute “ Vertical scroll bar ” and “ Horizontal scroll bar ” All set to True;
Then select the class of this interface in the class view , Then right-click properties , Then select the message in the attribute , Look in the message WM_HSCROLL and WM_VSCROLL, Add these two event functions :


Then add the following code to these two time functions :
void CceshiDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add message handler code and / Or call the default value
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
SCROLLINFO scrollinfo;
GetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
//
switch (nSBCode)
{
case SB_LEFT:
ScrollWindow((scrollinfo.nPos - scrollinfo.nMin) * 10, 0);
scrollinfo.nPos = scrollinfo.nMin;
SetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
break;
case SB_RIGHT:
ScrollWindow((scrollinfo.nPos - scrollinfo.nMax) * 10, 0);
scrollinfo.nPos = scrollinfo.nMax;
SetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
break;
case SB_LINELEFT:
scrollinfo.nPos -= 1;
if (scrollinfo.nPos < scrollinfo.nMin)
{
scrollinfo.nPos = scrollinfo.nMin;
break;
}
SetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
ScrollWindow(10, 0);
break;
case SB_LINERIGHT:
scrollinfo.nPos += 1;
if (scrollinfo.nPos > scrollinfo.nMax)
{
scrollinfo.nPos = scrollinfo.nMax;
break;
}
SetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
ScrollWindow(-10, 0);
break;
case SB_PAGELEFT:
scrollinfo.nPos -= 5;
if (scrollinfo.nPos < scrollinfo.nMin)
{
scrollinfo.nPos = scrollinfo.nMin;
break;
}
SetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
ScrollWindow(10 * 5, 0);
break;
case SB_PAGERIGHT:
scrollinfo.nPos += 5;
if (scrollinfo.nPos > scrollinfo.nMax)
{
scrollinfo.nPos = scrollinfo.nMax;
break;
}
SetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
ScrollWindow(-10 * 5, 0);
break;
case SB_THUMBPOSITION:
break;
case SB_THUMBTRACK:
ScrollWindow((scrollinfo.nPos - nPos) * 10, 0);
scrollinfo.nPos = nPos;
SetScrollInfo(SB_HORZ, &scrollinfo, SIF_ALL);
break;
case SB_ENDSCROLL:
break;
}
}
void CceshiDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add message handler code and / Or call the default value
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
SCROLLINFO scrollinfo;
GetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
switch (nSBCode)
{
case SB_LINEUP: //Scroll one line up
scrollinfo.nPos -= 1;
if (scrollinfo.nPos < scrollinfo.nMin)
{
scrollinfo.nPos = scrollinfo.nMin;
break;
}
SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
ScrollWindow(0, 10);
break;
case SB_LINEDOWN: //Scroll one line down
scrollinfo.nPos += 1;
if (scrollinfo.nPos + scrollinfo.nPage > scrollinfo.nMax) // Be sure to add the length of the slider here , Judge again
{
scrollinfo.nPos = scrollinfo.nMax;
break;
}
SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
ScrollWindow(0, -10);
break;
case SB_PAGEUP: //Scroll one page up.
scrollinfo.nPos -= 5;
if (scrollinfo.nPos <= scrollinfo.nMin)
{
scrollinfo.nPos = scrollinfo.nMin;
break;
}
SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
ScrollWindow(0, 10 * 5);
break;
case SB_PAGEDOWN: //Scroll one page down
scrollinfo.nPos += 5;
if (scrollinfo.nPos + scrollinfo.nPage >= scrollinfo.nMax) // Be sure to add the length of the slider here , Judge again
{
scrollinfo.nPos = scrollinfo.nMax;
break;
}
SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
ScrollWindow(0, -10 * 5);
break;
case SB_ENDSCROLL: //End scroll
break;
case SB_THUMBPOSITION: //Scroll to the absolute position. The current position is provided in nPos
break;
case SB_THUMBTRACK: //Drag scroll box to specified position. The current position is provided in nPos
ScrollWindow(0, (scrollinfo.nPos - nPos) * 10);
scrollinfo.nPos = nPos;
SetScrollInfo(SB_VERT, &scrollinfo, SIF_ALL);
break;
}
}
After adding, you can see the effect of the interface as shown in the following figure :

That is, the scroll bar can be pulled at will , The interface can be expanded horizontally and vertically .
边栏推荐
- FCN全卷积网络理解及代码实现(来自pytorch官方实现)
- The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
- 使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
- ASGNet论文和代码解读2
- 复习专栏之---消息队列
- AfxMessageBox和MessageBox的用法
- Cygwin的下载和安装配置
- 10、Scanner. Next() cannot read spaces /indexof -1
- 392. judgment subsequence
- Leetcode:829. Sum of continuous integers
猜你喜欢

【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍

【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算

整合阿里云短信的问题:无法从静态上下文中引用非静态方法
![[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes](/img/be/325f78dee744138a865c13d2c20475.png)
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes

还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板

Implement pow (x, n) function

Pyramid Scene Parsing Network【PSPNet】论文阅读

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

Feature pyramid networks for object detection
随机推荐
8. string conversion integer (ATOI)
Explain spark operation mode in detail (local+standalone+yarn)
Appium自动化测试基础 — APPium基本原理
389. 找不同
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
10. 正则表达式匹配
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
【快捷键】
Implement pow (x, n) function
168. excel table column name
208. implement trie (prefix tree)
Cygwin的下载和安装配置
What happens when a function is called before it is declared in C?
Golang multi graph generation gif
LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
[nine day training] content III of the problem solution of leetcode question brushing Report
205. isomorphic string
Research on target recognition and tracking based on 3D laser point cloud
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars