Quote
Franck MICHEL (Franck.Mic...@wanadoo.fr) wrote:
:
: I would like to know how I could make the simplest adaptation possible
: of my programs in TP 5.5 to TP for Windows.
:
: My programs in TP 5.5 only use Initgraph, lineto and moveto;
: what should I use in replacement of these instructions ?
Here is a short example which may answer your question:
Program TestGraphics;
Uses WinCrt,WinProcs,WinTypes;
Var MyWindowHandle : HWnd;
DeviceContextHandle : HDC;
Begin
InitWinCrt;
MyWindowHandle := GetActiveWindow; {FindWindow would be safer.}
{Or change the WinCrt unit to make the WindowHandle (CRTWindow) public.}
DeviceContextHandle := GetDC(MyWindowHandle);
MoveTo(DeviceContextHandle,100,100);
LineTo(DeviceContextHandle,200,300);
ReleaseDC(MyWindowHandle,DeviceContextHandle);
{Don't forget to Release. Windows only allows a Maximum of 5 Device
Contexts for the entire system.}
end.
To make more interesting lines (color, width, and style) you need to
look up CreatePen, SelectObject, and DeleteObject.
There is a major problem with the preceeding (and following) code.
Windoze will NOT buffer the contents of its windows. If another
window pops up in front of yours, the contents of your window are
erased and it is up to you to redraw the window when it again becomes
visible. (WinCrt does buffer text for you, redrawing it as needed.)
To do this right, you could CreateCompatibleBitmap and CreateCompatibleDC,
SelectObject the bitmap into the spare DC, do all your drawing on the spare
DC, and copy the results (BitBlt) to your window's DC from time to time.
Whenever your program pauses, you should loop on PeekMessage to see whether
there is WM_Paint message requesting than you repaint (BitBlt) your window.
With or without the above complication, you MIGHT want to make a fake
graph unit, implementing just what you need for your programs:
Unit Graph; {Fake graph unit for compiling DOS programs for Windows.}
Interface
Uses WinCrt,WinProcs,WinTypes;
Procedure InitGraph(Var GraphDriver,GraphMode:Integer; DriverPath:String);
Procedure MoveTo(X,Y:Integer);
Procedure LineTo(X,Y:Integer);
Implementation
Var Window : HWnd;
Context : HDC;
OldExitProc : Pointer;
Procedure ExitGraph; far;
Begin
ExitProc := OldExitProc;
ReleaseDC(Window, Context);
DoneWinCrt;
End;
Procedure InitGraph(Var GraphDriver,GraphMode:Integer; DriverPath:String);
Begin
{?Set WinCrt screen variables according to Graphmode?}
InitWinCrt;
Window := GetActiveWindow;
Context := GetDC(Window);
OldExitProc := ExitProc;
ExitProc := @ExitGraph;
end;
Procedure WinMoveTo(DC:HDC;X,Y:Integer);
Begin
MoveTo(DC,X,Y); {WinProcs version}
End;
Procedure MoveTo(X,Y:Integer); {Faked DOS Version}
Begin
WinMoveTo(Context,X,Y);
End;
Procedure WinLineTo(DC:HDC;X,Y:Integer);
Begin
LineTo(DC,X,Y); {WinProcs Version}
End;
Procedure LineTo(X,Y:Integer); {Faked DOS version}
Begin
WinLineTo(Context,X,Y);
end;
end.
|\/| || Burnaby South Secondary School
| |orew...@planeteer.com || Beautiful British Columbia
Mathematics & Computer Science || (Canada)