⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colordlg.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:
{
 HDC hDC;
 long temp;
 int w = LOWORD(GetDialogBaseUnits());
 POINT points[3];
 int height;
 int oben;
 RECT rect;
 HBRUSH hbr;
 HWND hwnd = GetDlgItem(hDlg, 0x2be);
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );

 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6)))   /* if full size */
 {
   GetClientRect(hwnd, &rect);
   height = rect.bottom;
   hDC = GetDC(hDlg);
   points[0].y = rect.top;
   points[0].x = rect.right;     /*  |  /|  */
   ClientToScreen(hwnd, points); /*  | / |  */
   ScreenToClient(hDlg, points); /*  |<  |  */
   oben = points[0].y;           /*  | \ |  */
                                 /*  |  \|  */
   temp = (long)height * (long)y;
   points[0].y = oben + height - temp / (long)MAXVERT;
   points[1].y = points[0].y + w;
   points[2].y = points[0].y - w;
   points[2].x = points[1].x = points[0].x + w;

   hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
   if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE);
   FillRect(hDC, &lpp->old3angle, hbr);
   lpp->old3angle.left  = points[0].x;
   lpp->old3angle.right = points[1].x + 1;
   lpp->old3angle.top   = points[2].y - 1;
   lpp->old3angle.bottom= points[1].y + 1;
   Polygon(hDC, points, 3);
   ReleaseDC(hDlg, hDC);
 }
}


/***********************************************************************
 *                    CC_PaintCross                           [internal]
 */
void CC_PaintCross( HWND hDlg, int x, int y)
{
 HDC hDC;
 int w = GetDialogBaseUnits();
 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
 RECT rect;
 POINT point, p;
 HPEN hPen;

 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) ))   /* if full size */
 {
   GetClientRect(hwnd, &rect);
   hDC = GetDC(hwnd);
   SelectClipRgn( hDC, CreateRectRgnIndirect(&rect));
   hPen = CreatePen(PS_SOLID, 2, 0xffffff); /* -white- color */
   hPen = SelectObject(hDC, hPen);
   point.x = ((long)rect.right * (long)x) / (long)MAXHORI;
   point.y = rect.bottom - ((long)rect.bottom * (long)y) / (long)MAXVERT;
   if ( lpp->oldcross.left != lpp->oldcross.right )
     BitBlt(hDC, lpp->oldcross.left, lpp->oldcross.top,
              lpp->oldcross.right - lpp->oldcross.left,
              lpp->oldcross.bottom - lpp->oldcross.top,
              lpp->hdcMem, lpp->oldcross.left, lpp->oldcross.top, SRCCOPY);
   lpp->oldcross.left   = point.x - w - 1;
   lpp->oldcross.right  = point.x + w + 1;
   lpp->oldcross.top    = point.y - w - 1;
   lpp->oldcross.bottom = point.y + w + 1;

   MoveToEx(hDC, point.x - w, point.y, &p);
   LineTo(hDC, point.x + w, point.y);
   MoveToEx(hDC, point.x, point.y - w, &p);
   LineTo(hDC, point.x, point.y + w);
   DeleteObject( SelectObject(hDC, hPen)) ;
   ReleaseDC(hwnd, hDC);
 }
}


#define XSTEPS 48
#define YSTEPS 24


/***********************************************************************
 *                    CC_PrepareColorGraph                    [internal]
 */
static void CC_PrepareColorGraph( HWND hDlg )
{
 int sdif, hdif, xdif, ydif, r, g, b, hue, sat;
 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
 HBRUSH hbrush;
 HDC hdc ;
 RECT rect, client;
 HCURSOR hcursor = SetCursor( LoadCursorW(0, (LPCWSTR)IDC_WAIT) );

 GetClientRect(hwnd, &client);
 hdc = GetDC(hwnd);
 lpp->hdcMem = CreateCompatibleDC(hdc);
 lpp->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
 SelectObject(lpp->hdcMem, lpp->hbmMem);

 xdif = client.right / XSTEPS;
 ydif = client.bottom / YSTEPS+1;
 hdif = 239 / XSTEPS;
 sdif = 240 / YSTEPS;
 for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
 {
  rect.right = rect.left + xdif;
  rect.bottom = client.bottom;
  for(sat = 0; sat < 240 + sdif; sat += sdif)
  {
   rect.top = rect.bottom - ydif;
   r = CC_HSLtoRGB('R', hue, sat, 120);
   g = CC_HSLtoRGB('G', hue, sat, 120);
   b = CC_HSLtoRGB('B', hue, sat, 120);
   hbrush = CreateSolidBrush( RGB(r, g, b));
   FillRect(lpp->hdcMem, &rect, hbrush);
   DeleteObject(hbrush);
   rect.bottom = rect.top;
  }
  rect.left = rect.right;
 }
 ReleaseDC(hwnd, hdc);
 SetCursor(hcursor);
}

/***********************************************************************
 *                          CC_PaintColorGraph                [internal]
 */
