From: "Renaldas" Newsgroups: borland.public.delphi.graphics References: <3af9b2dc_2@dnews> <3AF9EF4A.B4A3E457@borland.newsgroups> <3b0049b1_1@dnews> Subject: Re: How to do textout in the caption region of a form? Date: Fri, 25 May 2001 02:23:09 -0700 Lines: 206 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 NNTP-Posting-Host: 212.59.4.234 Message-ID: <3b0e2464_1@dnews> X-Trace: dnews 990782564 212.59.4.234 (25 May 2001 02:22:44 -0700) Path: dnews Xref: dnews borland.public.delphi.graphics:39176 Hi Andre, Below is the help for you and working sample: // You have to write a handler for Form's OnPaint event; procedure TForm1.FormPaint(Sender: TObject); const sc_title = 'This is the caption text which you want to write'; var MyRect, RealRect : TRect; MyHDC : HDC; x, y : integer; SysLogFont, LogFont : TLogFont; begin // here is full form's rectangle GetWindowRect(Handle, RealRect); MyHDC := GetWindowDC(Handle); // Let's set font size to system font's size and select it if GetObject(Canvas.Font.Handle, SizeOf(LogFont), @LogFont)<>0 then begin if GetObject(GetStockObject(SYSTEM_FONT), SizeOf(SysLogFont), @SysLogFont)<>0 then begin LogFont.lfHeight := SysLogFont.lfHeight; end; SelectObject(MyHDC, CreateFontIndirect(LogFont)); end; // Now lets calculate the rectangular region where you want to write your text on x := GetSystemMetrics( SM_CXSIZE )+ GetSystemMetrics( SM_CXBORDER )+ GetSystemMetrics( SM_CXFRAME ); y := GetSystemMetrics( SM_CYFRAME ) + GetSystemMetrics( SM_CYBORDER ); MyRect.Left := x; MyRect.Top := y; MyRect.Right := RealRect.Right - RealRect.Left -2*x - GetSystemMetrics( SM_CXFRAME ); MyRect.Bottom := GetSystemMetrics( SM_CYFRAME ) + GetSystemMetrics( SM_CYBORDER ) + GetSystemMetrics(SM_CYSIZE ); if Active then SetBkColor( MyHDC, GetSysColor(COLOR_ACTIVECAPTION) ) else SetBkColor( MyHDC, GetSysColor(COLOR_INACTIVECAPTION) ); // This enables to view gradient color change under Windows 2000 SetBkMode( MyHDC, TRANSPARENT ); // Text color must be retrieved from system also if Active then SetTextColor( MyHDC, GetSysColor(COLOR_CAPTIONTEXT) ) else SetTextColor( MyHDC, GetSysColor(COLOR_INACTIVECAPTIONTEXT) ); // Here is actual text output on the caption DrawText( MyHDC, sc_title, -1, MyRect, DT_LEFT ); ReleaseDC( Handle, MyHDC ); end; You have to write a handler for form's OnCreate event as follows: procedure TForm1.FormCreate(Sender: TObject); begin // Just set canvas font to your font. // I used this to write Lithuanian font text on the systems which doesn't supported Lithuanian language // Well, this may contradict to Microsoft rule that form's caption must be written in System's font, but I denied it // for the sake of Lithuanian user Font.Name := 'TimesLT Stressed'; Font.Size :=12; Font.Charset := ANSI_CHARSET; Canvas.Font.Name := 'TimesLT Stressed'; Canvas.Font.Size :=12; Canvas.Font.Charset := ANSI_CHARSET; // It is necessary to set Form's caption to empty string in order system doesn't implement Caption drawing Caption := ''; // Form has to be repainted when a user switches to another application's window Application.OnDeactivate := AppDeactivate; end; procedure TForm1.AppDeactivate(Sender: TObject); begin Form1.Repaint; end; // Also form has to be repainted here too procedure TForm1.FormDeactivate(Sender: TObject); begin Form1.Repaint; end; Take into account Microsoft rule: there *must* be no bitmaps in form's caption area. There are some other rules, but this is most important. Well, but you can avoid it always on your own will ... :) I hope it helps. Also: in case you will know any Delphi or MS VisualC++ projects which need programmer let me know. I am doing off-site projects in Delphi, Visual C++. Kind regards, Renaldas Urniezius Kaunas, Lithuania the Baltic States "andre groeneveld" wrote in message news:3b0049b1_1@dnews... > Thanks already, > > How to tell the program in which position to do the textout? > I wanna for example put the time in the right side of the title bar, having > the original background color settings as default behind the text...... > > Friendly greetings, > > > André Groeneveld > Middelweg 11a > 3235 NM Rockanje > Telefoon: 0031 181 401544 > Mobiel: 0031 6 53885101 > Fax: 0031 84 8688169 > Email: A.groeneveld@hccnet.nl > Hotmail: Andre_developer@hotmail.com > > > -- > André Groeneveld > Middelweg 11a > 3235 NM Rockanje > Telefoon: 0031 181 401544 > Mobiel: 0031 6 53885101 > Fax: 0031 84 8688169 > Email: A.groeneveld@hccnet.nl > Hotmail: Andre_developer@hotmail.com > "Charles Hacker" schreef in bericht > news:3AF9EF4A.B4A3E457@borland.newsgroups... > > andre wrote: > > > Hello, who knows how i can write text with the TEXTOUT command in the > title > > > bar of a form in D5? > > > > You have to handle the WM_NCPAINT message. > > > > type > > TForm1 = class(TForm) > > private > > procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT; > > public > > end; > > > > var > > Form1 : TForm1; > > > > implementation > > > > {$r *.dfm} > > > > procedure TForm1.WMNCPaint(var Msg: TWMNCPaint); > > var ACanvas : TCanvas; > > begin > > inherited; > > ACanvas := TCanvas.Create; > > try > > ACanvas.Handle := GetWindowDC(Form1.Handle); > > with ACanvas do begin > > Brush.Color := clActiveCaption; > > Font.Name := 'Tahoma'; > > Font.Size := 8; > > Font.Color := clred; > > Font.Style := [fsItalic, fsBold]; > > TextOut(GetSystemMetrics(SM_CYMENU) + > > GetSystemMetrics(SM_CXBORDER), > > Round((GetSystemMetrics(SM_CYCAPTION) - > > Abs(Font.Height))/2) +1, > > ' Some Text' > > end; > > finally > > ReleaseDC(Form1.Handle, ACanvas.Handle); > > ACanvas.Free; > > end; > > end; > > > > -- > > Charles Hacker > > Lecturer in Electronics and Computing > > School of Engineering > > Griffith University - Gold Coast > > Australia