Активный курсор в Scroll Bar.
Компилятор: Visual C++ 6
Автор: Siarhei Akulich.
Данный пример позволяет динамически менять
курсор на scrollbar-е окна. Переменные m_nVIDResource и
m_nHIDResource используются для предотвращения
множественной загрузки курсора.
CMyWnd наследован от CWnd.
UINT m_nVIDResource;
UINT m_nHIDResource;
CMyWnd::CMyWnd()
{
m_nVIDResource = 0;
m_nHIDResource = 0;
}
BOOL CMyWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if(nHitTest == HTVSCROLL)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VSCROLLBAR));
if(m_nVIDResource != IDC_VSCROLLBAR)
m_nVIDResource = IDC_VSCROLLBAR;
return true;
}
else if(nHitTest == HTHSCROLL)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HSCROLLBAR));
if(m_nHIDResource != IDC_HSCROLLBAR)
m_nHIDResource = IDC_HSCROLLBAR;
return true;
}
else
{
if(m_nVIDResource != 0) m_nVIDResource = 0;
if(m_nHIDResource != 0) m_nHIDResource = 0;
}
return BaseClass::OnSetCursor(pWnd, nHitTest, message);
}
void CMyWnd::OnVScroll(UINT nSBCode, UINT nPos,
CScrollBar* pScrollBar)
{
switch (nSBCode) {
case SB_THUMBTRACK:
if(m_nVIDResource != IDC_VTHUMBTRACK)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VTHUMBTRACK));
m_nVIDResource = IDC_VTHUMBTRACK;
}
break;
case SB_LINEDOWN:
if(GetScrollPos(SB_VERT) == GetScrollLimit(SB_VERT))
{
if(m_nVIDResource != IDC_VLINEDOWN_DISABLE)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VLINEDOWN_DISABLE));
m_nVIDResource = IDC_VLINEDOWN_DISABLE;
}
}
else if(m_nVIDResource != IDC_VLINEDOWN)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VLINEDOWN));
m_nVIDResource = IDC_VLINEDOWN;
}
break;
case SB_LINEUP: вверх
SCROLLINFO info;
info.cbSize = sizeof(SCROLLINFO);
GetScrollInfo(SB_VERT, >info);
if(info.nPos == info.nMin)
{
if(m_nVIDResource != IDC_VLINEUP_DISABLE)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VLINEUP_DISABLE));
m_nVIDResource = IDC_VLINEUP_DISABLE;
}
}
else if(m_nVIDResource != IDC_VLINEUP)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VLINEUP));
m_nVIDResource = IDC_VLINEUP;
}
break;
case SB_PAGEDOWN:
if(m_nVIDResource != IDC_VPAGEDOWN)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VPAGEDOWN));
m_nVIDResource = IDC_VPAGEDOWN;
}
break;
case SB_PAGEUP: вверх
if(m_nVIDResource != IDC_VPAGEUP)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_VPAGEUP));
m_nVIDResource = IDC_VPAGEUP;
}
break;
}
BaseClass::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CMyWnd::OnHScroll(UINT nSBCode, UINT nPos,
CScrollBar* pScrollBar)
{
switch (nSBCode) {
case SB_THUMBTRACK:
if(m_nHIDResource != IDC_HTHUMBTRACK)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HTHUMBTRACK));
m_nHIDResource = IDC_HTHUMBTRACK;
}
break;
case SB_LINEDOWN:
if(GetScrollPos(SB_HORZ) == GetScrollLimit(SB_HORZ))
{
if(m_nHIDResource != IDC_HLINEDOWN_DISABLE)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HLINEDOWN_DISABLE));
m_nHIDResource = IDC_HLINEDOWN_DISABLE;
}
}
else if(m_nHIDResource != IDC_HLINEDOWN)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HLINEDOWN));
m_nHIDResource = IDC_HLINEDOWN;
}
break;
case SB_LINEUP: вверх
SCROLLINFO info;
info.cbSize = sizeof(SCROLLINFO);
GetScrollInfo(SB_HORZ, &info);
if(info.nPos == info.nMin)
{
if(m_nHIDResource != IDC_HLINEUP_DISABLE)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HLINEUP_DISABLE));
m_nHIDResource = IDC_HLINEUP_DISABLE;
}
}
else if(m_nHIDResource != IDC_HLINEUP)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HLINEUP));
m_nHIDResource = IDC_HLINEUP;
}
break;
case SB_PAGEDOWN:
if(m_nHIDResource != IDC_HPAGEDOWN)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HPAGEDOWN));
m_nHIDResource = IDC_HPAGEDOWN;
}
break;
case SB_PAGEUP: вверх
if(m_nHIDResource != IDC_HPAGEUP)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_HPAGEUP));
m_nHIDResource = IDC_HPAGEUP;
}
break;
}
BaseClass::OnHScroll(nSBCode, nPos, pScrollBar);
}
Downloads
Скачать демонстрационный
пример - 49 Kb
|