home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------
- newapi.c
- GradientFill and Layerd Window
- Kazubon 1999
- ---------------------------------------------*/
-
- #include "tcdll.h"
-
- #if _MSC_VER < 1200
-
- typedef USHORT COLOR16;
-
- typedef struct _TRIVERTEX
- {
- LONG x;
- LONG y;
- COLOR16 Red;
- COLOR16 Green;
- COLOR16 Blue;
- COLOR16 Alpha;
- }TRIVERTEX,*PTRIVERTEX,*LPTRIVERTEX;
-
- typedef struct _GRADIENT_RECT
- {
- ULONG UpperLeft;
- ULONG LowerRight;
- }GRADIENT_RECT,*PGRADIENT_RECT,*LPGRADIENT_RECT;
-
- typedef struct _BLENDFUNCTION
- {
- BYTE BlendOp;
- BYTE BlendFlags;
- BYTE SourceConstantAlpha;
- BYTE AlphaFormat;
- } BLENDFUNCTION,*PBLENDFUNCTION;
-
- #define AC_SRC_OVER 0x00
-
- #define GRADIENT_FILL_RECT_H 0x00000000
- #define GRADIENT_FILL_RECT_V 0x00000001
- #define GRADIENT_FILL_TRIANGLE 0x00000002
- #define GRADIENT_FILL_OP_FLAG 0x000000ff
-
- #endif
-
- #define WS_EX_LAYERED 0x80000
- #define LWA_ALPHA 2
-
- HMODULE hmodMSIMG32 = NULL;
- BOOL (WINAPI *pGradientFill)(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG) = NULL;
-
- HMODULE hmodUSER32 = NULL;
- BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD) = NULL;
-
- static BOOL bInitGradientFill = FALSE;
- static BOOL bInitLayeredWindow = FALSE;
-
- static void RefreshRebar(HWND hwndBar);
-
- void InitGradientFill(void)
- {
- if(bInitGradientFill) return;
-
- hmodMSIMG32 = LoadLibrary("msimg32.dll");
- if(hmodMSIMG32 != NULL)
- {
- (FARPROC)pGradientFill = GetProcAddress(hmodMSIMG32, "GradientFill");
- if(pGradientFill == NULL)
- {
- FreeLibrary(hmodMSIMG32); hmodMSIMG32 = NULL;
- }
- }
- bInitGradientFill = TRUE;
- }
-
- void InitLayeredWindow(HWND hwndClock)
- {
- if(bInitLayeredWindow) return;
-
- hmodUSER32 = LoadLibrary("user32.dll");
- if(hmodUSER32 != NULL)
- {
- (FARPROC)pSetLayeredWindowAttributes =
- GetProcAddress(hmodUSER32, "SetLayeredWindowAttributes");
- if(pSetLayeredWindowAttributes == NULL)
- {
- FreeLibrary(hmodUSER32); hmodUSER32 = NULL;
- }
- }
- bInitLayeredWindow = TRUE;
- }
-
- void EndNewAPI(HWND hwndClock)
- {
- if(hmodMSIMG32 != NULL) FreeLibrary(hmodMSIMG32);
- hmodMSIMG32 = NULL; pGradientFill = NULL;
-
- if(pSetLayeredWindowAttributes)
- {
- HWND hwnd;
- LONG exstyle;
-
- hwnd = GetParent(GetParent(hwndClock));
- exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
- if(exstyle & WS_EX_LAYERED)
- {
- exstyle &= ~WS_EX_LAYERED;
- SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
- RefreshRebar(hwnd);
- }
- }
-
- if(hmodUSER32 != NULL) FreeLibrary(hmodUSER32);
- hmodUSER32 = NULL; pSetLayeredWindowAttributes = NULL;
- }
-
- void GradientFillClock(HDC hdc, RECT* prc, COLORREF col1, COLORREF col2)
- {
- TRIVERTEX vert[2];
- GRADIENT_RECT gRect;
-
- if(!pGradientFill) InitGradientFill();
- if(!pGradientFill) return;
-
- vert[0].x = prc->left;
- vert[0].y = prc->top;
- vert[0].Red = (COLOR16)GetRValue(col1) * 256;
- vert[0].Green = (COLOR16)GetGValue(col1) * 256;
- vert[0].Blue = (COLOR16)GetBValue(col1) * 256;
- vert[0].Alpha = 0x0000;
- vert[1].x = prc->right;
- vert[1].y = prc->bottom;
- vert[1].Red = (COLOR16)GetRValue(col2) * 256;
- vert[1].Green = (COLOR16)GetGValue(col2) * 256;
- vert[1].Blue = (COLOR16)GetBValue(col2) * 256;
- vert[1].Alpha = 0x0000;
- gRect.UpperLeft = 0;
- gRect.LowerRight = 1;
- pGradientFill(hdc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_H);
- }
-
- void SetLayeredTaskbar(HWND hwndClock)
- {
- LONG exstyle;
- HWND hwnd;
- int alpha;
-
- alpha = GetMyRegLong(NULL, "AlphaTaskbar", 0);
- alpha = 255 - (alpha * 255 / 100);
- if(alpha < 8) alpha = 8; else if(alpha > 255) alpha = 255;
-
- if(!pSetLayeredWindowAttributes && alpha < 255)
- InitLayeredWindow(hwndClock);
- if(!pSetLayeredWindowAttributes) return;
-
- hwnd = GetParent(GetParent(hwndClock));
-
- exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
- if(alpha < 255) exstyle |= WS_EX_LAYERED;
- else exstyle &= ~WS_EX_LAYERED;
- SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
- RefreshRebar(hwnd);
-
- if(alpha < 255)
- pSetLayeredWindowAttributes(hwnd, 0, (BYTE)alpha, LWA_ALPHA);
- }
-
- /*--------------------------------------------------
- redraw ReBarWindow32 forcely
- ----------------------------------------------------*/
- void RefreshRebar(HWND hwndBar)
- {
- HWND hwnd;
- char classname[80];
-
- hwnd = GetWindow(hwndBar, GW_CHILD);
- while(hwnd)
- {
- GetClassName(hwnd, classname, 80);
- if(lstrcmpi(classname, "ReBarWindow32") == 0)
- {
- InvalidateRect(hwnd, NULL, TRUE);
- hwnd = GetWindow(hwnd, GW_CHILD);
- while(hwnd)
- {
- InvalidateRect(hwnd, NULL, TRUE);
- hwnd = GetWindow(hwnd, GW_HWNDNEXT);
- }
- break;
- }
- hwnd = GetWindow(hwnd, GW_HWNDNEXT);
- }
- }
-
-