home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / nastroje / d23456 / NSIS.EXE / Source / exehead / bgbg.c next >
C/C++ Source or Header  |  2001-05-19  |  4KB  |  96 lines

  1. #include <windows.h>
  2. #include "resource.h"
  3. #include "config.h"
  4.  
  5. #ifdef NSIS_SUPPORT_BGBG
  6.  
  7. static int m_color1, m_color2, m_textcolor;
  8.  
  9. static LRESULT CALLBACK BG_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  10. {
  11.   switch (uMsg)
  12.   {
  13.     case WM_PAINT:
  14.       {
  15.         static PAINTSTRUCT ps;
  16.         HFONT newFont, oldFont;
  17.         HDC hdc=BeginPaint(hwnd,&ps);
  18.         RECT r;
  19.         int y;
  20.         GetClientRect(hwnd,&r);
  21.     // this portion by Drew Davidson, drewdavidson@mindspring.com
  22.         // ABD: this method of drawing the gradient is *much* faster/more responsive, especially on 32 bpp displays.
  23.         // To test the speedup, switch to a full-screen app, and then back to the installer.  The old method
  24.         // sloooooowly draws the gradient when the window is revealed.  The new method pops up the gradient pretty 
  25.         // much instantly. This drawing method looks largely the same as the above, but we draw in strips 10 
  26.         // pixels high, instead of creating/destroying a pen for every single horizontal line.
  27.         
  28.         // JF: made slower, reduced to 4 pixels high, because I like how it looks better/
  29.         for (y = r.top; y < r.bottom; y += 4)
  30.         {
  31.           int rv,gv,bv;
  32.               RECT rect;
  33.               HBRUSH brush;
  34.           rv = GetRValue(m_color2) * y / r.bottom + GetRValue(m_color1) * (r.bottom - y) / r.bottom;
  35.           gv = GetGValue(m_color2) * y / r.bottom + GetGValue(m_color1) * (r.bottom - y) / r.bottom;
  36.           bv = GetBValue(m_color2) * y / r.bottom + GetBValue(m_color1) * (r.bottom - y) / r.bottom;
  37.               brush = CreateSolidBrush(RGB(rv,gv,bv));
  38.               SetRect(&rect, r.left, y, r.right, y+4);
  39.               // note that we don't need to do "SelectObject(hdc, brush)" 
  40.               // because FillRect lets us specify the brush as a parameter.
  41.               FillRect(hdc, &rect, brush);
  42.               DeleteObject(brush);
  43.         }
  44.         
  45.         if (m_textcolor != -1)
  46.         {
  47.           newFont = CreateFont(40,0,0,0,FW_BOLD,TRUE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Garamond");
  48.           if (newFont)
  49.           {
  50.             static char buf[256];
  51.             r.left+=16;
  52.             r.top+=8;
  53.             GetWindowText(hwnd,buf,sizeof(buf));
  54.             SetBkMode(hdc,TRANSPARENT);
  55.             SetTextColor(hdc,m_textcolor);
  56.             oldFont = SelectObject(hdc,newFont);
  57.             DrawText(hdc,buf,-1,&r,DT_TOP|DT_LEFT|DT_SINGLELINE);
  58.             SelectObject(hdc,oldFont);
  59.             DeleteObject(newFont);
  60.           }
  61.         }
  62.         EndPaint(hwnd,&ps);
  63.       }
  64.     return 0;
  65.   }
  66.   return DefWindowProc(hwnd,uMsg,wParam,lParam);
  67. }
  68.  
  69.  
  70. HWND bgWnd_Init(HINSTANCE hInstance, char *title, int color1, int color2, int color3)
  71. {
  72.   RECT vp;
  73.   char classname[4]="_Nb";
  74.   {
  75.     static WNDCLASS wc;
  76.       wc.style = CS_VREDRAW | CS_HREDRAW;
  77.       wc.lpfnWndProc = BG_WndProc;
  78.       wc.hInstance = hInstance;
  79.       wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON2));
  80.       wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  81.       wc.lpszClassName = classname;
  82.  
  83.     if (!RegisterClass(&wc)) return 0;
  84.   }
  85.   m_color1=color1;
  86.   m_color2=color2;
  87.   m_textcolor=color3;
  88.   
  89.   SystemParametersInfo(SPI_GETWORKAREA, 0, &vp, 0);
  90.  
  91.   return CreateWindow(classname,title,WS_VISIBLE|WS_OVERLAPPED|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MAXIMIZEBOX|WS_MINIMIZEBOX,
  92.     vp.left,vp.top,vp.right-vp.left,vp.bottom-vp.top,GetDesktopWindow(),NULL,hInstance,NULL);
  93. }
  94.  
  95.  
  96. #endif //NSIS_SUPPORT_BGBG