📄 scrlbar.c
字号:
}
}
else
{ // 水平 SB_HORZ
if( (lprcNew->right - lprcNew->left) < MIN_THUMBSIZE )
{
rect = *lprcNew;
#ifdef ZT_PHONE
InflateRect( &rect, 0, -1 );
#endif
FillRect( hdc, &rect, GetSysColorBrush(COLOR_SCROLLBAR) );
return 0;
}
}
{
int iOldMode;
int xyMid;
HFONT hFont;
BYTE bThumb;
RECT rect = *lprcNew;
//画滑块
hBrush = GetSysColorBrush( COLOR_SCROLLBARTHUMB );//COLOR_3DFACE );
hBrush = SelectObject( hdc, hBrush );
Rectangle( hdc, lprcNew->left, lprcNew->top, lprcNew->right, lprcNew->bottom );
hBrush = SelectObject( hdc, hBrush );
// 选择符号字体 draw text
hFont = SelectObject( hdc, GetStockObject(SYSTEM_FONT_SYMBOL) );
iOldMode = SetBkMode( hdc, TRANSPARENT );
if( fnBar == SB_VERT )
{ //垂直
xyMid = (lprcNew->bottom + lprcNew->top) / 2;
rect.top = xyMid - 8;
rect.bottom = xyMid + 8;
bThumb = SYM_SCROLL_VTHUMB;
}
else
{ //水平
xyMid = (lprcNew->left + lprcNew->right) / 2;
rect.left = xyMid - 8;
rect.right = xyMid + 8;
bThumb = SYM_SCROLL_HTHUMB;
}
SetTextColor( hdc, CL_WHITE );
DrawText( hdc, (LPCTSTR)&bThumb, 1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
SetTextColor( hdc, CL_DARKGRAY );
if( fnBar == SB_VERT )
{
rect.top++;
rect.bottom++;
}
else
{
rect.left++;
rect.right++;
}
DrawText( hdc, (LPCTSTR)&bThumb, 1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
SetBkMode( hdc, iOldMode );
SelectObject( hdc, hFont );
}
return 0;
}
// **************************************************
// 声明:static int Scrl_DrawScrollBar( _LPSCROLL lpsd, HDC hdc )
// 参数:
// IN lpsd - 滚动条数据对象指针
// IN hdc - 显示DC
// 返回值:
// 返回0
// 功能描述:
// 画滚动条
// 引用:
//
// ************************************************
static int Scrl_DrawScrollBar( _LPSCROLL lpsd, HDC hdc )
{
RECT rect;
int drawPos[6];
HFONT hFont;
int iOldMode;
BYTE bArrow;
if( lpsd->fnBar == SB_CORNER )
{ //右下角
FillRect( hdc, &lpsd->rect, GetSysColorBrush(COLOR_3DFACE) );
}
else
{ //显示矩形
rect = lpsd->rect;
// 选择符号字体
hFont = SelectObject( hdc, GetStockObject(SYSTEM_FONT_SYMBOL) );//
//得到显示位置
Scrl_GetDrawPos( lpsd, drawPos );
if( lpsd->fnBar == SB_VERT )
{ //垂直
rect.top = drawPos[1];
rect.bottom = drawPos[4];
#ifdef ZT_PHONE
{
HBRUSH hBrush = GetSysColorBrush(COLOR_SCROLLBAR);
hBrush = SelectObject( hdc, hBrush );
Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
SelectObject( hdc, hBrush );
}
#else
FillRect( hdc, &rect, GetSysColorBrush(COLOR_SCROLLBAR) );
#endif
// 画上箭头 draw up arrow
rect.top = drawPos[0];
rect.bottom = drawPos[1];
Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
iOldMode = SetBkMode( hdc, TRANSPARENT );
if( lpsd->sd.state & ESB_DISABLE_UP )
SetTextColor( hdc, GetSysColor(COLOR_GRAYTEXT) );
else
SetTextColor( hdc, GetSysColor(COLOR_BTNTEXT) );
bArrow = SYM_UPARROW;
DrawText( hdc, (LPCTSTR)&bArrow, 1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
// 画下箭头 draw down arrow
rect.top = drawPos[4];
rect.bottom = drawPos[5];
SetBkMode( hdc, OPAQUE );
Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
if( lpsd->sd.state & ESB_DISABLE_DOWN )
SetTextColor( hdc, GetSysColor(COLOR_GRAYTEXT) );//CL_LIGHTGRAY );
else
SetTextColor( hdc, GetSysColor(COLOR_BTNTEXT) );//CL_BLACK );
bArrow = SYM_DOWNARROW;
SetBkMode( hdc, TRANSPARENT );
DrawText( hdc, (LPCTSTR)&bArrow, 1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
// draw thumb
rect.top = drawPos[2];
rect.bottom = drawPos[3];
SetBkMode( hdc, iOldMode );
Scrl_DrawThumbBox( hdc, SB_VERT, lpsd->sd.state, 0, &rect );
}
else if( lpsd->fnBar == SB_HORZ )
{ //水平
rect.left = drawPos[1];
rect.right = drawPos[4];
#ifdef ZT_PHONE
{
HBRUSH hBrush = GetSysColorBrush(COLOR_SCROLLBAR);
hBrush = SelectObject( hdc, hBrush );
Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
SelectObject( hdc, hBrush );
}
#else
FillRect( hdc, &rect, GetSysColorBrush(COLOR_SCROLLBAR) );
#endif
rect.left = drawPos[0];
rect.right = drawPos[1];
Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
iOldMode = SetBkMode( hdc, TRANSPARENT );
//画左箭头
if( lpsd->sd.state & ESB_DISABLE_LEFT )
SetTextColor( hdc, GetSysColor(COLOR_GRAYTEXT) );//CL_LIGHTGRAY );
else
SetTextColor( hdc, GetSysColor(COLOR_BTNTEXT) );//CL_BLACK );
bArrow = SYM_LEFTARROW;
DrawText( hdc, (LPCTSTR)&bArrow, 1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
rect.left = drawPos[4];
rect.right = drawPos[5];
SetBkMode( hdc, OPAQUE );
Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom );
if( lpsd->sd.state & ESB_DISABLE_RIGHT )
SetTextColor( hdc, GetSysColor(COLOR_GRAYTEXT) );//CL_LIGHTGRAY );
else
SetTextColor( hdc, GetSysColor(COLOR_BTNTEXT) );//CL_BLACK );
//画右箭头
bArrow = SYM_RIGHTARROW;
SetBkMode( hdc, TRANSPARENT );
DrawText( hdc, (LPCTSTR)&bArrow, 1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
SetBkMode( hdc, iOldMode );
rect.left = drawPos[2];
rect.right = drawPos[3];
Scrl_DrawThumbBox( hdc, SB_HORZ, lpsd->sd.state, 0, &rect );
}
SelectObject( hdc, hFont );
}
return 0;
}
// **************************************************
// 声明:int Scrl_RedrawScrollBar( HWND hWnd, HDC hdc, int fnBar )
// 参数:
// IN hWnd - 窗口句柄
// IN hdc - 显示DC句柄
// IN fnBar - 滚动条类型,为下值:
// SB_VERT - 垂直
// SB_HORT - 水平
//
// 返回值:
// 返回0
// 功能描述:
// 画滚动条
// 引用:
//
// ************************************************
int Scrl_RedrawScrollBar( HWND hWnd, HDC hdc, int fnBar )
{
_SCROLL sd;
//得到滚动条数据
Scrl_GetScrollData( hWnd, fnBar, &sd );
//画
Scrl_DrawScrollBar( &sd, hdc );
return 0;
}
// **************************************************
// 声明:static void Scrl_TranslatePos( HWND hWnd, int fnBar, short * lpx, short * lpy )
// 参数:
// IN hWnd - 窗口句柄
// IN fnBar - 滚动条类型,为下值:
// SB_VERT - 垂直
// SB_HORT - 水平
// IN/OUT lpx - 输入客户x坐标,输出窗口x坐标
// IN/OUT lpy - 输入客户y坐标,输出窗口y坐标
// 返回值:
// 返回0
// 功能描述:
// 将客户坐标转成窗口坐标
// 引用:
//
// ************************************************
static void Scrl_TranslatePos( HWND hWnd, int fnBar, short * lpx, short * lpy )
{
POINT pt;
RECT rect;
if( fnBar != SB_CTL )
{
if( lpx )
pt.x = *lpx;
if( lpy )
pt.y = *lpy;
//先转化为屏幕坐标
ClientToScreen( hWnd, &pt );
//得到窗口的屏幕矩形
GetWindowRect( hWnd, &rect );
//转化
if( lpx )
*lpx = (short)(pt.x - rect.left);
if( lpy )
*lpy = (short)(pt.y - rect.top);
}
}
// **************************************************
// 声明:LRESULT Scrl_DoLBUTTONDOWN( HWND hWnd, int fnBar, int x, int y )
// 参数:
// IN hWnd - 窗口句柄
// IN fnBar - 滚动条类型,为下值:
// SB_VERT - 垂直
// SB_HORT - 水平
// IN x - 当前鼠标x位置
// IN y - 当前鼠标y位置
// 返回值:
// 返回0
// 功能描述:
// 处理 WM_LBUTTONDOWN 消息
// 引用:
//
// ************************************************
#define SLEEP_TICK 200
LRESULT Scrl_DoLBUTTONDOWN( HWND hWnd, int fnBar, int x, int y )
{
_SCROLL si;
int posv[6], pos, oldPos, i;
short nx, ny;
HDC hdc;
HBRUSH hBrush;
RECT rect, oldRect;
MSG msg;
UINT dwMsg;
BOOL edgeMsg = FALSE;
WORD ncode;
BOOL bHasTimer = FALSE;
DWORD dwTickCount;
//得到滚动条数据
Scrl_GetScrollData( hWnd, fnBar, &si );
rect = si.rect;
//得到显示位置
Scrl_GetDrawPos( &si, posv );
pos = (si.fnBar==SB_VERT) ? y : x;
//得到鼠标在滚动条上的位置信息(i)
for( i = 0; i < 5; i++ )
if( pos >= posv[i] && pos < posv[i+1] )
break;
if( si.fnBar == SB_VERT )
{ //垂直
rect.top = posv[i];
rect.bottom = posv[i+1];
dwMsg = WM_VSCROLL;
}
else
{ //水平
rect.left = posv[i];
rect.right = posv[i+1];
dwMsg = WM_HSCROLL;
}
if( i == 0 || i == 4 )
{ //在上/左 下/右 箭头区域
ncode = (i == 0) ? SB_LINEUP : SB_LINEDOWN;
}
else if( i == 1 || i == 3 )
{ //在上页 下页区域
ncode = (i == 1 ) ? SB_PAGEUP : SB_PAGEDOWN;
}
else if( i == 2 )
{ //在滑快
ncode = SB_THUMBTRACK;
}
if( (si.sd.state & ESB_DISABLE_LTUP) &&
(ncode == SB_LINEUP || ncode == SB_PAGEUP || ncode == SB_THUMBTRACK ) )
{ //无效上
return 0;
}
else if ( (si.sd.state & ESB_DISABLE_RTDN) &&
(ncode == SB_LINEDOWN || ncode == SB_PAGEDOWN || ncode == SB_THUMBTRACK ) )
{ //无效下
return 0;
}
if( i == 2 )
{ //设置跟踪状态
Scrl_SetScrollState( hWnd, fnBar, SBS_TRACKTHUMB, TRUE );
}
oldRect = rect;
oldPos = si.sd.nPos;
//抓住鼠标
SetCapture( hWnd );
if( ncode != SB_THUMBTRACK )
Scrl_SendScrollMsg( hWnd, fnBar, dwMsg, MAKELONG( ncode, 0 ), (LPARAM)hWnd );
//得到显示DC
hdc = Scrl_GetScrollDC( hWnd, fnBar );
hBrush = (HBRUSH)SelectObject( hdc, GetStockObject( LTGRAY_BRUSH ) );
#ifdef EML_DOS
_ShowMouse();
#endif
if( ncode != SB_THUMBTRACK )
{
bHasTimer = TRUE;
}
dwTickCount = GetTickCount();
//进入模式处理状态
// do modal loop
while( GetCapture() == hWnd )
{
BOOL bHandleTimer = FALSE;
if( bHasTimer )
SetSysTimer( hWnd, IDSCROLLBAR, SLEEP_TICK, NULL );
//得到消息
if( GetMessage( &msg, 0, 0, 0 ) )
{ //处理消息
if( bHasTimer )
KillSysTimer( hWnd, IDSCROLLBAR );
if( msg.message == WM_LBUTTONUP )
{
#ifdef EML_DOS
_HideMouse();
#endif
if( i == 1 || i == 3 )
{
// InvertRect( hdc, &rect );
}
if( i == 0 || i == 4 )
{
// DrawEdge( hdc, &rect, BDR_RAISEDOUTER, BF_RECT );
}
#ifdef EML_DOS
_ShowMouse();
#endif
if( i == 2 )
{ // clear background
//#ifdef EML_DOS
// _HideMouse();
//#endif
// Scrl_DrawThumbBox( hdc, fnBar, &oldRect, FALSE );
//#ifdef EML_DOS
// _ShowMouse();
//#endif
//画滑快
Scrl_SetScrollState( hWnd, fnBar, SBS_TRACKTHUMB, FALSE );
Scrl_SendScrollMsg( hWnd, fnBar, dwMsg, MAKELONG( SB_THUMBPOSITION, oldPos ), (LPARAM)hWnd );
}
Scrl_SendScrollMsg( hWnd, fnBar, dwMsg, (WPARAM)MAKELONG( SB_ENDSCROLL, 0 ), (LPARAM)hWnd );
if( i == 2 )
{
// redraw thumb box
Scrl_GetScrollData( hWnd, fnBar, &si );
Scrl_GetDrawPos( &si, posv );
if( si.fnBar == SB_VERT )
{
rect.top = posv[i];
rect.bottom = posv[i+1];
}
else if( si.fnBar == SB_HORZ )
{
rect.left = posv[i];
rect.right = posv[i+1];
}
#ifdef EML_DOS
_HideMouse();
#endif
Scrl_DrawThumbBox( hdc, si.fnBar, si.sd.state, &oldRect, &rect ); //2000.12.08
#ifdef EML_DOS
_ShowMouse();
#endif
}
break;
}
else if( msg.message == WM_MOUSEMOVE )
{
if( i == 2 )
{ // thumb box
if( si.fnBar == SB_VERT )
{
ny = HIWORD( msg.lParam );
Scrl_TranslatePos( hWnd, fnBar, 0, &ny );
ny = ny - y;
// draw thumb box
rect.top = posv[2] + ny;
rect.bottom = posv[3] + ny;
if( rect.bottom <= posv[4] && rect.top >= posv[1] )
{
#ifdef EML_DOS
_HideMouse();
#endif
// clear background
// draw thumb box
Scrl_DrawThumbBox( hdc, fnBar, si.sd.state, &oldRect, &rect );
#ifdef EML_DOS
_ShowMouse();
#endif
oldRect = rect;
{ // LN, 2003-07-12 error: ( posv[4] - posv[1] - (posv[3]-posv[2]) ) == 0
int diff = ( posv[4] - posv[1] - (posv[3]-posv[2]) );
if( diff )
pos = si.sd.nMin + (rect.top-posv[1]) * (si.sd.nMax-si.sd.nMin-si.sd.nPage+1) / diff;
else
{ // diff = 0
;// nothing to do
}
}
if( pos != oldPos )
{
Scrl_SendScrollMsg( hWnd, fnBar, dwMsg, MAKELONG( SB_THUMBTRACK, pos ), (LPARAM)hWnd );
oldPos = pos;
}
edgeMsg = FALSE;
}
else if( edgeMsg == FALSE )
{
if( rect.bottom > posv[4] )
{
pos = si.sd.nMax - si.sd.nPage + 1;
Scrl_SendScrollMsg( hWnd, fnBar, dwMsg, MAKELONG( SB_THUMBTRACK, pos ), (LPARAM)hWnd );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -