ش | ی | د | س | چ | پ | ج |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
void CListBoxEx::SetBkColor(COLORREF crBkColor,COLORREF crSelectedColor)
{
//Deletes previous brush. Must do in order to create a new one m_BkBrush.DeleteObject();
//Sets the brush the specified background color m_BkBrush.CreateSolidBrush(crBkColor); Invalidate();
//Forces Redraw
}
Function DrawBorders()
GetClientRect hlist,Crect
InflateRect Crect,GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)
'Since we'll be using m_bOver, let's 'initialize it. Add m_bOver = 'FALSE; on PreSubclassWindow.
if (m_bOver) Then
DrawEdge hdc,Crect,EDGE_BUMP,BF_RECT
Else
DrawEdge hdc,Crect,EDGE_SUNKEN,BF_RECT
End If
ReleaseDC hdc
End Function
WM_MOUSEAVE
m_bOver=FALSE
DrawBorders()
We then set them to an initial value under PreSubclassWindow:
m_bOver = FALSE;
m_ItemHeight=18; m_crTextHlt=GetSysColor(COLOR_HIGHLIGHTTEXT);
m_crTextClr=GetSysColor(COLOR_WINDOWTEXT);
m_HBkColor=GetSysColor(COLOR_HIGHLIGHT);
m_BmpWidth=16;
m_BmpHeight=16;
MeasureItem:
lpMeasureItemStruct->itemHeight=m_ItemHeight;
we can resize the client area. This can be done by receiving the message WM_NCCALCSIZE
lpncsp->rgrc[0].top += 16; //Top
lpncsp->rgrc[0].bottom -= 16; //Bottom
OnNcPaint()
static BOOL before=FALSE
if (!before) Then
SetWindowPos(NULL,0,0,0,0,SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE before=TRUE
DrawBorders()
DrawScrolls(UINT WhichOne, UINT State)
pDC=GetDC()
CRect rect
GetClientRect hwnd,Crect)
if (IsWindowEnabled())State=SC_DISABLED; //Expands the so that it does not draw over the borders
Crect.left=Crect.left-GetSystemMetrics(SM_CYEDGE) Crect.right= Crect.right+GetSystemMetrics(SM_CXEDGE)
if (WhichOne==SC_UP)
rect.bottom=rect.top-GetSystemMetrics(SM_CXEDGE) rect.top=rect.top-16-GetSystemMetrics(SM_CXEDGE)
'Draws the scroll up
DrawFrameControl pDC,Crect,DFC_SCROLL,State Or DFCS_SCROLLUP)
else
'Needs to draw down rect.top=rect.bottom+GetSystemMetrics(SM_CXEDGE) rect.bottom=rect.bottom+16+GetSystemMetrics(SM_CXEDGE); DrawFrameControl pDC,Crect,DFC_SCROLL,State Or DFCS_SCROLLDOWN
ReleaseDC pDC
pubic const SC_UP=2
public const SC_DOWN=3
OnEnable
'SC_NORMAL will be changed to 'SC_DISABLED if the window is disabled DrawScrolls(SC_UP,SC_NORMAL) DrawScrolls(SC_DOWN,SC_NORMAL);
OnNcLButtonDown(UINT nHitTest, CPoint point)
if (nHitTest=HTVSCROLL) 'Up scroll Pressed DrawScrolls(SC_UP,SC_PRESSED) 'Scroll up 1 line SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0)
SetTimer(1,100,NULL)'Sets the timer ID 1
else if (nHitTest==HTHSCROLL)'Down scroll Pressed DrawScrolls(SC_DOWN,SC_PRESSED) ' Scroll down 1 line SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0) SetTimer(2,100,NULL) 'Sets the timer ID 2
OnTimer(UINT nIDEvent)
result=GetKeyState(VK_LBUTTON)
if (nIDEvent==1) ' Up timer If it returns negative then it is pressed
if (result<0)
SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0)
else ' No longer pressed
KillTimer(1) DrawScrolls(SC_UP,SC_NORMAL)
else 'Down timer
'If it returns negative then it is pressed
if (result<0)
SendMessage(WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0)
else
KillTimer(2)
DrawScrolls(SC_DOWN,SC_NORMAL)
OnNcHitTest(CPoint point)
CRect rect,top,bottom
GetWindowRect hwnd,Crect
ScreenToClient hwnd,Crect)
top=bottom=rect
top.bottom=rect.top+16 bottom.top=rect.bottom-16
'Obtains where the mouse is
UINT
where=CListBox::OnNcHitTest(point)
'Converts the point so its relative to the client area
ScreenToClient hwnd,&point)
if (where == HTNOWHERE) 'If mouse is not in a place it recognizes
if (PtInRect(top,point)) 'Check to see if the mouse is on the top
where=HTVSCROLL
else if (PtInRect(bottom,point)) 'Check to see if its on the bottom
where=HTHSCROLL
return where ' Returns where it is
WM_NCLBUTTONDOWN 0x00A1
Parameters
wParam
The hit-test value returned by the DefWindowProc function as a result of processing the WM_NCHITTEST message. For a list of hit-test values, see WM_NCHITTEST.
lParam
A POINTS structure that contains the x- and y-coordinates of the cursor. The coordinates are relative to the upper-left corner of the screen.