Jump to content
Sign in to follow this  
pier

Window hooking

Recommended Posts

Hi!

Do you believe it is feasible to show some python graphics, say from matplotlib, and the "hook" the window and make it "live" inside a panel of a Delphi application? (when the panel moves/resizes the window moves/resizes with it)? If so is any code for doing this available? (if not I will write it)

Thanks for any suggestion

Share this post


Link to post

Thank you so much for your reply. I was aware of the possibility of using the SVG output of matplotlib (which I will use as an intermediate solution), however this is not what I am looking for. matplotlib was just an example of a more general type of approach I am pursuing, i.e. "embedding"/"controlling" graphical output of python applications in order to make it appear more integrated within a Delphi application. Anyhow thank you again for your time and suggestion.

Edited by pier

Share this post


Link to post

In case somebody is interested this is how I managed to nicely integrate matplotlib figures inside my delphi app.

 

1)   the pythons script shows the plot with "plt.show(block=False)"

 

2) this is the code which executes the script and embeds the plot

procedure TForm1.Button1Click(Sender: TObject);

var plotwnd:HWND;
begin
  PythonEngine1.ExecStrings( Synedit1.Lines );

 plotwnd:=Findwindow(nil,'Figure 1');
 if plotwnd<>0 then
 begin
 Windows.SetParent(plotwnd,(PageControl1.Pages[1] as TTabSheet).Handle);
 SetWindowLong(plotwnd, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and not WS_BORDER and not WS_SIZEBOX and not WS_DLGFRAME );
 showwindow(plotwnd,sw_showmaximized);
 setforegroundwindow(plotwnd);
 end;

end;

 

the plot is displayed inside a tabsheet which has an event handler to automatically resize the plot

procedure TForm1.PlotResize(Sender: TObject);
begin
   movewindow(plotwnd,0,0,(PageControl1.Pages[1] as TTabSheet).Width,(PageControl1.Pages[1] as TTabSheet).Height,True);
end;

 

 

 

Cattura.PNG

  • Like 4

Share this post


Link to post
On 3/11/2021 at 2:26 PM, pier said:


 Windows.SetParent(plotwnd,(PageControl1.Pages[1] as TTabSheet).Handle);
 

this might be stupid question :).   I tried the code but windows showed as undefined, I could not find which library to add to uses to make it recognizable

could you please give some details how to git it work

 

thanks

--- follow up.   found it 🙂

    it is:    

                winapi.windows.setparent ..........

thanks

 

Edited by Talal Bader

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×