static void CC_PaintColorGraph( HWND hDlg )
{
 HWND hwnd = GetDlgItem( hDlg, 0x2c6 );
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
 HDC  hDC;
 RECT rect;
 if (IsWindowVisible(hwnd))   /* if full size */
 {
  if (!lpp->hdcMem)
   CC_PrepareColorGraph(hDlg);   /* should not be necessary */

  hDC = GetDC(hwnd);
  GetClientRect(hwnd, &rect);
  if (lpp->hdcMem)
      BitBlt(hDC, 0, 0, rect.right, rect.bottom, lpp->hdcMem, 0, 0, SRCCOPY);
  else
      WARN("choose color: hdcMem is not defined\n");
  ReleaseDC(hwnd, hDC);
 }
}

/***********************************************************************
 *                           CC_PaintLumBar                   [internal]
 */
static void CC_PaintLumBar( HWND hDlg, int hue, int sat )
{
 HWND hwnd = GetDlgItem(hDlg, 0x2be);
 RECT rect, client;
 int lum, ldif, ydif, r, g, b;
 HBRUSH hbrush;
 HDC hDC;

 if (IsWindowVisible(hwnd))
 {
  hDC = GetDC(hwnd);
  GetClientRect(hwnd, &client);
  rect = client;

  ldif = 240 / YSTEPS;
  ydif = client.bottom / YSTEPS+1;
  for (lum = 0; lum < 240 + ldif; lum += ldif)
  {
   rect.top = max(0, rect.bottom - ydif);
   r = CC_HSLtoRGB('R', hue, sat, lum);
   g = CC_HSLtoRGB('G', hue, sat, lum);
   b = CC_HSLtoRGB('B', hue, sat, lum);
   hbrush = CreateSolidBrush( RGB(r, g, b) );
   FillRect(hDC, &rect, hbrush);
   DeleteObject(hbrush);
   rect.bottom = rect.top;
  }
  GetClientRect(hwnd, &rect);
  FrameRect(hDC, &rect, GetStockObject(BLACK_BRUSH) );
  ReleaseDC(hwnd, hDC);
 }
}

/***********************************************************************
 *                             CC_EditSetRGB                  [internal]
 */
void CC_EditSetRGB( HWND hDlg, COLORREF cr )
{
 char buffer[10];
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
 int r = GetRValue(cr);
 int g = GetGValue(cr);
 int b = GetBValue(cr);
 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) ))   /* if full size */
 {
   lpp->updating = TRUE;
   sprintf(buffer, "%d", r);
   SetWindowTextA( GetDlgItem(hDlg, 0x2c2), buffer);
   sprintf(buffer, "%d", g);
   SetWindowTextA( GetDlgItem(hDlg, 0x2c3), buffer);
   sprintf( buffer, "%d", b );
   SetWindowTextA( GetDlgItem(hDlg, 0x2c4),buffer);
   lpp->updating = FALSE;
 }
}

/***********************************************************************
 *                             CC_EditSetHSL                  [internal]
 */
void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
{
 char buffer[10];
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );

 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) ))   /* if full size */
 {
   lpp->updating = TRUE;
   sprintf(buffer, "%d", h);
   SetWindowTextA( GetDlgItem(hDlg, 0x2bf), buffer);
   sprintf(buffer, "%d", s);
   SetWindowTextA( GetDlgItem(hDlg, 0x2c0), buffer);
   sprintf(buffer, "%d", l);
   SetWindowTextA( GetDlgItem(hDlg, 0x2c1), buffer);
   lpp->updating = FALSE;
 }
 CC_PaintLumBar(hDlg, h, s);
}

/***********************************************************************
 *                       CC_SwitchToFullSize                  [internal]
 */
void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPCRECT lprect )
{
 int i;
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );

 EnableWindow( GetDlgItem(hDlg, 0x2cf), FALSE);
 CC_PrepareColorGraph(hDlg);
 for (i = 0x2bf; i < 0x2c5; i++)
   ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
 for (i = 0x2d3; i < 0x2d9; i++)
   ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_SHOW);
 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_SHOW);
 ShowWindow( GetDlgItem(hDlg, 1090), SW_SHOW);

 if (lprect)
  SetWindowPos(hDlg, 0, 0, 0, lprect->right-lprect->left,
   lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);

 ShowWindow( GetDlgItem(hDlg, 0x2be), SW_SHOW);
 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_SHOW);

 CC_EditSetRGB(hDlg, result);
 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
 ShowWindow( GetDlgItem( hDlg, 0x2c6), SW_SHOW);
 UpdateWindow( GetDlgItem(hDlg, 0x2c6) );
}

/***********************************************************************
 *                           CC_PaintPredefColorArray         [internal]
 *                Paints the default standard 48 colors
 */
