From: "Shannon Broskie" Newsgroups: borland.public.delphi.graphics References: <3ac8ec1a_2@dnews> Subject: Re: Maskblt - proper way Date: Thu, 5 Apr 2001 13:21:03 -0400 Lines: 97 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 216.174.24.2 Message-ID: <3acca8b8_1@dnews> X-Trace: dnews 986491064 216.174.24.2 (5 Apr 2001 10:17:44 -0700) Path: dnews Xref: dnews borland.public.delphi.graphics:37035 This is what I wound up doing... Any suggestions? procedure DrawTitleBarImage (const Form : TForm; const Bitmap: TBitmap); var Mask : TBitmap; FormDC : HDC; CyCaption, CxSize, CxDlgFrame, CyDlgFrame, CyEdge, CxEdge, SxIcon, SyIcon : integer; BorderIconCount, ImgLeft, ImgTop : integer; FormStyle : int64; FormIcons : TBorderIcons; ARect : TRect; begin FormDC := GetWindowDC (Form.Handle); CyCaption := GetSystemMetrics (SM_CYCAPTION); // Height of Title bar CxSize := GetSystemMetrics (SM_CXSIZE); // Width of button in title bar CxDlgFrame := GetSystemMetrics (SM_CXDLGFRAME); // Thickness of frame CyDlgFrame := GetSystemMetrics (SM_CYDLGFRAME); // Thickness of frame CxEdge := GetSystemMetrics (SM_CXEDGE); // 3D border thickness CyEdge := GetSystemMetrics (SM_CYEDGE); // 3D border thickness SxIcon := GetSystemMetrics (SM_CXSMICON); // Recommended icon x size SyIcon := GetSystemMetrics (SM_CYSMICON); // Recommended icon y size FormStyle := GetWindowLong (Form.Handle, GWL_STYLE); FormIcons := Form.BorderIcons; // Make sure there's a title bar to draw in... if FormStyle and WS_CAPTION = WS_CAPTION then begin // Check what title bar buttons are shown BorderIconCount := 1; if biMinimize in FormIcons then inc (BorderIconCount); if biMaximize in FormIcons then inc (BorderIconCount); if biSystemMenu in FormIcons then inc (BorderIconCount); // Resize Bitmap to recommended title bar icon sizes ARect := Rect (0, 0, SxIcon, SyIcon); Bitmap.Canvas.StretchDraw (ARect, Bitmap); // Calculate left and top starting point of image ImgLeft := Form.Width - (BorderIconCount * CxSize + CxDlgFrame + CxEdge); ImgTop := (CyCaption + CyDlgFrame + CyEdge - Bitmap.Height) div 2; Mask := TBitmap.Create; Mask.Assign (Bitmap); Mask.Mask(Bitmap.TransparentColor); try TransparentStretchBlt (FormDC, ImgLeft, ImgTop, Bitmap.Width, Bitmap.Height, Bitmap.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height, Mask.Canvas.Handle, 0, 0); finally Mask.Free; end; end; end; "Shannon Broskie" wrote in message news:3ac8ec1a_2@dnews... > What is the proper way to transparently draw a bitmap? > > I need to use Maskblt because the final image will wind up being in the > form's title bar. > > I'm having trouble generating the mask... > Here's some code I've been using to play around with it... > > var > DC : HDC; > begin > image1.Picture.Bitmap.Assign (imgLock.Picture.Bitmap); > image1.Picture.Bitmap.Mask (imgLock.Picture.Bitmap.TransparentColor); > DC := GetWindowDC (Self.Handle); > MaskBlt (DC, 100, 100, imgLock.Width, imgLock.Height, > imgLock.Canvas.Handle, 0, 0, > image1.Canvas.Handle, 0, 0, SRCCOPY); > > > The mask method of image1 seems to generate a mask that maskblt does not > like... Any ideas? > > Thanks in advance... > >