Transparent form

Transparent form

Post by Evandro L F Dugnan » Sat, 15 Apr 2000 04:00:00



How can I create a transparent form?
Where can I find examples of transparent forms? (how to create, manipulate,
etc...)

Thanks.

--

Evandro L F Dugnani

ComVC 333
ICQ 68457416

 
 
 

Transparent form

Post by Wilson Fis » Sun, 16 Apr 2000 04:00:00


By transparent forms you mean 'forms wit da holes'?

Here

Add this to your form class

bool __fastcall TForm1::GetRegionData(HRGN &Region,Graphics::TBitmap
*Bitmap,
                                      COLORREF Trans)
{
   DWORD RectCount=0;
   BYTE  *Row;
   RECT  *RData=NULL;
   LONG  LowX, LowY;
   Graphics::TBitmap *OurBM=new Graphics::TBitmap;
   // Check that we had enough memory to create a new Bitmap object.
   if(!OurBM)
      return false;
   // Copy the Bitmap to our new structure and set it's pixelformat to 24bit
   // this is the easiest of formats to use at low level, R,G,B
(BYTE,BYTE,BYTE)
   OurBM->Assign(Bitmap);
   OurBM->PixelFormat=pf24bit;
   LowX=OurBM->Width; LowY=OurBM->Height;
   // Go through the Rows of the Bitmap and make a collection of RECT
structures
   // which will hold the start and end points of none transparent pixels we
can
   // then empty these into a region.
   for(int Y=0;Y<OurBM->Height;Y++)
   {
      bool InRect=false;
      int  StartRect;
      // Retrieve the Current Scan line of the Bitmap row pointed to by Y,
this
      // as explained earlier is split into RGB compnents lateron.
      Row=(BYTE*)OurBM->ScanLine[Y];
      // Cycle through this row and isolate patches of none transparent
blocks
      // and add then to our Rect Structure.
      for(int X=0;X<OurBM->Width;X++)
      {
         // Get the RGB components
         BYTE Red=Row[X*3+0],Green=Row[X*3+1],Blue=Row[X*3+2];
         // Check if we're entering a non-transparent part of the image.
         if(RGB(Red,Green,Blue)!=Trans && !InRect)
         {
            // Mark the start of this non-transparent block.
            StartRect=X;
            InRect=true;
         }
         // Check if we're ending a non-transparent block or we're at the
end
         // of a Row, if so then add a Rectantangle describing the
         // non-transparent blocks dimensions to our structure.
         if((RGB(Red,Green,Blue)==Trans && InRect) ||
            (X==OurBM->Width-1 && InRect))
         {
            // Mark the Ending Block this can Either be because of the end
of
            // row or end of NT block, each case requires a different value.
            int FinX=X;
            if(X==OurBM->Width-1 && RGB(Red,Green,Blue)!=Trans)
               FinX=OurBM->Width;
            // Add this new Area to our RECT structure, first copy the
existing
            // one then add our new one to it.
            RECT *TempRect=new RECT[++RectCount];
            if(RData)
            {
               memcpy(TempRect,RData,sizeof(RECT)*RectCount);
               delete RData;
            }
            // Add the New Data.
            TempRect[RectCount-1].left=StartRect;
            TempRect[RectCount-1].top=Y;
            TempRect[RectCount-1].right=FinX;
            TempRect[RectCount-1].bottom=Y+1;
            if(StartRect<LowX) LowX=StartRect;
            if(Y<LowY)         LowY=Y;
            // Copy it back to the main structure.
            RData=TempRect;
            // Set InRect to false, well because we're not.
            InRect=false;
         }
      }
   }
   // Destroy the Bitmap.
   delete OurBM;
   // Make sure we have the data we need to create a region, if there was no
   // valid region in the bitmap then exit.
   if(!RData)
      return false;
   // Now we should have all the data we need to create a region so lets
attempt
   // to make one in the pointer we've been given.  We need to make a dummy
   // Region in the return region as the CombineRgn Requires it.
   Region=CreateRectRgn(0,0,0,0);
   for (DWORD I=0;I<=RectCount-1;I++)
   {
      // Create a Region from the new data.
      HRGN TempRegion=CreateRectRgnIndirect(&RData[I]);
      // Add it to our Current Data.
      CombineRgn(Region,TempRegion,Region,RGN_OR);
      // Destroy the Temporary Region.
      DeleteObject(TempRegion);
   }
   // Delete the Rectangle Data.
   if(RData)
      delete RData;
   return true;

Quote:}

 Put this in your form create!

   Graphics::TBitmap *MyBitty=new Graphics::TBitmap;
   MyBitty->LoadFromFile("C:\\Test.BMP");
   GetRegionData(MyRegion,MyBitty,RGB(0,0,0));  // Black is transparent
255,255,255 for white
   SetWindowRgn(Handle,MyRegion,true);

AND AFTER THE LINES IN YOUR CODE THAT LOOK LIKE THIS
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

 PUT THIS
HRGN MyRegion=NULL;
PS2 has Bump mapping Dreamcast has a tammagacy memory pad!  Play Sonic2 on
the megadrive or Sol-Feace on the Sega-CD feel good!

 
 
 

Transparent form

Post by Wilson Fis » Sun, 16 Apr 2000 04:00:00


   Change this line
   memcpy(TempRect,RData,sizeof(RECT)*RectCount);
  to this one.
   memcpy(TempRect,RData,sizeof(RECT)*(RectCount-1));
 
 
 

Transparent form

Post by Evandro L F Dugnan » Tue, 18 Apr 2000 04:00:00


Hi Wilson,

    The solution its OK to show static image, and works very well. Thanks.
But what I really need is how to show every C++ Builder component, including
TForm, with a transparent background.
    Is it possible?

--

Evandro L F Dugnani

ComVC 333
ICQ 68457416


Quote:>    Change this line
>    memcpy(TempRect,RData,sizeof(RECT)*RectCount);
>   to this one.
>    memcpy(TempRect,RData,sizeof(RECT)*(RectCount-1));

 
 
 

1. Transparent Form (but objects show in form)

Hi,

I think there is a window message for it -
I dont remember where I found this code, but I hope it can help...

{
Suppose you have one form named Form1, and a button1 on Form1,
On Form1's OnCreate event write these code:

procedure TForm1.FormCreate(Sender: TObject);
begin

setwindowlong(form1.handle,gwl_exstyle,(getwindowlong(form1.handle,gwl_exsty
le)
                or ws_ex_transparent));
end;

{
Only the button can be seen, but form cannot.


2. Sorta OpenGL Related! :)

3. FREE CLIP-ART

4. Transparent FORM with Transparent Backround TEXT with Animation..?

5. Decrease colours limited ?

6. Transparent Form

7. best budget DV Cam for the job

8. making transparent forms with bitmaps

9. VB - API Guru Challenge - Transparent Form in 9x

10. Semi-transparent form