Solved

Colour change

Posted on 1998-01-18
1
777 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
1 Comment
 
LVL 5

Accepted Solution

by:
inter earned 50 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now