Solved

Colour change

Posted on 1998-01-18
1
788 Views
Last Modified: 2010-04-16
how do i change the text and background colour using Borland turbo pascal for windows.
Cheers
Scarhand
0
Comment
Question by:Scarhand
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
inter earned 50 total points
ID: 1217167
In windows, when you want to draw any thing on windows. You should do it by calling windows internal functions called GDI (graphic driver interface) API(application programmers interface). To draw, you must first obtain a handle (an integer value like pointer that points to that memory object). Once you obtain the handle, you can modify its properties, and paint on it. The following example writes a Blue text on your window in Borland Pascal.

var
  ThePen, OldPeb : HPen; {these are defined by wintypes unit}
  TheDC  : HDC;
const
  Ts : PChar = 'This is test'#0;
begin
  TheDC := GetDC(hWnd);  {obtain device context handle for hWnd}
                         {Hwnd is a handle to out window ssigned}
                         {by Windows}
  ThePen := CreatePen(psSolid, 1, BLUE);
  OldPen := SelectObject(TheDC, ThePen);
  {Begining of any drawing}
  TextOut(TheDC, 10,10, Ts, Length(Ts)); {now draw text at 10,10}
                                         {Since the PEN is BLUE}
                               {The text will be blue}
  {End of any drawing}
  SelectObject(TheDC, OldPen); {Replace old pen}
  DeleteObject(ThePen);   {Free up pen}
  ReleaseDC(hWnd, TheDC); {Free up the DC}
end;

As you see the operation is a bit complex. This is due to the fact that windows drawing system should maintain all the applications drawings and prevent them from destroying other windows appereance.
To my personal oppinion if you want to program on windows you'd better program in Borland Delphi since you know pascal. If this not satisfy you I may give more info...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question