⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scrollbar.c

📁 MinGUI 可视化程序代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 /******************************************************************************
*
* Copyright  2006 National ASIC Center, All right Reserved
*
* FILE NAME:			scrollbar.c
* PROGRAMMER:			ming.c
* Date of Creation:		2006/08/8
*
* DESCRIPTION: 								
*						
* NOTE:						 		
*
* FUNCTIONS LIST:
* -----------------------------------------------------------------------------
*
* -----------------------------------------------------------------------------
*
* MODIFICATION HISTORY
*     LastModify  2006/09/20
******************************************************************************/
#include "mingui.h"
//---------------------------------------------------------------------------
typedef struct t_scrollbar
{ int ScrollbarDragging,flipflop;
  int Left,Top,Right,Bottom;
  int TrackHeight,ScrollTop,ScrollHeight;
  int TotalLine,TopLine,LinePerPage;
  int PageKeepLines; /*滚屏时一页最少保持的行数*/
}TScrollBar;
//---------------------------------------------------------------------------
#define DesignationW                   16
#define ScrollHeightAttenuationParam   20 
#define WndScrollBar(hWnd)             ( (TScrollBar *)((char *)hWnd+sizeof(TWND)+((PWND)hWnd)->WinClass->cbWndExtra) )
void ScrollBar_UpdateScroll(HWND hWnd,TScrollBar *scrollbar,BOOL bRepaint);
void ScrollBar_PaintTrack(HDC dc,TScrollBar *scrollbar);
void ScrollBar_UpdateFlipflopButton(HWND hWnd,TScrollBar *scrollbar,int flipflop);
//---------------------------------------------------------------------------
void ScrollBar_CalcuSize(HWND hWnd,TRECT *ClientRect)
{ TScrollBar *scrollbar= WndScrollBar(hWnd);
  ClientRect->right-=DesignationW;
  scrollbar->ScrollbarDragging=scrollbar->flipflop=0;
  scrollbar->Top=WNDPTR(hWnd)->ClientRect.top-WNDPTR(hWnd)->WndRect.top;
  scrollbar->Left=WNDPTR(hWnd)->ClientRect.right-WNDPTR(hWnd)->WndRect.left;
  scrollbar->Right=scrollbar->Left+DesignationW;
  scrollbar->Bottom=WNDPTR(hWnd)->ClientRect.bottom-WNDPTR(hWnd)->WndRect.top;
  scrollbar->TrackHeight=scrollbar->Bottom - scrollbar->Top - (DesignationW<<1);
  if(scrollbar->TrackHeight<0) scrollbar->TrackHeight=0;

  scrollbar->ScrollTop=scrollbar->Top+DesignationW;
  scrollbar->ScrollHeight=0;

  scrollbar->TotalLine=0;
  scrollbar->TopLine=0;
  scrollbar->LinePerPage=0;  
  scrollbar->PageKeepLines=0;
}
//---------------------------------------------------------------------------
int ScrollBar_DataSize(void)
{ return sizeof(TScrollBar);
}
//---------------------------------------------------------------------------
void ScrollBar_Initialize(HWND hWnd,int TopLine,int TotalLine,int LinePerPage,int PageKeepLines)
{ if(WndGetAttr(hWnd,WS_VSCROLL|WS_BORDER)==(WS_VSCROLL|WS_BORDER))
  { TScrollBar *scrollbar= WndScrollBar(hWnd);
    scrollbar->TotalLine=TotalLine;
    scrollbar->TopLine=TopLine;
    scrollbar->PageKeepLines=PageKeepLines;
	scrollbar->LinePerPage=(LinePerPage<1)?1:LinePerPage;
	ScrollBar_UpdateScroll(hWnd,scrollbar,false);
  }
}
//---------------------------------------------------------------------------
void ScrollBar_Synchronize(HWND hWnd,int topLine)
{ if(WndGetAttr(hWnd,WS_VSCROLL|WS_BORDER)==(WS_VSCROLL|WS_BORDER) && topLine>=0)
  { TScrollBar *scrollbar= WndScrollBar(hWnd);
    if(topLine!=scrollbar->TopLine && topLine<scrollbar->TotalLine)
	{ scrollbar->TopLine=topLine;
	  if(scrollbar->ScrollHeight>0)
	  { int newscrolltop=scrollbar->Top+DesignationW+topLine*(scrollbar->TrackHeight-scrollbar->ScrollHeight)/(scrollbar->TotalLine-scrollbar->PageKeepLines);
	    if(newscrolltop!=scrollbar->ScrollTop)
		{ HDC dc=GetDC(hWnd);
	      scrollbar->ScrollTop=newscrolltop;
	      ScrollBar_PaintTrack(dc,scrollbar);
	      ReleaseDC(dc);
		}
	  }
	} 
  }
}
//---------------------------------------------------------------------------
void ScrollBar_Synchronize2(HWND hWnd,int topLine,int totalLine)
{ if( WndGetAttr(hWnd,WS_VSCROLL|WS_BORDER)==(WS_VSCROLL|WS_BORDER) )
  { TScrollBar *scrollbar=WndScrollBar(hWnd);
	if(topLine>=0 && totalLine>topLine)
    { if(scrollbar->TotalLine!=totalLine)
      { scrollbar->TotalLine=totalLine;
	    scrollbar->TopLine=topLine;
        ScrollBar_UpdateScroll(hWnd,scrollbar,true);
      }
      else if(topLine!=scrollbar->TopLine)
	  { ScrollBar_Synchronize(hWnd,topLine-scrollbar->TopLine);
	  }
	}
    else if(totalLine<=0 && scrollbar->TotalLine>0)
	{ scrollbar->TotalLine=0;
	  scrollbar->TopLine=0;
      ScrollBar_UpdateScroll(hWnd,scrollbar,true);
	}
  }
}
//---------------------------------------------------------------------------
void ScrollBar_UpdateFlipflopButton(HWND hWnd,TScrollBar *scrollbar,int flipflop)
{  HDC dc=GetDC(hWnd);
   int triangleW=DesignationW>>1;
   int triangleH=DesignationW>>2;
   
   GroupOn(dc);
    
   if(flipflop==0)
   { SetColor(dc,CL_BLACK);
   }
   else
   { SetColor(dc,CL_WHITE);
   }
   
   if(scrollbar->TrackHeight>0)
   { if (flipflop==1 || scrollbar->flipflop==1)
	 { DrawLine(dc,scrollbar->Left+4,scrollbar->Top+triangleW+1,scrollbar->Left+triangleW,scrollbar->Top+5);
	   DrawLine(dc,scrollbar->Left+DesignationW-4,scrollbar->Top+triangleW+1,scrollbar->Left+triangleW,scrollbar->Top+5);
	   //DrawLine(dc,scrollbar->Left+5,scrollbar->Top+triangleW+2,scrollbar->Left+triangleW,scrollbar->Top+7);
	   //DrawLine(dc,scrollbar->Left+DesignationW-5,scrollbar->Top+triangleW+2,scrollbar->Left+triangleW,scrollbar->Top+7);
       GroupOff(dc,scrollbar->Left,scrollbar->Top,DesignationW,DesignationW);
	 }
     else if(flipflop==2 || scrollbar->flipflop==2)
	 { DrawLine(dc,scrollbar->Left+4,scrollbar->Bottom-triangleW-1,scrollbar->Left+triangleW,scrollbar->Bottom-5);
       DrawLine(dc,scrollbar->Left+DesignationW-4,scrollbar->Bottom-triangleW-1,scrollbar->Left+triangleW,scrollbar->Bottom-5);
	   //DrawLine(dc,scrollbar->Left+5,scrollbar->Bottom-triangleW-2,scrollbar->Left+triangleW,scrollbar->Bottom-7);
       //DrawLine(dc,scrollbar->Left+DesignationW-5,scrollbar->Bottom-triangleW-2,scrollbar->Left+triangleW,scrollbar->Bottom-7);
       GroupOff(dc,scrollbar->Left,scrollbar->Bottom-DesignationW,DesignationW,DesignationW);
	 }
   }
   else
   { int triangleOffsetX=scrollbar->Left+(DesignationW-triangleW)/2;
     int i,designationY=(scrollbar->Top+scrollbar->Bottom)>>1;
     if (flipflop==1 || scrollbar->flipflop==1)
	 { for(i=0;i<triangleH-2;i++)
	      DrawHorLine(dc,triangleOffsetX+i+2,designationY-i-3,triangleW-i-i-4);
	   GroupOff(dc,triangleOffsetX+2,designationY-triangleH,triangleW-4,triangleH-2);
	 }
     else if(flipflop==2 || scrollbar->flipflop==2)
	 { for(i=0;i<triangleH-2;i++)
	     DrawHorLine(dc,triangleOffsetX+i+2,designationY+i+3,triangleW-i-i-4);
	   GroupOff(dc,triangleOffsetX+2,designationY+3,triangleW-4,triangleH-2);
	 }
   }
   scrollbar->flipflop=flipflop;
   ReleaseDC(dc);
}
//---------------------------------------------------------------------------
void ScrollBar_MouseUp(HWND hWnd)
{ TScrollBar *scrollbar= WndScrollBar(hWnd);
  if(scrollbar->ScrollbarDragging)
  { scrollbar->ScrollbarDragging=false;
  }
  if(scrollbar->flipflop)
  { ScrollBar_UpdateFlipflopButton(hWnd,scrollbar,0);
  }
}
//---------------------------------------------------------------------------
void ScrollBar_MouseMove(HWND hWnd,LPARAM LParam)
{ TScrollBar *scrollbar= WndScrollBar(hWnd);
  if(scrollbar->ScrollbarDragging)
  { int xPos=LOWORD(LParam)-WNDPTR(hWnd)->WndRect.left;
    int yPos=HIWORD(LParam)-WNDPTR(hWnd)->WndRect.top;
    if(PointInRect(xPos, yPos, (TRECT *)&scrollbar->Left))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -