Years ago, I made a small unit for TurboPascal7 that open a graphic
window in a console application.
Can someone tell me how to do the same thing with the new Delphi5?
Thank you, Leonardo Maffi.
unit ConsGraf;
interface
uses WinTypes, WinProcs;
type
Wind = object
err: boolean;
Window: HWnd;
Message: TMsg;
dc: HDC;
constructor OpenW(Name:string; x0,y0,w,h: integer);
destructor Term(wai:boolean); virtual;
end;
implementation
function WP(Window:HWnd; Message,WParam:Word;
LParam:Longint):Longint; export;
begin
case Message of
wm_Destroy:
begin
PostQuitMessage(0);
Exit;
end;
end;
WP := DefWindowProc(Window, Message, WParam, LParam);
end;
constructor Wind.OpenW(Name:string; x0,y0,w,h: integer);
const
AppName = 'name2';
WindowClass: TWndClass = (
style: 0;
lpfnWndProc: @WP;
cbClsExtra: 0;
cbWndExtra: 0;
hInstance: 0;
hIcon: 0;
hCursor: 0;
hbrBackground: 0;
lpszMenuName: AppName;
lpszClassName: AppName);
var
Tr: TRect; // For AdjustWindowRect.
name2: array[0..256] of char;
begin
err:= true;
if (Name<>'') and (w>0) and (h>0) then begin
err:= false;
StrPCopy(name2, Name);
if HPrevInst = 0 then begin
WindowClass.lpszClassName:= name2;
WindowClass.hInstance:= HInstance;
WindowClass.hIcon:= LoadIcon(0, idi_Application);
WindowClass.hCursor:= LoadCursor(0, idc_Arrow);
WindowClass.hbrBackground:=
GetStockObject(black_Brush);
if not RegisterClass(WindowClass) then err:= true;
end;
if not err then begin
tr.left:= x0;
tr.top:= y0;
tr.right:= w;
tr.bottom:= h;
AdjustWindowRect(tr, ws_OverlappedWindow, false);
Window := CreateWindow(
name2, name2, ws_OverlappedWindow,
x0,y0, w+(tr.bottom+x0-tr.left)-h,
h+(tr.right+y0-tr.top)-w, 0, 0, HInstance, nil);
err:= window=0;
ShowWindow(Window, CmdShow);
UpdateWindow(Window);
DC:= GetDC(Window);
err:= err or (DC=0);
end;
end;
end; // Term Wind.OpenW.
destructor Wind.Term(wai:boolean);
begin
if not err then begin
if wai then
while GetMessage(Message, 0, 0, 0) do begin
TranslateMessage(Message);
DispatchMessage(Message);
end;
ReleaseDC(window, dc);
end;
end;
end.
Sent via Deja.com http://www.deja.com/
Before you buy.