Einzelnen Beitrag anzeigen

hboy

Registriert seit: 16. Jan 2004
364 Beiträge
 
#29

Re: was machen mit den Hangups ? Konsolenprobleme die zweite

  Alt 12. Jan 2005, 20:08
hättest den Klassenname nennen müssn. ich nehm mal an TConsoleWnd. TCustomWnd is meine heilige kuh

Delphi-Quellcode:
unit ConsoleWnd;

interface
  uses WndClass, StaticClass, types, windows, sysutils;

  type TConsoleWnd = class(TCustomWnd)
    proto: TCustomWndProtocolstatic;
    killed : boolean;
    Constructor Create(Param: Cardinal);
    Destructor Destroy; override;
  private
    fUseMessageThread: Boolean;
    TID: Cardinal;
    procedure Resize(Sender: TObject);
    procedure Hide(Sender: TObject);
    procedure SetUseMessageThread(doit: Boolean);

  public
    property UseMessageThread: Boolean read fUseMessageThread write SetUseMessageThread;
    procedure ProcessMessage;
  end;

  var WinKilled: Boolean;

implementation

 Constructor TConsoleWnd.Create(Param: Cardinal);
 begin
   inherited;
   self.Width := 700;
   self.Height := 400;
   self.UseMinConstraints := true;
   self.MinConstraintsVal := Point(700, 400);
   proto := TCustomWndProtocolstatic.Create(self.handle);
   proto.Width := self.ClientRect.Right;
   proto.Height := self.ClientRect.Bottom;
   proto.font.Color := $FFFFFF;
   proto.font.Name := 'Courier';
   proto.Color := $0;
   proto.Clear;
   self.OnResize := Resize;
   self.OnHide := Hide;
 end;

 procedure TConsoleWnd.Resize(Sender: TObject);
 begin
   if self.ClientRect.Bottom =0 then exit;
   proto.Width := self.ClientRect.Right;
   proto.Height := self.ClientRect.Bottom;
 end;

 procedure TConsoleWnd.Hide(Sender: TObject);
 begin
   proto.Hide;
   windows.TerminateProcess(GetCurrentProcess,0);
 end;

 Destructor TConsoleWnd.Destroy;
 begin
   proto.Free;
   inherited;
 end;

 procedure TConsoleWnd.ProcessMessage;
 var msg: TMsg;
 begin
   if GetMessage(msg,0,0,0) then
   begin
     TranslateMessage(msg);
     DispatchMessage(msg);
   end;
 end;


 procedure MessageProc(param: Cardinal);
 begin
  while true do TConsoleWnd(param).ProcessMessage;
 end;

 procedure TConsoleWnd.SetUseMessageThread(doit: Boolean);
 begin
   if (self.fUseMessageThread = false) and doit then
   begin
     BeginThread(nil,0,@MessageProc,@self,0,TID);
   end;

   if (self.fUseMessageThread = true) and (not doit) then
   begin
     TerminateThread(TID,0);
   end;
 end;
end.
Power is nothing without TControl
  Mit Zitat antworten Zitat