当前位置:网站首页>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 .
边栏推荐
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- pytorch nn.AdaptiveAvgPool2d(1)
- Edlines: a real time line segment detector with a false detection control
- Leetcode:829. Sum of continuous integers
- Pytorch training deep learning network settings CUDA specified GPU visible
- What happens when a function is called before it is declared in C?
- Use of comment keyword in database
- Promql select time series
- 389. find a difference
- 【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算
猜你喜欢

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

Promql select time series

【TA-霜狼_may-《百人计划》】2.2 模型与材质空间

Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)

How keil displays Chinese annotations (simple with pictures)

Asgnet paper and code interpretation 2

【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
![[nine day training] content III of the problem solution of leetcode question brushing Report](/img/7e/1e76181e56ef7feb083f9662df71c7.jpg)
[nine day training] content III of the problem solution of leetcode question brushing Report

Binary tree god level traversal: Morris traversal

Sort linked list (merge sort)
随机推荐
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
What happens when a function is called before it is declared in C?
在线公网安备案保姆级教程【伸手党福利】
Pytorch training deep learning network settings CUDA specified GPU visible
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
MFC窗口滚动条用法
10. regular expression matching
241. 为运算表达式设计优先级
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
Leetcode:829. 连续整数求和
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture
392. judgment subsequence
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
171. excel table column No
30. Concatenate substrings of all words
30. 串联所有单词的子串
187. repeated DNA sequences
Golang multi graph generation gif
程序员女友给我做了一个疲劳驾驶检测
4、【WebGIS实战】软件操作篇——数据导入及处理