static void CC_PaintPredefColorArray( HWND hDlg, int rows, int cols)
{
 HWND hwnd = GetDlgItem(hDlg, 0x2d0);
 RECT rect;
 HDC  hdc;
 HBRUSH hBrush;
 int dx, dy, i, j, k;
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );

 GetClientRect(hwnd, &rect);
 dx = rect.right / cols;
 dy = rect.bottom / rows;
 k = rect.left;

 hdc = GetDC(hwnd);
 GetClientRect(hwnd, &rect);
 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
 FillRect(hdc, &rect, hBrush);
 for ( j = 0; j < rows; j++ )
 {
  for ( i = 0; i < cols; i++ )
  {
   hBrush = CreateSolidBrush(predefcolors[j][i]);
   if (hBrush)
   {
    hBrush = SelectObject(hdc, hBrush);
    Rectangle(hdc, rect.left, rect.top,
                rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
    rect.left = rect.left + dx;
    DeleteObject(SelectObject(hdc, hBrush)) ;
   }
  }
  rect.top = rect.top + dy;
  rect.left = k;
 }
 ReleaseDC(hwnd, hdc);
 if (lpp->hwndFocus == hwnd)
   CC_DrawCurrentFocusRect(lpp);
}
/***********************************************************************
 *                             CC_PaintUserColorArray         [internal]
 *               Paint the 16 user-selected colors
 */
void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, const COLORREF *lpcr )
{
 HWND hwnd = GetDlgItem(hDlg, 0x2d1);
 RECT rect;
 HDC  hdc;
 HBRUSH hBrush;
 int dx, dy, i, j, k;
 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );

 GetClientRect(hwnd, &rect);

 dx = rect.right / cols;
 dy = rect.bottom / rows;
 k = rect.left;

 hdc = GetDC(hwnd);
 if (hdc)
 {
  hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
  if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
  FillRect( hdc, &rect, hBrush );
  for (j = 0; j < rows; j++)
  {
   for (i = 0; i < cols; i++)
   {
    hBrush = CreateSolidBrush(lpcr[i+j*cols]);
    if (hBrush)
    {
     hBrush = SelectObject(hdc, hBrush) ;
     Rectangle(hdc, rect.left, rect.top,
                  rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
     rect.left = rect.left + dx;
     DeleteObject( SelectObject(hdc, hBrush) ) ;
    }
   }
   rect.top = rect.top + dy;
   rect.left = k;
  }
  ReleaseDC(hwnd, hdc);
 }
 if (lpp->hwndFocus == hwnd)
   CC_DrawCurrentFocusRect(lpp);
}



/***********************************************************************
 *                             CC_HookCallChk                 [internal]
 */
BOOL CC_HookCallChk( const CHOOSECOLORW *lpcc )
{
 if (lpcc)
  if(lpcc->Flags & CC_ENABLEHOOK)
   if (lpcc->lpfnHook)
    return TRUE;
 return FALSE;
}

/***********************************************************************
 *                              CC_WMInitDialog                  [internal]
 */
static LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
{
   int i, res;
   int r, g, b;
   HWND hwnd;
   RECT rect;
   POINT point;
   LPCCPRIV lpp;

   TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
   lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );

   lpp->lpcc = (LPCHOOSECOLORW) lParam;
   if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLORW) )
   {
       HeapFree(GetProcessHeap(), 0, lpp);
       EndDialog (hDlg, 0) ;
       return FALSE;
   }

   SetPropW( hDlg, szColourDialogProp, lpp );

   if (!(lpp->lpcc->Flags & CC_SHOWHELP))
      ShowWindow( GetDlgItem(hDlg,0x40e), SW_HIDE);
   lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);

#if 0
   cpos = MAKELONG(5,7); /* init */
   if (lpp->lpcc->Flags & CC_RGBINIT)
   {
     for (i = 0; i < 6; i++)
       for (j = 0; j < 8; j++)
        if (predefcolors[i][j] == lpp->lpcc->rgbResult)
        {
          cpos = MAKELONG(i,j);
          goto found;
        }
   }
   found:
   /* FIXME: Draw_a_focus_rect & set_init_values */
#endif

   GetWindowRect(hDlg, &lpp->fullsize);
   if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
   {
      hwnd = GetDlgItem(hDlg, 0x2cf);
      EnableWindow(hwnd, FALSE);
   }
   if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
   {
      rect = lpp->fullsize;
      res = rect.bottom - rect.top;
      hwnd = GetDlgItem(hDlg, 0x2c6); /* cut at left border */
      point.x = point.y = 0;
      ClientToScreen(hwnd, &point);
      ScreenToClient(hDlg,&point);
      GetClientRect(hDlg, &rect);
      point.x += GetSystemMetrics(SM_CXDLGFRAME);
      SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);

      for (i = 0x2bf; i < 0x2c5; i++)
         ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
      for (i = 0x2d3; i < 0x2d9; i++)
         ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
      ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_HIDE);
      ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_HIDE);
      ShowWindow( GetDlgItem(hDlg, 0x2c6), SW_HIDE);
      ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_HIDE);
      ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
   }
   else
      CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, NULL);
   res = TRUE;
   for (i = 0x2bf; i < 0x2c5; i++)
     SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0);  /* max 3 digits:  xyz  */
   if (CC_HookCallChk(lpp->lpcc))
   {
          res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -