home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 December (Special) / DOSV2002_12.iso / utility / tcl230ja95.lzh / source.lzh / dll / newapi.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-08  |  4.6 KB  |  195 lines

  1. /*-------------------------------------------
  2.   newapi.c
  3.   GradientFill and Layerd Window
  4.   Kazubon 1999
  5. ---------------------------------------------*/
  6.  
  7. #include "tcdll.h"
  8.  
  9. #if _MSC_VER < 1200
  10.  
  11. typedef USHORT COLOR16;
  12.  
  13. typedef struct _TRIVERTEX
  14. {
  15.     LONG    x;
  16.     LONG    y;
  17.     COLOR16 Red;
  18.     COLOR16 Green;
  19.     COLOR16 Blue;
  20.     COLOR16 Alpha;
  21. }TRIVERTEX,*PTRIVERTEX,*LPTRIVERTEX;
  22.  
  23. typedef struct _GRADIENT_RECT
  24. {
  25.     ULONG UpperLeft;
  26.     ULONG LowerRight;
  27. }GRADIENT_RECT,*PGRADIENT_RECT,*LPGRADIENT_RECT;
  28.  
  29. typedef struct _BLENDFUNCTION
  30. {
  31.     BYTE   BlendOp;
  32.     BYTE   BlendFlags;
  33.     BYTE   SourceConstantAlpha;
  34.     BYTE   AlphaFormat;
  35. } BLENDFUNCTION,*PBLENDFUNCTION;
  36.  
  37. #define AC_SRC_OVER                 0x00
  38.  
  39. #define GRADIENT_FILL_RECT_H    0x00000000
  40. #define GRADIENT_FILL_RECT_V    0x00000001
  41. #define GRADIENT_FILL_TRIANGLE  0x00000002
  42. #define GRADIENT_FILL_OP_FLAG   0x000000ff
  43.  
  44. #endif
  45.  
  46. #define WS_EX_LAYERED 0x80000
  47. #define LWA_ALPHA     2
  48.  
  49. HMODULE hmodMSIMG32 = NULL;
  50. BOOL (WINAPI *pGradientFill)(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG) = NULL;
  51.  
  52. HMODULE hmodUSER32 = NULL;
  53. BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD) = NULL;
  54.  
  55. static BOOL bInitGradientFill = FALSE;
  56. static BOOL bInitLayeredWindow = FALSE;
  57.  
  58. static void RefreshRebar(HWND hwndBar);
  59.  
  60. void InitGradientFill(void)
  61. {
  62.     if(bInitGradientFill) return;
  63.     
  64.     hmodMSIMG32 = LoadLibrary("msimg32.dll");
  65.     if(hmodMSIMG32 != NULL)
  66.     {
  67.         (FARPROC)pGradientFill = GetProcAddress(hmodMSIMG32, "GradientFill");
  68.         if(pGradientFill == NULL)
  69.         {
  70.             FreeLibrary(hmodMSIMG32); hmodMSIMG32 = NULL;
  71.         }
  72.     }
  73.     bInitGradientFill = TRUE;
  74. }
  75.  
  76. void InitLayeredWindow(HWND hwndClock)
  77. {
  78.     if(bInitLayeredWindow) return;
  79.     
  80.     hmodUSER32 = LoadLibrary("user32.dll");
  81.     if(hmodUSER32 != NULL)
  82.     {
  83.         (FARPROC)pSetLayeredWindowAttributes = 
  84.             GetProcAddress(hmodUSER32, "SetLayeredWindowAttributes");
  85.         if(pSetLayeredWindowAttributes == NULL)
  86.         {
  87.             FreeLibrary(hmodUSER32); hmodUSER32 = NULL;
  88.         }
  89.     }
  90.     bInitLayeredWindow = TRUE;
  91. }
  92.  
  93. void EndNewAPI(HWND hwndClock)
  94. {
  95.     if(hmodMSIMG32 != NULL) FreeLibrary(hmodMSIMG32);
  96.     hmodMSIMG32 = NULL; pGradientFill = NULL;
  97.     
  98.     if(pSetLayeredWindowAttributes)
  99.     {
  100.         HWND hwnd;
  101.         LONG exstyle;
  102.         
  103.         hwnd = GetParent(GetParent(hwndClock));
  104.         exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
  105.         if(exstyle & WS_EX_LAYERED)
  106.         {
  107.             exstyle &= ~WS_EX_LAYERED;
  108.             SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
  109.             RefreshRebar(hwnd);
  110.         }
  111.     }
  112.     
  113.     if(hmodUSER32 != NULL) FreeLibrary(hmodUSER32);
  114.     hmodUSER32 = NULL; pSetLayeredWindowAttributes = NULL;
  115. }
  116.  
  117. void GradientFillClock(HDC hdc, RECT* prc, COLORREF col1, COLORREF col2)
  118. {
  119.     TRIVERTEX vert[2];
  120.     GRADIENT_RECT gRect;
  121.     
  122.     if(!pGradientFill) InitGradientFill();
  123.     if(!pGradientFill) return;
  124.     
  125.     vert[0].x      = prc->left;
  126.     vert[0].y      = prc->top;
  127.     vert[0].Red    = (COLOR16)GetRValue(col1) * 256;
  128.     vert[0].Green  = (COLOR16)GetGValue(col1) * 256;
  129.     vert[0].Blue   = (COLOR16)GetBValue(col1) * 256;
  130.     vert[0].Alpha  = 0x0000;
  131.     vert[1].x      = prc->right;
  132.     vert[1].y      = prc->bottom; 
  133.     vert[1].Red    = (COLOR16)GetRValue(col2) * 256;
  134.     vert[1].Green  = (COLOR16)GetGValue(col2) * 256;
  135.     vert[1].Blue   = (COLOR16)GetBValue(col2) * 256;
  136.     vert[1].Alpha  = 0x0000;
  137.     gRect.UpperLeft  = 0;
  138.     gRect.LowerRight = 1;
  139.     pGradientFill(hdc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_H);
  140. }
  141.  
  142. void SetLayeredTaskbar(HWND hwndClock)
  143. {
  144.     LONG exstyle;
  145.     HWND hwnd;
  146.     int alpha;
  147.     
  148.     alpha = GetMyRegLong(NULL, "AlphaTaskbar", 0);
  149.     alpha = 255 - (alpha * 255 / 100);
  150.     if(alpha < 8) alpha = 8; else if(alpha > 255) alpha = 255;
  151.     
  152.     if(!pSetLayeredWindowAttributes && alpha < 255)
  153.         InitLayeredWindow(hwndClock);
  154.     if(!pSetLayeredWindowAttributes) return;
  155.     
  156.     hwnd = GetParent(GetParent(hwndClock));
  157.     
  158.     exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
  159.     if(alpha < 255) exstyle |= WS_EX_LAYERED;
  160.     else exstyle &= ~WS_EX_LAYERED;
  161.     SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
  162.     RefreshRebar(hwnd);
  163.     
  164.     if(alpha < 255)
  165.         pSetLayeredWindowAttributes(hwnd, 0, (BYTE)alpha, LWA_ALPHA);
  166. }
  167.  
  168. /*--------------------------------------------------
  169.     redraw ReBarWindow32 forcely
  170. ----------------------------------------------------*/
  171. void RefreshRebar(HWND hwndBar)
  172. {
  173.     HWND hwnd;
  174.     char classname[80];
  175.     
  176.     hwnd = GetWindow(hwndBar, GW_CHILD);
  177.     while(hwnd)
  178.     {
  179.         GetClassName(hwnd, classname, 80);
  180.         if(lstrcmpi(classname, "ReBarWindow32") == 0)
  181.         {
  182.             InvalidateRect(hwnd, NULL, TRUE);
  183.             hwnd = GetWindow(hwnd, GW_CHILD);
  184.             while(hwnd)
  185.             {
  186.                 InvalidateRect(hwnd, NULL, TRUE);
  187.                 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
  188.             }
  189.             break;
  190.         }
  191.         hwnd = GetWindow(hwnd, GW_HWNDNEXT);
  192.     }
  193. }
  194.  
  195.