Winapi 滚动图
我正在尝试绘制一个带有滚动条的图形,Winapi 滚动图,winapi,graph,scrollbar,wm-paint,Winapi,Graph,Scrollbar,Wm Paint,我正在尝试绘制一个带有滚动条的图形, 图表使用时间表示x轴,我希望有一个有限的x轴(1分钟) 所以直到1分钟,滚动条的页面是滚动条的长度, 在此之后,页面应为“60秒长”,滚动条的最大长度应为“已用时间” 拖动滚动条时,滚动条会跟踪,并调出图形的相关位。 图形应自动滚动,直到其被拖走(并在拖回最大值后自动滚动) 这就是我目前所拥有的 在wndproc的顶部定义 staticScrollInfo sci={sizeof(SCROLLINFO),SIF_范围| SIF_位置| SIF_页面| SIF
图表使用时间表示x轴,我希望有一个有限的x轴(1分钟)
所以直到1分钟,滚动条的页面是滚动条的长度,
在此之后,页面应为“60秒长”,滚动条的最大长度应为“已用时间”
拖动滚动条时,滚动条会跟踪,并调出图形的相关位。
图形应自动滚动,直到其被拖走(并在拖回最大值后自动滚动) 这就是我目前所拥有的 在wndproc的顶部定义
staticScrollInfo sci={sizeof(SCROLLINFO),SIF_范围| SIF_位置| SIF_页面| SIF_轨迹位置,0,0,0}代码>
在WM_HSCROLL事件中:
GetScrollInfo((HWND)lParam, SB_CTL, &sci);
int pos;
pos = sci.nPos;
switch(LOWORD(wParam))
{
case SB_PAGELEFT:
pos -= sci.nPage;
break;
case SB_LINELEFT:
pos -= (sci.nMax/10);
break;
case SB_PAGERIGHT:
pos += sci.nPage;
break;
case SB_LINERIGHT:
pos += (sci.nMax/10);
break;
case SB_THUMBTRACK:
tsTracking = true;
pos = sci.nTrackPos;
break;
case SB_THUMBPOSITION:
tsTracking = false;
pos = sci.nTrackPos;
break;
}
if (pos < sci.nMin) pos = sci.nMin;
if (pos > sci.nMax) pos = sci.nMax;
if (pos != sci.nPos)
{
sci.fMask = SIF_POS;
sci.nPos = pos;
if(sci.nPos >= (sci.nMax-(sci.nPage*1.2)-1)) //this should detect when the thumb has reached the end of the scrollbar
sci.nPos = sci.nMax;
SetScrollInfo((HWND)lParam, SB_CTL, &sci, TRUE);
PostMessage(hWnd, WM_COMMAND, IDM_DISPLAYRESULTS, 0);
}
break;
至于全球的:
g_h_minX
是开始时间,
g_h_maxX
是最后一次结果时间
MAX\u TIME\u WIDTH\u MS
是“窗口长度”,单位为MS->我想要滚动条页面的时间长度(60秒)
因此,我们的想法是将end
设置到滚动条所在的位置,然后通过从end
获取窗口长度,并计算出我们要查看的图形的哪一部分来获取start
在过去的两天里,我一直在摆弄这个,我的想法都快用完了。
我相信我很接近,但我不太明白
编辑:
稍微更新了代码
似乎我也忘了说问题出在哪里了。
scolling代码工作不正常,当新数据进入时会自动滚动,
但是,当我将拇指从滚动条的末端拖开时,它只会捕捉到开始,并且不会移动。
仔细观察,箭头起作用,右键单击菜单上的“page right”和“page left”起作用,而不是跟踪
任何帮助都将不胜感激
提前谢谢。我已经找到了问题,
我最终把所有的东西都转换成了秒,然后用它来工作,结果工作起来了,所以我一定是遇到了一些缩放问题。
代码的结尾是这样的:
case WM_HSCROLL:
{
SCROLLINFO sci = {sizeof(SCROLLINFO),SIF_RANGE|SIF_POS|SIF_PAGE|SIF_TRACKPOS,0,0,0,0,0};
GetScrollInfo((HWND)lParam, SB_CTL, &sci);
int pos;
pos = sci.nPos;
switch(LOWORD(wParam))
{
case SB_PAGELEFT:
pos -= sci.nPage;
break;
case SB_LINELEFT:
pos -= 2;
break;
case SB_PAGERIGHT:
pos += sci.nPage;
break;
case SB_LINERIGHT:
pos += 2;
break;
case SB_THUMBTRACK:
tsTracking = true;
pos = sci.nTrackPos;
break;
case SB_THUMBPOSITION:
tsTracking = false;
pos = sci.nTrackPos;
break;
case SB_LEFT:
pos = sci.nMin;
break;
case SB_RIGHT:
pos = sci.nMax;
break;
}
if (pos < sci.nMin) pos = sci.nMin;
if (pos > sci.nMax) pos = sci.nMax;
if (pos != sci.nPos)
{
sci.fMask = SIF_POS;
sci.nPos = pos;
//if(sci.nPos >= (sci.nMax-sci.nPage)) //this should detect when the thumb has reached the end of the scrollbar
// sci.nPos = sci.nMax;
SetScrollInfo((HWND)lParam, SB_CTL, &sci, TRUE);
PostMessage(hWnd, WM_COMMAND, IDM_DISPLAYRESULTS, 0);
}
}
break;
case WM\HSCROLL:
{
SCROLLINFO sci={sizeof(SCROLLINFO),SIF_范围| SIF_位置| SIF_页面| SIF_轨迹位置,0,0,0};
GetScrollInfo((HWND)LPRAM、SB_CTL和sci);
int pos;
pos=sci.NPO;
开关(LOWORD(wParam))
{
案例SB_PAGELEFT:
pos-=sci.nPage;
打破
案例SB_左:
pos-=2;
打破
案例SB_PAGERIGHT:
pos+=sci.nPage;
打破
案例SB_LINERIGHT:
pos+=2;
打破
案例SB_THUMBTRACK:
tsTracking=true;
pos=sci.nTrackPos;
打破
案例SB_位置:
tsTracking=false;
pos=sci.nTrackPos;
打破
案例SB_左:
pos=sci.nMin;
打破
案例SB_右:
pos=sci.nMax;
打破
}
如果(possci.nMax)pos=sci.nMax;
如果(位置!=sci.NPO)
{
sci.fMask=SIF_POS;
sci.nPos=pos;
//if(sci.nPos>=(sci.nMax sci.nPage))//这应该检测拇指何时到达滚动条的末端
//sci.nPos=sci.nMax;
SetScrolInfo((HWND)LPRAM、SB_CTL和sci,TRUE);
PostMessage(hWnd,WM_命令,IDM_显示结果,0);
}
}
打破
用于滚动代码和
__int64
elapsed_time = g_h_maxX-g_h_minX, //the elapsed time
windowLengthMS, //the current window length in ms (between 0 and MAX_TIME_WIDTH_MS)
start, //the start of the current window
end; //the end of the current window
static UINT32 windowMaxS = 1; //how long the window max is (used for x sub-divisions)
double
xTickStep, //x division step
yTickStep, //y division step
xScale, //x-scale (used to get the time relative to the elapsed time and size of the graph)
yScale; //y-scale (used to get the data being plotted relative to its max, and the size of the graph)
GetScrollInfo(get_chwnd(IDCW_HARMONICSRESULTSTIMESHIFTSB),SB_CTL,&sci); //gets the scroll info for the scrollbar
if (elapsed_time >= MAX_TIME_WIDTH_MS) //if elapsed time is longer then the max window length
{
start = _SECSTOMS(sci.nPos); //sets start to end - window length
end = start+MAX_TIME_WIDTH_MS; //set the end to current (scroll position / scroll max) * latest time -> this should put end relative to the scrollbar
}
else //if (elapsed_time <= MAX_TIME_WIDTH_MS)
{
start = g_h_minX; //start is min
end = g_h_maxX; //end is max
}
windowLengthMS = (end-start); //find the current window length
if(_MSTOSECS(windowLengthMS) > windowMaxS) //if the current window length beats one fo the markers
windowMaxS = ((windowMaxS < 10)?windowMaxS+1:(windowMaxS==40)?windowMaxS*1.5:windowMaxS*2); //change subdiv scaling
xScale = double(graph_width)/double(windowLengthMS); //set x-scale to width / window length
yScale = (double)(graph_height)/((double)max - (double)g_h_minY); //set y-scale to height / (maxVal-minVal)
if(!(g_h_maxY-g_h_minY))
yScale = 1;
if(!windowLengthMS)
xScale = 1;
int ticks = _MSTOSECS(elapsed_time); //ticks = full seconds elapsed
xTickStep = double(graph_width)/double(ticks+1); //tickstep = seconds+1 (accounts for 0)
yTickStep = double(graph_height)/double(Y_TICKS); //6 y-ticks, constant.
\uuu int64
已用时间=g_h_maxX-g_h_minX,//已用时间
windowLengthMS,//以毫秒为单位的当前窗口长度(介于0和最大\u时间\u宽度\u毫秒之间)
start,//当前窗口的开始
结束//当前窗口的结尾
静态UINT32 windowMaxS=1//窗口最大长度(用于x子分区)
双重的
xTickStep,//x除法步骤
yTickStep,//y除法步骤
xScale,//x-scale(用于获取相对于经过的时间和图形大小的时间)
yScale//y比例(用于获取相对于其最大值和图形大小绘制的数据)
GetScrollInfo(get_chwnd(IDCW_HarmonicsResultsTimeShift SB)、SB_CTL和sci)//获取滚动条的滚动信息
if(经过的\u时间>=最大时间\u宽度\u毫秒)//如果经过的时间长于最大窗口长度
{
开始=_SECSTOMS(sci.nPos);//设置开始到结束-窗口长度
end=start+MAX\u TIME\u WIDTH\u MS;//将end设置为当前(滚动位置/滚动最大)*最新时间->这应该相对于滚动条放置end
}
else//if(已用时间窗口最大值)//如果当前窗口长度超过一个标记
windowMaxS=((windowMaxS<10)?windowMaxS+1:(windowMaxS==40)?windowMaxS*1.5:windowMaxS*2)//更改细分曲面缩放
xScale=double(图形宽度)/double(窗口长度)//将x比例设置为宽度/窗口长度
yScale=(双)图形高度/(双)最大值-(双)g_h_最小值)//将y比例设置为高度/(maxVal-minVal)
if(!(g_h_maxY-g_h_minY))
yScale=1;
如果(!windowLengthMS)
xScale=1;
int ticks=_MSTOSECS(经过的时间)//滴答声=已过去的完整秒数
xTickS
__int64
elapsed_time = g_h_maxX-g_h_minX, //the elapsed time
windowLengthMS, //the current window length in ms (between 0 and MAX_TIME_WIDTH_MS)
start, //the start of the current window
end; //the end of the current window
static UINT32 windowMaxS = 1; //how long the window max is (used for x sub-divisions)
double
xTickStep, //x division step
yTickStep, //y division step
xScale, //x-scale (used to get the time relative to the elapsed time and size of the graph)
yScale; //y-scale (used to get the data being plotted relative to its max, and the size of the graph)
GetScrollInfo(get_chwnd(IDCW_HARMONICSRESULTSTIMESHIFTSB),SB_CTL,&sci); //gets the scroll info for the scrollbar
if (elapsed_time >= MAX_TIME_WIDTH_MS) //if elapsed time is longer then the max window length
{
start = _SECSTOMS(sci.nPos); //sets start to end - window length
end = start+MAX_TIME_WIDTH_MS; //set the end to current (scroll position / scroll max) * latest time -> this should put end relative to the scrollbar
}
else //if (elapsed_time <= MAX_TIME_WIDTH_MS)
{
start = g_h_minX; //start is min
end = g_h_maxX; //end is max
}
windowLengthMS = (end-start); //find the current window length
if(_MSTOSECS(windowLengthMS) > windowMaxS) //if the current window length beats one fo the markers
windowMaxS = ((windowMaxS < 10)?windowMaxS+1:(windowMaxS==40)?windowMaxS*1.5:windowMaxS*2); //change subdiv scaling
xScale = double(graph_width)/double(windowLengthMS); //set x-scale to width / window length
yScale = (double)(graph_height)/((double)max - (double)g_h_minY); //set y-scale to height / (maxVal-minVal)
if(!(g_h_maxY-g_h_minY))
yScale = 1;
if(!windowLengthMS)
xScale = 1;
int ticks = _MSTOSECS(elapsed_time); //ticks = full seconds elapsed
xTickStep = double(graph_width)/double(ticks+1); //tickstep = seconds+1 (accounts for 0)
yTickStep = double(graph_height)/double(Y_TICKS); //6 y-ticks, constant.