// ListXP.cpp: implementation of the CListXP class.
//
//////////////////////////////////////////////////////////////////////
/**************�������ñ��������ÿ��������**********************/
//ͷ��
////////////////////////////////////////////////////////////////////////////////////////////////////
// ����Ԥ����
#if _WIN32_WINNT < 0x0400
#define _WIN32_WINNT 0x0400
#endif
#if WINVER < 0x0500
#define WINVER 0x0500
#endif // WINVER < 0x0500


// ǿ��ʹ�� C ���Է�ʽ����
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus
#include "SpinXP.h"
#include "ScrollXP.H"
#include <CommCtrl.H>

//////////////////////////////////////////////////////////////////////////////////////////////////
// ȫ�ֱ���
extern HHOOK g_hPrevHookXP ;		// ������Ϣ HOOK ���
extern PCLASSXP g_pClassXP ;		// ���ڵ� CLASSXP �ṹָ��
extern COLORREF g_crDialogbkColor;  // ���ڱ�����ɫ
//////////////////////////////////////////////////////////////
/****************************************************************/
////////////////////////////////////////////////////////////////////////////////////////////////////
// ������ת�ؼ�
VOID WINAPI SpinDrawSpinBox(const PCLASSXP pCxp)
{
	RECT Rect;
	int i;
	MEMDCXP Mdcxp;
	HANDLE hHandle;
	PCLASSXP pEditCxp;
	HDC hDC;
    HWND hWnd;
	// ��ȡ�ڴ�����豸����
	Mdcxp.hWnd = pCxp->hWnd;
	Mdcxp.bTransfer = FALSE;
	Mdcxp.hBitmap = NULL;
	GetMemDCXP(&Mdcxp);
	hWnd = pCxp->hWnd;
//    hDC = GetWindowDC(hWnd);
	hDC = Mdcxp.hMemDC;
	if(hDC == NULL) return;
    if((pCxp->dwState & CXPU_ALIGNLEFT) || (pCxp->dwState & CXPU_ALIGNRIGHT))
	{
		pEditCxp = GetClassXP((HWND) SendMessage(hWnd, UDM_GETBUDDY, 0, 0));
		CXPM_SETSTATE(pCxp->dwState, CXPS_DISABLED, pEditCxp->dwState & CXPS_DISABLED);
	}
	else
		pEditCxp = NULL;

	GetClientRect(hWnd, &Rect);	

	if (pEditCxp)
	{
#ifdef CXP_BKCOLOR
		// �������
		hHandle = (HANDLE) CreateSolidBrush(
			(pCxp->dwState & CXPS_DISABLED) ? (CXP_BKCOLOR - 0x00202020) : 0x00BD9E7B);
#else // CXP_BKCOLOR
		// �������
		hHandle = (HANDLE) CreateSolidBrush(
			(pCxp->dwState & CXPS_DISABLED) ? (GetSysColor(COLOR_BTNFACE) - 0x00202020) : 0x00BD9E7B);
#endif // CXP_BKCOLOR
		FrameRect(hDC, &Rect, (HBRUSH)hHandle);
		DeleteObject((HGDIOBJ) hHandle);

#ifdef CXP_BKCOLOR
		hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1,
			(pCxp->dwState & CXPS_DISABLED) || (pEditCxp->lState & CXPE_READONLY) ?
			CXP_BKCOLOR : GetSysColor(COLOR_WINDOW)));
#else // CXP_BKCOLOR
		hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1,
			GetSysColor((pCxp->dwState & CXPS_DISABLED) || (pEditCxp->dwState & CXPE_READONLY) ?
			COLOR_BTNFACE : COLOR_WINDOW)));
#endif // CXP_BKCOLOR
		MoveToEx(hDC, (pCxp->dwState & CXPU_ALIGNLEFT) ? Rect.right - 1 : 0, 1, NULL);
		LineTo(hDC, (pCxp->dwState & CXPU_ALIGNLEFT) ? Rect.right - 1 : 0, Rect.bottom - 1);
		DeleteObject(SelectObject(hDC, hHandle));
		InflateRect(&Rect, -1, -1);
	}

	FillRect(hDC, &Rect, GetSysColorBrush(COLOR_WINDOW));
	InflateRect(&Rect, -1, -1);

	if (pCxp->dwState & CXPS_HORIZON)
		Rect.left += (Rect.right - Rect.left) / 2;
	else
		Rect.top += (Rect.bottom - Rect.top) / 2;

	i = pCxp->dwState | CXPH_SMALLARROW;
	if (pCxp->dwState & CXPU_UPPART)
	{
		i &= ~CXPS_HOTLIGHT;
		i &= ~CXPS_PRESSED;
	}
	
	i |= (pCxp->dwState & CXPS_HORIZON) ? CXPH_RIGHTWARDS : CXPH_DOWNWARDS;

