I have two programs, just forms with buttons. One program on the button calls the exe file of another program and makes it a child window. It is impossible to send a button click (which lies on the form of the second program) after opening.

procedure TForm1.Button1Click(Sender: TObject); var hw:hwnd; FormRgn:HRGN; wnd:THandle; begin ShellExecute(Handle, 'open','D:\12\12 \Win32\Debug\Web.exe',nil,nil,SW_SHOWMINNOACTIVE); sleep(100); hw:=FindWindow(nil,'Web'); //Π½Π°Ρ…ΠΎΠ΄ΠΈΠΌ Ρ…Π΅Π½Π΄Π΅Π» Π½ΡƒΠΆΠ½ΠΎΠ³ΠΎ ΠΎΠΊΠ½Π° Windows.SetParent(hw,Handle); //Π΄Π΅Π»Π°Π΅ΠΌ Π΅Π³ΠΎ Π΄ΠΎΡ‡Π΅Ρ€Π½ΠΈΠΌ ΠΎΠΊΠ½ΠΎΠΌ прилоТСния MoveWindow(hw,0,0,ClientWidth,ClientHeight,true); //смСщаСм ΠΎΠΊΠ½ΠΎ Π² ΠΏΠΎΠ·ΠΈΡ†ΠΈΡŽ 0 0 FormRgn:=CreateRectRgn(7,30,Width-200,Height-100); //ΡƒΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΊΡƒΡŽ ΠΎΠ±Π»Π°ΡΡ‚ΡŒ оставим Π²ΠΈΠ΄ΠΈΠΌΠΎΠΉ SetWindowRgn(hw, FormRgn, TRUE); //ΠΎΠ±Ρ€Π΅Π·Π°Π΅ΠΌ всС лишнСС wnd:=FindWindow(nil,'Web'); // ΠΈΡ‰Π΅ΠΌ ΠΎΠΊΠ½ΠΎ ΠΏΠΎ названию wnd:=FindWindowEx(wnd,0,nil,'Web'); // ΠΈΡ‰Π΅ΠΌ ΠΊΠ½ΠΎΠΏΠΊΡƒ ΠΏΠΎ названию wnd:=FindWindowEx(wnd,0,nil,'start'); // ΠΈΡ‰Π΅ΠΌ ΠΊΠ½ΠΎΠΏΠΊΡƒ ΠΏΠΎ названию SendMessage(wnd,WM_LBUTTONDOWN,0,0); // ΠΆΠΌΠ΅ΠΌ ΠΊΠ½ΠΎΠΏΠΊΡƒ SendMEssage(wnd,WM_LBUTTONUP,0,0); //отпускаСм ΠΊΠ½ΠΎΠΏΠΊΡƒ end; 
  • your code lacks heaps of checks - was there anything for every call to FindWindow or not? - kami
  • "One button program calls the exe file of another program and makes it a child window." Of course, I could be wrong, but something I strongly doubt that you can make the window of another process (application) a child window. - Alekcvp

1 answer 1

Understood, thanks for responding. It was indeed logical that after the window became a child, it was necessary to use the handle of the main program.