当前位置:网站首页>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 .
边栏推荐
- Appium自动化测试基础--补充:C/S架构和B/S架构说明
- 数据库中COMMENT关键字的使用
- [TA frost wolf \u may- hundred people plan] 1.3 secret of texture
- 复习专栏之---消息队列
- 4、【WebGIS实战】软件操作篇——数据导入及处理
- Blueprism registration, download and install -rpa Chapter 1
- 165. compare version numbers
- Sort linked list (merge sort)
- 深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
- 【TA-霜狼_may-《百人计划》】1.1 渲染流水线
猜你喜欢

整合阿里云短信的问题:无法从静态上下文中引用非静态方法
![[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model](/img/05/85c004e4fbfc8d4984ac04ddb1190b.png)
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model

Pytorch training deep learning network settings CUDA specified GPU visible
![[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation

Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)

Leetcode 128 longest continuous sequence (hash set)

Promql select time series

The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)

LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表

Valentine's Day is nothing.
随机推荐
6. zigzag transformation
ASGNet论文和代码解读2
214. minimum palindrome string
Ultimate dolls 2.0 | encapsulation of cloud native delivery
Appium自动化测试基础 — APPium基本原理
Gorilla/mux framework (RK boot): RPC error code design
MFC窗口滚动条用法
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
【TA-霜狼_may-《百人计划》】1.1 渲染流水线
AfxMessageBox和MessageBox的用法
8. string conversion integer (ATOI)
205. 同构字符串
Download and installation configuration of cygwin
【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
Leetcode:829. 连续整数求和
Valid brackets (force deduction 20)
[shortcut key]
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
还在浪费脑细胞自学吗,这份面试笔记绝对是C站天花板