//	DropThumbXP(Mdcxp.hMemDC, &Rect, i);
	ScrollDrowThumbXP(hDC, Rect, i);

	i = pCxp->dwState | CXPH_SMALLARROW;
	i |= (pCxp->dwState & CXPS_HORIZON) ? CXPH_LEFTWARDS : CXPH_UPWARDS;
	if (!(pCxp->dwState & CXPU_UPPART))
	{
		i &= ~CXPS_HOTLIGHT;
		i &= ~CXPS_PRESSED;
	}
	if (pCxp->dwState & CXPS_HORIZON)
	{
		Rect.right = Rect.left;
		Rect.left = pEditCxp ? 2 : 1;
	}
	else
	{
		Rect.bottom = Rect.top;
		Rect.top = pEditCxp ? 2: 1;
	}
//	DropThumbXP(Mdcxp.hMemDC, &Rect, i);
	ScrollDrowThumbXP(hDC, Rect, i);

	// ��ԭ���ͷ��ڴ��豸����
	Mdcxp.bTransfer = TRUE;
	ReleaseMemDCXP(&Mdcxp);
//	ReleaseDC(hWnd, hDC);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT SpinWindowProc(PCLASSXP pCxp, UINT message,WPARAM wParam, LPARAM lParam)
{
//	SCROLLINFO sif;
	LONG lReturn;
	RECT Rect;
	HWND hWnd = pCxp->hWnd;
	switch (message)
		{
		case WM_PAINT:
		case WM_NCPAINT:
		    SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
			lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
		    SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
			SpinDrawSpinBox(pCxp);
			return lReturn;
//			return CXPC_DRAWCLASSXP | CXPC_PRECALLDEFPROC;
        case WM_LBUTTONDBLCLK:
			return TRUE;
		case WM_LBUTTONDOWN:
			pCxp->dwState |= CXPS_PRESSED;
		    SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
			lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
		    SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
			SpinDrawSpinBox(pCxp);
			return lReturn;
//			return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC;

		case WM_LBUTTONUP:
			pCxp->dwState &= ~CXPS_PRESSED;
		    SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
			lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
		    SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
			SpinDrawSpinBox(pCxp);
			return lReturn;
//			return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC;

		case WM_MOUSEMOVE:
			GetClientRect(hWnd, &Rect);
			if (pCxp->dwState & CXPU_UPPART)
			{
				if (((pCxp->dwState & CXPS_HORIZON) && (LOWORD(lParam) > Rect.right / 2)) ||
					(!(pCxp->dwState & CXPS_HORIZON) && (HIWORD(lParam) > Rect.bottom / 2)))
				{
					pCxp->dwState &= ~CXPU_UPPART;
		            SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
			        lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
		             SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
			        SpinDrawSpinBox(pCxp);
			        return lReturn;
//					return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC | CXPC_CALLCOMMON;
				}
			}
			else
			{
				if (((pCxp->dwState & CXPS_HORIZON) && (LOWORD(lParam) <= Rect.right / 2)) ||
					(!(pCxp->dwState & CXPS_HORIZON) && (HIWORD(lParam) <= Rect.bottom / 2)))
				{
					pCxp->dwState |= CXPU_UPPART;
		            SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
			        lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
		            SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
			        SpinDrawSpinBox(pCxp);
			        return lReturn;
					//return CXPC_DRAWCLASSXP | CXPC_PRECALLWNDPROC | CXPC_CALLCOMMON;
				}
			}
			return DefWindowProc(hWnd, message, wParam, lParam);
//			return CXPC_CALLCOMMON;

		case WM_ERASEBKGND:
			return TRUE;
		}
/*	switch (message)
		{
		case WM_PAINT:
		case WM_NCPAINT:
			pCxp->dwState |= CXPS_NOPAINT;
			lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
			SpinDrawSpinBoxXP(pCxp);
			return lReturn;
		}
*/
// ����ԭ���Ļص�����
	lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
	if (message == WM_NCDESTROY)		// ��������
		DeleteClassXP(hWnd);
	return lReturn;
}


/**************�������ñ��������ÿ��������**********************/
//�
#ifdef __cplusplus
}
#endif // __cplusplus
/*****************************************************************/