使用水平拟合图像调整窗口大小时的Thumtrack长度问题

时间:2014-02-13 08:37:41

标签: c++ windows

例如:如果我的图像宽度和高度是1600x2000,客户端窗口宽度和高度是900x600 ..现在我想水平地适合图像。为此,我将图像宽度(1600)降低到窗口宽度(900),并且为了保持图像的原始宽高比,我还将图像的高度(2000)降低到1125.因为我使用过FITHORIZONTAL中的以下逻辑然后我将使用下面的wm_size代码来设置滚动条位置和拇指长度。遗憾的是,即使拇指跟踪器已到达滚动条的末端,也不会显示完整图像。

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;  
     }  


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;  
              }  

0 个答案:

没有答案