Thema: FindWindow

Einzelnen Beitrag anzeigen

t.roller
(Gast)

n/a Beiträge
 
#7

AW: FindWindow

  Alt 4. Feb 2017, 07:35
Statt jedes einzelne Objekt zu suchen, ist es ausreichend, nur das Empfänger-Window zu suchen und dem die Messages zu senden.
Delphi-Quellcode:
SENDER:

var
  Form1: TForm1;
  aWnd : HWND;

const
    WM_MY_MESSAGE = WM_USER + 10; //1034

implementation

{$R *.dfm}

procedure TForm1.bnMINIMIZEClick(Sender: TObject);
begin if aWnd<>0 then Postmessage(aWnd,WM_SYSCOMMAND, SC_MINIMIZE,0); end;

procedure TForm1.bnRESTOREClick(Sender: TObject); // SC_RESTORE
begin
aWnd := FindWindow(NIL, 'WindowProc');
  if aWnd<>0 then
  BEGIN
      Postmessage(aWnd,WM_SYSCOMMAND, SC_RESTORE,0);
      SetForegroundwindow(aWnd);
      SendMessage(aWnd, WM_SYSCOMMAND, SC_RESTORE, aWnd);
  END;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
SendMessage(aWnd, WM_MY_MESSAGE, 123, 1);
SendMessage(aWnd, WM_MY_MESSAGE, 123, 2);
SendMessage(aWnd, WM_MY_MESSAGE, 123, 3);
SendMessage(aWnd, WM_MY_MESSAGE, 123, 4);
SendMessage(aWnd, WM_MY_MESSAGE, 123, 5);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin aWnd := FindWindow(NIL, 'WindowProc'); end; //sucht Empfänger

procedure TForm1.bnCLOSEClick(Sender: TObject);
begin
if aWnd<>0 then Postmessage(aWnd,WM_SYSCOMMAND,SC_CLOSE,0); //Close Empfänger
Application.Terminate; //Close Sender
end;

end.
//---------------------------------------------------------
EMPFÄNGER:

  protected
    procedure WndProc(var Message: TMessage); override;
  end;

var
  Form1: TForm1;

const
    WM_MY_MESSAGE = WM_USER + 10; //1034

implementation

{$R *.dfm}

procedure TForm1.WndProc(var Message: TMessage);
begin
  inherited;
  case Message.Msg of
    WM_MY_MESSAGE: BEGIN
      case Message.LParam of
      1: PostMessage(Button1.Handle, BM_CLICK, 0, 0);
      2: PostMessage(Button2.Handle, BM_CLICK, 0, 0);
      3: PostMessage(Button3.Handle, BM_CLICK, 0, 0);
      4: PostMessage(Button4.Handle, BM_CLICK, 0, 0);
      5: PostMessage(Button5.Handle, BM_CLICK, 0, 0);
      end;
    END;
  end;
end;

procedure TForm1.bnCLEARClick(Sender: TObject);
begin Memo1.clear; end;

procedure TForm1.Button1Click(Sender: TObject);
begin Memo1.Lines.Add('B1'); end;

procedure TForm1.Button2Click(Sender: TObject);
begin Memo1.Lines.Add('B2'); end;

procedure TForm1.Button3Click(Sender: TObject);
begin Memo1.Lines.Add('B3'); end;

procedure TForm1.Button4Click(Sender: TObject);
begin Memo1.Lines.Add('B4'); end;

procedure TForm1.Button5Click(Sender: TObject);
begin Memo1.Lines.Add('B5'); end;
Angehängte Dateien
Dateityp: zip WndProcTest.zip (1,69 MB, 15x aufgerufen)

Geändert von t.roller ( 4. Feb 2017 um 08:52 Uhr)
  Mit Zitat antworten Zitat