CUSTDRAW.CPP
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:10k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- #include "../stdafx.h"
- #include "coolscroll.h"
- #include "detours.h"
- extern HDC hdcSkin;
- typedef struct
- {
- int x, y;
- int width, height;
- } CustomDrawTable;
- // Define a set of structures which describe
- // where-abouts the source "textures" are in the
- // custom draw bitmap. We need to know x, y, width and height
- // for each scrollbar segment.
- CustomDrawTable cdt_horz_normal[] =
- {
- { 0, 0, 18, 18 }, //left arrow NORMAL
- { 0, 19, 18, 18 }, //right arrow NORMAL
- { 0, 83, 1, 18 }, //page left NORMAL
- { 0, 83, 1, 18 }, //page right NORMAL
- { -1, -1, -1, -1 }, //padding
- { 54, 0, 9, 18 }, //horz thumb (left)
- { 54+9, 0, 1, 18 }, //horz thumb (middle)
- { 54+9, 0, 9, 18 }, //horz thumb (right)
- };
- CustomDrawTable cdt_horz_hot[] =
- {
- { 18, 0, 18, 18 }, //left arrow ACTIVE
- { 18, 19, 18, 18 }, //right arrow ACTIVE
- { 4, 83, 1, 18 }, //page left ACTIVE
- { 4, 83, 1, 18 }, //page right ACTIVE
- { -1, -1, -1, -1 }, //padding
- { 54, 19, 9, 18 }, //horz thumb (left)
- { 54+9, 19, 1, 18 }, //horz thumb (middle)
- { 54+9, 19, 9, 18 }, //horz thumb (right)
- };
- CustomDrawTable cdt_horz_active[] =
- {
- { 36, 0, 18, 18 }, //left arrow ACTIVE
- { 36, 19, 18, 18 }, //right arrow ACTIVE
- { 4, 83, 1, 18 }, //page left ACTIVE
- { 4, 83, 1, 18 }, //page right ACTIVE
- { -1, -1, -1, -1 }, //padding
- { 54, 38, 9, 18 }, //horz thumb (left)
- { 54+9, 38, 1, 18 }, //horz thumb (middle)
- { 54+9, 38, 9, 18 }, //horz thumb (right)
- };
- CustomDrawTable cdt_vert_normal[] =
- {
- { 72, 0, 18, 18 }, //up arrow NORMAL
- { 72, 19, 18, 18 }, //down arrow NORMAL
- { 0, 112, 18, 1 }, //page up NORMAL
- { 0, 112, 18, 1 }, //page down NORMAL
- { -1, -1, -1, -1 }, //padding
- { 126, 0, 18, 9 }, //vert thumb (left)
- { 126, 9, 18, 1 }, //vert thumb (middle)
- { 126, 9, 18, 9 }, //vert thumb (right)
- };
- CustomDrawTable cdt_vert_hot[] =
- {
- { 90, 0, 18, 18 }, //up arrow ACTIVE
- { 90, 19, 18, 18 }, //down arrow ACTIVE
- { 4, 83, 18, 1 }, //page up ACTIVE
- { 4, 83, 18, 1 }, //page down ACTIVE
- { -1, -1, -1, -1 }, //padding
- { 126, 19, 18, 9 }, //vert thumb (left)
- { 126, 28, 18, 1 }, //vert thumb (middle)
- { 126, 28, 18, 9 }, //vert thumb (right)
- };
- CustomDrawTable cdt_vert_active[] =
- {
- { 108, 0, 18, 18 }, //up arrow ACTIVE
- { 108, 19, 18, 18 }, //down arrow ACTIVE
- { 4, 83, 18, 1 }, //page up ACTIVE
- { 4, 83, 18, 1 }, //page down ACTIVE
- { -1, -1, -1, -1 }, //padding
- { 126, 38, 18, 9 }, //vert thumb (left)
- { 126, 47, 18, 1 }, //vert thumb (middle)
- { 126, 47, 18, 9 }, //vert thumb (right)
- };
- LRESULT HandleCustomDraw(UINT ctrlid, NMCSBCUSTOMDRAW *nm)
- {
- RECT *rc;
- CustomDrawTable *cdt;
- UINT code = NM_CUSTOMDRAW;
- UNREFERENCED_PARAMETER(ctrlid);
- if(nm->dwDrawStage == CDDS_PREPAINT)
- return CDRF_SKIPDEFAULT;
- //the sizing gripper in the bottom-right corner
- if(nm->nBar == SB_BOTH)
- {
- RECT *rc = &nm->rect;
- StretchBlt(nm->hdc, rc->left, rc->top, rc->right-rc->left, rc->bottom-rc->top,
- hdcSkin, 100, 100, 18, 18, SRCCOPY);
- return CDRF_SKIPDEFAULT;
- }
- else if(nm->nBar == SB_HORZ)
- {
- rc = &nm->rect;
- if(nm->uState == CDIS_HOT)
- cdt = &cdt_horz_hot[nm->uItem];
- else if(nm->uState == CDIS_SELECTED)
- cdt = &cdt_horz_active[nm->uItem];
- else
- cdt = &cdt_horz_normal[nm->uItem];
- if(nm->uItem == HTSCROLL_THUMB)
- {
- StretchBlt(nm->hdc, rc->left, rc->top, 9, rc->bottom-rc->top, hdcSkin, cdt->x, cdt->y, cdt->width, cdt->height, SRCCOPY);
- cdt++;
- StretchBlt(nm->hdc, rc->left+9, rc->top, (rc->right-rc->left)-18, rc->bottom-rc->top, hdcSkin, cdt->x, cdt->y, cdt->width, cdt->height, SRCCOPY);
- cdt++;
- StretchBlt(nm->hdc, rc->left+(rc->right-rc->left)-9, rc->top, 9, rc->bottom-rc->top, hdcSkin, cdt->x, cdt->y, cdt->width, cdt->height, SRCCOPY);
- return CDRF_SKIPDEFAULT;
- }
- }
- else if(nm->nBar == SB_VERT)
- {
- rc = &nm->rect;
- if(nm->uState == CDIS_HOT)
- cdt = &cdt_vert_hot[nm->uItem];
- else if(nm->uState == CDIS_SELECTED)
- cdt = &cdt_vert_active[nm->uItem];
- else
- cdt = &cdt_vert_normal[nm->uItem];
- if(nm->uItem == HTSCROLL_THUMB)
- {
- StretchBlt(nm->hdc, rc->left, rc->top, rc->right-rc->left, 9, hdcSkin, cdt->x, cdt->y, cdt->width, cdt->height, SRCCOPY);
- cdt++;
- StretchBlt(nm->hdc, rc->left, rc->top+9, rc->right-rc->left, (rc->bottom-rc->top)-18, hdcSkin, cdt->x, cdt->y, cdt->width, cdt->height, SRCCOPY);
- cdt++;
- StretchBlt(nm->hdc, rc->left, rc->top+(rc->bottom-rc->top)-9, rc->right-rc->left, 9,hdcSkin, cdt->x, cdt->y, cdt->width, cdt->height, SRCCOPY);
- return CDRF_SKIPDEFAULT;
- }
- }
- else
- {
- return CDRF_DODEFAULT;
- }
- //normal bitmaps, use same code for HORZ and VERT
- StretchBlt(nm->hdc, rc->left, rc->top, rc->right-rc->left, rc->bottom-rc->top,
- hdcSkin, cdt->x, cdt->y, cdt->width, cdt->height, SRCCOPY);
- return CDRF_SKIPDEFAULT;
- }
- //////////////////////////////////////////////////////
- DETOUR_TRAMPOLINE(BOOL WINAPI Detour_EnableScrollBar(HWND hwnd, int wSBflags, UINT wArrows), EnableScrollBar);
- DETOUR_TRAMPOLINE(BOOL WINAPI Detour_GetScrollInfo (HWND hwnd, int fnBar, LPSCROLLINFO lpsi), GetScrollInfo);
- DETOUR_TRAMPOLINE(int WINAPI Detour_GetScrollPos (HWND hwnd, int nBar), GetScrollPos);
- DETOUR_TRAMPOLINE(BOOL WINAPI Detour_GetScrollRange (HWND hwnd, int nBar, LPINT lpMinPos, LPINT lpMaxPos), GetScrollRange);
- DETOUR_TRAMPOLINE(int WINAPI Detour_SetScrollInfo (HWND hwnd, int fnBar, LPSCROLLINFO lpsi, BOOL fRedraw), SetScrollInfo);
- DETOUR_TRAMPOLINE(int WINAPI Detour_SetScrollPos (HWND hwnd, int nBar, int nPos, BOOL fRedraw), SetScrollPos);
- DETOUR_TRAMPOLINE(int WINAPI Detour_SetScrollRange (HWND hwnd, int nBar, int nMinPos, int nMaxPos, BOOL fRedraw), SetScrollRange);
- DETOUR_TRAMPOLINE(BOOL WINAPI Detour_ShowScrollBar (HWND hwnd, int wBar, BOOL fShow), ShowScrollBar);
- static BOOL WINAPI Tramp_EnableScrollBar(HWND hwnd, int wSBflags, UINT wArrows)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_EnableScrollBar(hwnd, wSBflags, wArrows);
- else
- return Detour_EnableScrollBar(hwnd, wSBflags, wArrows);
- }
- static BOOL WINAPI Tramp_GetScrollInfo(HWND hwnd, int fnBar, LPSCROLLINFO lpsi)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_GetScrollInfo(hwnd, fnBar, lpsi);
- else
- return Detour_GetScrollInfo(hwnd, fnBar, lpsi);
- }
- static int WINAPI Tramp_GetScrollPos(HWND hwnd, int nBar)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_GetScrollPos(hwnd, nBar);
- else
- return Detour_GetScrollPos(hwnd, nBar);
- }
- static BOOL WINAPI Tramp_GetScrollRange(HWND hwnd, int nBar, LPINT lpMinPos, LPINT lpMaxPos)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_GetScrollRange(hwnd, nBar, lpMinPos, lpMaxPos);
- else
- return Detour_GetScrollRange(hwnd, nBar, lpMinPos, lpMaxPos);
- }
- static int WINAPI Tramp_SetScrollInfo(HWND hwnd, int fnBar, LPSCROLLINFO lpsi, BOOL fRedraw)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_SetScrollInfo(hwnd, fnBar, lpsi, fRedraw);
- else
- return Detour_SetScrollInfo(hwnd, fnBar, lpsi, fRedraw);
- }
- static int WINAPI Tramp_SetScrollPos(HWND hwnd, int nBar, int nPos, BOOL fRedraw)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_SetScrollPos(hwnd, nBar, nPos, fRedraw);
- else
- return Detour_SetScrollPos(hwnd, nBar, nPos, fRedraw);
- }
- static int WINAPI Tramp_SetScrollRange(HWND hwnd, int nBar, int nMinPos, int nMaxPos, BOOL fRedraw)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_SetScrollRange(hwnd, nBar, nMinPos, nMaxPos, fRedraw);
- else
- return Detour_SetScrollRange(hwnd, nBar, nMinPos, nMaxPos, fRedraw);
- }
- static BOOL WINAPI Tramp_ShowScrollBar (HWND hwnd, int wBar, BOOL fShow)
- {
- if(CoolSB_IsCoolScrollEnabled(hwnd))
- return CoolSB_ShowScrollBar(hwnd, wBar, fShow);
- else
- return Detour_ShowScrollBar(hwnd, wBar, fShow);
- }
- BOOL WINAPI CoolSB_InitializeApp(void)
- {
- DWORD dwVersion = GetVersion();
- // Only available under Windows NT, 2000 and XP
- if(dwVersion < 0x80000000)
- {
- DetourFunctionWithTrampoline((PBYTE)Detour_EnableScrollBar, (PBYTE)Tramp_EnableScrollBar);
- DetourFunctionWithTrampoline((PBYTE)Detour_GetScrollInfo, (PBYTE)Tramp_GetScrollInfo);
- DetourFunctionWithTrampoline((PBYTE)Detour_GetScrollPos, (PBYTE)Tramp_GetScrollPos);
- DetourFunctionWithTrampoline((PBYTE)Detour_GetScrollRange, (PBYTE)Tramp_GetScrollRange);
- DetourFunctionWithTrampoline((PBYTE)Detour_SetScrollInfo, (PBYTE)Tramp_SetScrollInfo);
- DetourFunctionWithTrampoline((PBYTE)Detour_SetScrollPos, (PBYTE)Tramp_SetScrollPos);
- DetourFunctionWithTrampoline((PBYTE)Detour_SetScrollRange, (PBYTE)Tramp_SetScrollRange);
- DetourFunctionWithTrampoline((PBYTE)Detour_ShowScrollBar, (PBYTE)Tramp_ShowScrollBar);
- // don't actually use this feature within coolsb yet, but we might need it
- CoolSB_SetESBProc(Detour_EnableScrollBar);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- BOOL WINAPI CoolSB_UninitializeApp(void)
- {
- DWORD dwVersion = GetVersion();
- // Only available under Windows NT, 2000 and XP
- if(dwVersion < 0x80000000)
- {
- DetourRemove((PBYTE)Detour_EnableScrollBar, (PBYTE)Tramp_EnableScrollBar);
- DetourRemove((PBYTE)Detour_GetScrollInfo, (PBYTE)Tramp_GetScrollInfo);
- DetourRemove((PBYTE)Detour_GetScrollPos, (PBYTE)Tramp_GetScrollPos);
- DetourRemove((PBYTE)Detour_GetScrollRange, (PBYTE)Tramp_GetScrollRange);
- DetourRemove((PBYTE)Detour_SetScrollInfo, (PBYTE)Tramp_SetScrollInfo);
- DetourRemove((PBYTE)Detour_SetScrollPos, (PBYTE)Tramp_SetScrollPos);
- DetourRemove((PBYTE)Detour_SetScrollRange, (PBYTE)Tramp_SetScrollRange);
- DetourRemove((PBYTE)Detour_ShowScrollBar, (PBYTE)Tramp_ShowScrollBar);
- // don't actually use this feature within coolsb yet, but we might need it
- CoolSB_SetESBProc(EnableScrollBar);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }