滚动条缩略图跟踪长度 基于图像的水平适合调整窗口大小时出现问题
scroll bar ThumbTrack length Issue when resizing window Based on Horizontal fit for Image
int ActualImageWidth = 1000;
int ActualImageHeight = 1200;
int WindowWidth = 800;
int WindowHeight = 500;
float resizedPercent;
为了达到水平最佳拟合,我想在不更改实际图像纵横比的情况下将实际图像宽度减小或增加为窗口宽度。并且我还应该根据新的调整大小的图像(窗口调整大小)保持滚动条拇指轨道长度。为此,我进行了以下计算
switch(FitType)
{
case FITHORIZONTAL:
//find out whether resize percentage is decrease or increase
if(ActualImageWidth > WindowWidth) //resize decreasing
{
//find out the pecentage of decreased value
resizedPercent = WindowWidth/ActualImageWidth;
} else //resize increasing
{
//find out the pecentage of increased value
resizedPercent = ActualImageWidth/WindowWidth;
}
ResizedWidth = iWndwidth;
ResizedHeight = ActualImageHeight * resizedPercent;
break;
}
为了设置滚动条,wm_size事件我使用以下代码
LRESULT CALLBACK my_wnd_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static SCROLLINFO si;
static RECT rect;
int WndWidth = 0;
int WndHeight = 0;
case WM_CREATE :
{
//getting image data from here.
return 0;
}
case WM_SIZE :
{
GetWindowRect(hWnd, &rect);
WndWidth = rect.right - rect.left;
WndHeight = rect.bottom - rect.top;
GetScrollInfo(hWnd, SB_VERT, &si);
int yMaxScroll = max((int)ResizedHeight - WndHeight, 0);
int yCurrentScroll = min(si.nPos, yMaxScroll);
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMin = 0;
si.nMax = ResizedHeight;
si.nPage = WndHeight;
si.nPos = 0;
SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
InvalidateRect(hWnd, &rect, true);
return 0;
}
case WM_PAINT :
{
//try to draw image here..
return 0;
}
}
我的问题是我无法获得确切的滚动条拇指轨道,因此我无法滚动图像直到图像末尾。请用样本建议正确的逻辑
注意:如果您以@o_weisman开头的评论,我将收到针对我的评论通知。在我的代码中,我也像这样覆盖 OnVScroll,它对我有用(您需要调整它以处理窗口的滚动消息:
void CMagDialog::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
{
int nDelta;
int nMaxPos = yMaxScroll;
if(pScrollBar == NULL)
{
switch (nSBCode)
{
case SB_LINEDOWN:
if (m_vScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/100,nMaxPos-m_vScrollPos);
break;
case SB_LINEUP:
if (m_vScrollPos <= 0)
return;
nDelta = -min(nMaxPos/100,m_vScrollPos);
break;
case SB_PAGEDOWN:
if (m_vScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/5,nMaxPos-m_vScrollPos);
break;
case SB_THUMBPOSITION:
nDelta = (int)nPos - m_vScrollPos;
break;
case SB_PAGEUP:
if (m_vScrollPos <= 0)
return;
nDelta = -min(nMaxPos/5, m_vScrollPos);
break;
default:
return;
}
m_vScrollPos += nDelta;
SetScrollPos(SB_VERT,m_vScrollPos,TRUE);
ScrollWindow(0,-nDelta);
}
}
相关文章:
- 为char数组调整zlib-zpipe
- 调整大小后指向元素值的指针unordered_map有效?
- QTableView:endMoveRows在模型中重置水平页眉大小
- 在C++中调整向量中的索引
- QScrollArea:由垂直滚动条引起的水平滚动条
- 哪些库可以通过Opencv调整曝光率
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- Alt+Enter 在 Win32 应用中,管理大小调整和分辨率
- 在容量内调整矢量大小时的性能影响
- 将 boost::odeint 与向量类一起使用,而无需调整向量的大小
- 将摄像机调整到俯视图
- Qt 图表条形图调整大小崩溃
- 除非重新绘制大小,否则SDL_Texture在调整大小后呈现黑色
- 调整布局上的 QGraphicsView 小部件的大小
- 如何在构建链接列表时调整头、尾指针
- 如何将旧的 C 样式 #define 映射与现代C++进行调整?
- 当您在此单词中搜索单词时调整字符数组的大小?
- 滚动条缩略图跟踪长度 基于图像的水平适合调整窗口大小时出现问题
- 图像水平调整算法
- 添加水平滚动条来调整窗口对话框的大小