Announcement

Collapse
No announcement yet.

'Ausgrauen' von farbigen Objekten

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 'Ausgrauen' von farbigen Objekten

    Hallo,

    weiß vielleicht jemand wie man die Farben von Objekten 'ausgrauen' kann (ähnlich wie beim Beenden Dialog von Win98, aber nicht so grob). Genügt es, einen festen Wert zu den Farben zu addieren oder von den Farben zu subtrahieren oder muss man für jede Farbe eine entsprechende 'gräuliche' Farbe definieren?

    Vielen Dank für jeden Hinweis

    Martin

  • #2
    Einfach nur die Eigenschaft Enabled auf false setzen
    Günther

    Comment


    • #3
      Such mal nach "ShadeRect" in der win32sdk.hlp. Da findest du ein Beispiel.<br>Uli

      Comment


      • #4
        Hallo Günther,

        Enabled setzt eben leider nicht die Farbe eines Objects (zumindest nicht
        eines von TPanel oder TLabel abgeleiteten).

        Marti

        Comment


        • #5
          Hallo Ullrich,

          vielleicht ist meine win32sdk.hlp zu alt (C++ Builder 4) oder die Suchfunktion zu doof, aber ich kann kein ShadeRect finden.

          Marti

          Comment


          • #6
            Hallo Martin,<br>
            hier hast du:<pre>
            How to Shade Images to Look Like Windows 95 Active Icon

            PSS ID Number: Q128786

            Authored 10-Apr-1995 Last modified 23-Jun-1995

            The information in this article applies to:

            - Microsoft Win32 Software Development Kit (SDK) versions 3.5 and 4.0

            SUMMARY

            This article shows by example how to display an image or an icon in a
            shaded state, as Windows 95 does for the active icon.

            MORE INFORMATION

            Step-by-Step Procedure
            ----------------------

            To obtain the shaded look for your image or icon, follow these six steps:

            1. Create a compatible DC and bitmap.

            2. Create a monochrome pattern brush with every other pixel on.

            3. Fill the memory image with the pattern.

            4. BitBlt the source image over the pattern using SRCAND so that only the
            'on' destination pixels are transferred.

            5. Color the destination with the pattern, using the highlight color for

            the 'off' pixels and using black for the 'on' pixels.

            6. Copy the filtered original from the memory DC to the destination using
            SRCPAINT so that only the 'on' pixels are transferred.

            This results in the destination having the original image with every other
            pixel colored with the highlight color.

            Sample Code
            -----------

            The following function implements these six steps to shade a rectangular
            area on a device context:

            // ShadeRect
            // hDC : the DC on which the area is to be shaded

            // lpRect : the coordinates within which to shade
            BOOL ShadeRect( HDC hDC, LPRECT lpRect )
            {
            COLORREF crHighlightColor, crOldBkColor, crOldTextColor;
            HBRUSH hBrush, hOldBrush;
            HBITMAP hBitmap, hBrushBitmap, hOldMemBitmap;
            int OldBkMode, nWidth, nHeight;
            HDC hMemDC;
            RECT rcRect = { 0, 0, 0, 0};
            // The bitmap bits are for a monochrome "every-other-pixel"
            // bitmap (for a pattern brush)
            WORD Bits[8] = { 0x0055, 0x00aa, 0x0055, 0x00aa,

            0x0055, 0x00aa, 0x0055, 0x00aa };

            // The Width and Height of the target area
            nWidth = lpRect->right - lpRect->left + 1;
            nHeight = lpRect->bottom - lpRect->top + 1;

            // Need a pattern bitmap
            hBrushBitmap = CreateBitmap( 8, 8, 1, 1, &Bits );
            // Need to store the original image
            hBitmap = CreateCompatibleBitmap( hDC, nWidth, nHeight );
            // Need a memory DC to work in
            hMemDC = CreateCompatibleDC( hDC );
            // Create the pattern brush

            hBrush = CreatePatternBrush( hBrushBitmap );

            // Has anything failed so far? If so, abort!
            if( (hBrushBitmap==NULL) || (hBitmap==NULL) ||
            (hMemDC==NULL) || (hBrush==NULL) )
            {
            if( hBrushBitmap != NULL ) DeleteObject(hBrushBitmap);
            if( hBitmap != NULL ) DeleteObject( hBitmap );
            if( hMemDC != NULL ) DeleteDC( hMemDC );
            if( hBrush != NULL ) DeleteObject( hBrush );
            return FALSE;
            }

            // Select the bitmap into the memory DC

            hOldMemBitmap = SelectObject( hMemDC, hBitmap );

            // How wide/tall is the original?
            rcRect.right = nWidth;
            rcRect.bottom = nHeight;

            // Lay down the pattern in the memory DC
            FillRect( hMemDC, &rcRect, hBrush );

            // Fill in the non-color pixels with the original image
            BitBlt( hMemDC, 0, 0, nWidth, nHeight, hDC,
            lpRect->left, lpRect->top, SRCAND );

            // For the "Shutdown" look, use black or gray here instead
            crHighlightColor = GetSysColor( COLOR_HIGHLIGHT );

            // Set the color scheme
            crOldTextColor = SetTextColor( hDC, crHighlightColor );
            crOldBkColor = SetBkColor( hDC, RGB(0,0,0) );
            SetBkMode( hDC, OPAQUE );

            // Select the pattern brush
            hOldBrush = SelectObject( hDC, hBrush );
            // Fill in the color pixels, and set the others to black
            FillRect( hDC, lpRect, hBrush );
            // Fill in the black ones with the original image
            BitBlt( hDC, lpRect->left, lpRect->top, nWidth, nHeight,
            hMemDC, 0, 0, SRCPAINT );

            // Restore target DC se

            Comment


            • #7
              <b>Teil 2</b>
              <pre>
              // Restore target DC settings
              SetBkMode( hDC, OldBkMode );
              SetBkColor( hDC, crOldBkColor );
              SetTextColor( hDC, crOldTextColor );

              // Clean up
              SelectObject( hMemDC, hOldMemBitmap );
              DeleteObject( hBitmap );
              DeleteDC( hMemDC );
              DeleteObject( hBrushBitmap );
              SelectObject( hDC, hOldBrush );
              DeleteObject( hBrush );

              return TRUE;
              }

              Additional reference words: 3.50 4.00 hatch darken shadow
              KBCategory: kbgraphic kbcode
              KBSubcategory: GdiMisc
              </pre&gt

              Comment


              • #8
                Hallo Ullrich,

                vielen Dank für das Beispiel. Ich habe auch noch ein paar Möglichkeiten
                entdeckt (das Beispiel geht von einem Formular mit einem Panel und vier
                Knöpfen aus) :

                <PRE>
                //---------------------------------------------------------------------------

                void __fastcall TForm1::SpeedDefaultClick(TObject *Sender)
                {

                Panel1->Color = clRed;
                Panel1->Font->Color = (TColor)(clWhite - Panel1->Color);
                Farbe.Gesamt = Panel1->Color;
                Panel1->Caption = "Rot: " + IntToStr(Farbe.Rot) +
                ", Gruen: " + IntToStr(Farbe.Gruen) +
                ", Blau: " + IntToStr(Farbe.Blau);
                }
                //---------------------------------------------------------------------------

                void __fastcall TForm1::SpeedGreyClick(TObject *Sender)
                {

                Farbe.Gesamt = Panel1->Color;

                D = (Farbe.Rot + Farbe.Gruen + Farbe.Blau)/3;
                Farbe.Rot = D;
                Farbe.Gruen = D;
                Farbe.Blau = D;

                Panel1->Color = Farbe.Gesamt;
                Panel1->Caption = "Rot: " + IntToStr(Farbe.Rot) +
                ", Gruen: " + IntToStr(Farbe.Gruen) +
                ", Blau: " + IntToStr(Farbe.Blau);

                }
                //---------------------------------------------------------------------------

                void __fastcall TForm1::SpeedPaleClick(TObject *Sender)
                {

                Farbe.Gesamt = Panel1->Color;

                Zuwachs = (255 - Farbe.Rot)/3 &gt; 0 ?
                (255 - Farbe.Rot)/3 : 255 - Farbe.Rot;
                Farbe.Rot = Farbe.Rot + Zuwachs &lt; 255 ?
                Farbe.Rot + Zuwachs : 255;
                Zuwachs = (255 - Farbe.Gruen)/3 &gt; 0 ?
                (255 - Farbe.Gruen)/3 : 255 - Farbe.Gruen;
                Farbe.Gruen = Farbe.Gruen + Zuwachs &lt; 255 ?
                Farbe.Gruen + Zuwachs : 255;
                Zuwachs = (255 - Farbe.Blau)/3 &gt; 0 ?
                (255 - Farbe.Blau)/3 : 255 - Farbe.Blau;
                Farbe.Blau = Farbe.Blau + Zuwachs &lt; 255 ?
                Farbe.Blau + Zuwachs : 255;

                Panel1->Color = Farbe.Gesamt;
                Panel1->Caption = "Rot: " + IntToStr(Farbe.Rot) +
                ", Gruen: " + IntToStr(Farbe.Gruen) +
                ", Blau: " + IntToStr(Farbe.Blau);

                }
                //---------------------------------------------------------------------------

                void __fastcall TForm1::SpeedFadeClick(TObject *Sender)
                {

                k = 0.15; //k = 0 keine Aenderung, k = 1 total grau

                Farbe.Gesamt = Panel1->Color;

                D = (Farbe.Rot + Farbe.Gruen + Farbe.Blau)/3;
                Farbe.Rot = D * k + Farbe.Rot * (1 - k);
                Farbe.Gruen = D * k + Farbe.Gruen * (1 - k);
                Farbe.Blau = D * k + Farbe.Blau * (1 - k);

                Panel1->Color = Farbe.Gesamt;
                Panel1->Caption = "Rot: " + IntToStr(Farbe.Rot) +
                ", Gruen: " + IntToStr(Farbe.Gruen) +
                ", Blau: " + IntToStr(Farbe.Blau);

                }
                //---------------------------------------------------------------------------

                und im Header :

                class TForm1 : public TForm
                {
                __published: // IDE-managed Components
                TPanel *Panel1;
                TSpeedButton *SpeedDefault;
                TSpeedButton *SpeedGrey;
                TSpeedButton *SpeedPale;
                TSpeedButton *SpeedFade;
                void __fastcall SpeedDefaultClick(TObject *Sender);
                void __fastcall SpeedGreyClick(TObject *Sender);
                void __fastcall SpeedPaleClick(TObject *Sender);
                void __fastcall SpeedFadeClick(TObject *Sender);

                private: // User declarations

                union TFarbe
                {
                int Gesamt;
                struct
                {
                unsigned char Rot;
                unsigned char Gruen;
                unsigned char Blau;
                unsigned char HochByte;
                };
                };

                TFarbe Farbe;

                unsigned char D;

                double k;

                int Zuwachs;

                public: // User declarations

                __fastcall TForm1(TComponent* Owner);

                };

                </PRE>

                Marti

                Comment

                Working...
                X