Board index » delphi » Function RGB - Pascal Win 1.5

Function RGB - Pascal Win 1.5

Can someone help me on how I can change my textcolor & backgroundcolor in
TPW1.5.  I use the WINCRT unit.

Is there a way to draw line to form a box in TPW 1.5
thanks

 

Re:Function RGB - Pascal Win 1.5


Quote
Hrymack wrote:
> Is there a way to draw line to form a box in TPW 1.5

You cannot draw a box in a WinCrt window. You have to create a "real" window,
find out its Device Context and draw to it. The following program creates a
generic window and draws a rectangle to it which will be filled with pixels
using the SetPixel and RGB functions:

uses owindows, wintypes, winprocs;
type
  TApp = object(TApplication)
           procedure InitMainWindow; virtual;
         end;
var
  Prog : TApp;

procedure TApp.InitMainWindow;
begin
  MainWindow := New(PWindow, Init(nil, 'MyTitle'))
end;

procedure DrawRectangle;
var
  DC : HDC;
  x, y : integer;
begin
  DC := GetDC(Application^.MainWindow^.HWindow);
  Rectangle(DC, 100, 100, 201, 201);

  for x := 101 to 199 do
    for y := 101 to 199 do
      SetPixel(DC, x, y, RGB(x, y, x div y))
end;

begin
  Prog.Init('');

  DrawRectangle;

  Prog.Run;
  Prog.Done
end.

Instead of Rectangle, you can use any other graphics function.

Note that if you minimize the window or another window becomes active, the
colorful rectangle will have disappeared when you reactivate your program.
To avoid that, you would have to create a user-defined window derived from
TWindow and write a virtual TWindow.Paint method.

--
http://www.geocities.com/SiliconValley/2926/txt/NGpaint.html

Re:Function RGB - Pascal Win 1.5


You can use the WM_CTLCOLOR command for the backgroundcolor of the
control.How it can look like is presented at http://netalive.org/ckb/ wich is

Coders Knowledge Base from where I have picked a lot of inspiration.

Hrymack skrev:

Quote
> Can someone help me on how I can change my textcolor & backgroundcolor in
> TPW1.5.  I use the WINCRT unit.

> Is there a way to draw line to form a box in TPW 1.5
> thanks

Re:Function RGB - Pascal Win 1.5


Quote
Hrymack wrote:
> > Is there a way to draw line to form a box in TPW 1.5
Frederic wrote:
> You cannot draw a box in a WinCrt window.

Sure you can...! I think I may have modified my wincrt.pas to include
this line:
 var  CrtWindow: HWnd;                  { CRT window handle }
In the interface section. I'm not sure if it is in the real wincrt.pas.
The rectangels also will be overwritten {erased} every time the screen
is redrawn {when it receives the wm_paint message} though... you would
have to add your own code to fix that.

{Begin program code here}

Program Draw;
Uses WinTypes,Winprocs,WinCrt;
Var DC:hDC;
Var Ch:Char;
Begin
     InitWinCrt;
     ShowWindow(CrtWindow,sw_showmaximized);
     WriteLn('Press any key to draw a rectangle; escape to quit');
     Repeat Until Keypressed; Ch:=ReadKey;
     Repeat
           Dc:=GetDC(CrtWindow);

Rectangle(Dc,random(320),random(240),random(320)+320,random(240)+240);
           ReleaseDC(CrtWindow,Dc);
           Ch:=Readkey;
     Until Ch=#27;
     DoneWinCrt;
End.

{End program code here}

Other Threads