Mega Code Archive

 
Categories / Delphi / Examples
 

Textbackgroundcolour

CreateWindow isn't an API but a function. You must call it first to create the window than you can use a DC to it for drawing. procedure TfApp.Button1Click(Sender: TObject); var hDesktopDC : HDC; begin hDesktopDC := GetDC(0); SetBkColor(hDesktopDC, clYellow); SetTextColor(hDesktopDC, clBlue); TextOut(hDesktopDC, 10, 10, pchar('This is some TextOut...'), 23); ReleaseDC(0, hDesktopDC); end; ************************************************************************************* OldTextColor : TColorRef; OldBkColor : TColorRef; OldBkMode : Integer; begin OldTextColor := SetTextColor(Form1.Canvas.Handle, RGB(0, 0, 255)); OldBkColor := SetBkColor(Form1.Canvas.Handle, RGB(255, 0, 0)); OldBkMode := SetBkMode(Form1.Canvas.Handle, OPAQUE); TextOut(Form1.Canvas.Handle, 100, 100, 'Blue text on red Background', 27); SetBkMode(Form1.Canvas.Handle, OldBkMode); SetBkColor(Form1.Canvas.Handle, OldBkColor); SetTextColor(Form1.Canvas.Handle, OldTextColor); ************************************************************************************* note that the Windows SetBkColor function is thus: //SetBkColor(HDC hdc, COLORREF crColor); //where //hdc is the handle of device context //crColor is the new background color value