Steve Maughan 26 Posted March 17, 2022 I have a popup menu on a TPaintBox. Up to now I've used the simple code: PopupPoint := PaintBox.ClientToScreen(X, Y); RadialMenu.Popup(PopupPoint.X, PopupPoint.Y); It seem this doesn't work on multi-monitor systems — the Radial Menu isn't visible after the popup and the user thinks the application has crashed. How do I adjust this so it works with multiple monitors? Thanks! Steve Share this post Link to post
Bill Meyer 337 Posted March 17, 2022 Perhaps this would help? https://stackoverflow.com/questions/65355149/how-to-convert-screen-coordinates-to-control-coordinates-with-embedded-form-and Share this post Link to post
Steve Maughan 26 Posted March 17, 2022 (edited) 2 minutes ago, Bill Meyer said: Perhaps this would help? https://stackoverflow.com/questions/65355149/how-to-convert-screen-coordinates-to-control-coordinates-with-embedded-form-and I found this but it seems to be FMX and, I should have said, my application is VCL. But thanks — Steve Edited March 17, 2022 by Steve Maughan Share this post Link to post
Remy Lebeau 1394 Posted March 17, 2022 (edited) Which version of Delphi are you using? TControl.ClientToScreen() does not take 2 integers as input, it takes either a TPoint or a TRect. But, fixing that, the rest of the code shown works just fine for me on my 2-monitor system. ClientToScreen() returns screen coordinates, and Popup() takes screen coordinates, and screen coordinates are within the Virtual Screen, not any particular monitor. Regardless of which monitor the PaintBox is displayed on, the PopupMenu appear wherever I click on the PaintBox. So, either you are doing something else wrong that we can't see, or this is a bug in your Delphi's VCL, Edited March 17, 2022 by Remy Lebeau Share this post Link to post
Steve Maughan 26 Posted March 17, 2022 1 minute ago, Remy Lebeau said: Which version of Delphi are you using? TControl.ClientToScreen() does not take 2 integers as input, it takes either a TPoint or a TRect. But, fixing that, the rest of the code shown works fine for me on my 2-monitor system. So, unless there is a bug in your Delphi's VCL, this should work just fine, since ClientToScreen() returns screen coordinates, and Popup() takes screen coordinates. Screen coordinates are within the Virtual Screen, not any particular monitor. Thanks Remy, I am actually passing a TPoint (my error when creating the code example). The user is reporting that the application crashes when they right click, and it's corrected when they only have one monitor. Does ClientToScreen work in all cases when the extra monitor is above, below, left and right of the main screen? Steve Share this post Link to post
Anders Melander 1782 Posted March 17, 2022 29 minutes ago, Steve Maughan said: The user is reporting that the application crashes when they right click, and it's corrected when they only have one monitor. So you haven't tried to reproduce the problem with two monitors...? 29 minutes ago, Steve Maughan said: Does ClientToScreen work in all cases when the extra monitor is above, below, left and right of the main screen? Yes. If you had looked at the source you would have seen that TControl.ClientToScreen calls TControl.GetClientOrigin which ends up calling Winapi.Windows.ClientToScreen(Handle, Result); The ClientToScreen API function returns the coordinates relative to the top left corner of the primary monitor, which is what you'd want. Share this post Link to post
Steve Maughan 26 Posted March 17, 2022 2 minutes ago, Anders Melander said: So you haven't tried to reproduce the problem with two monitors...? Yes. If you had looked at the source you would have seen that TControl.ClientToScreen calls TControl.GetClientOrigin which ends up calling Winapi.Windows.ClientToScreen(Handle, Result); The ClientToScreen API function returns the coordinates relative to the top left corner of the primary monitor, which is what you'd want. I don't have an extra monitor but a colleague has one so we're trying to reproduce. It seem the problem occurs in a configuration of two monitors above the main screen / laptop screen. Share this post Link to post
Anders Melander 1782 Posted March 17, 2022 So place a breakpoint on the call to ScreenToClient and see what's going on. Easy Peasy. Share this post Link to post
Remy Lebeau 1394 Posted March 17, 2022 2 hours ago, Steve Maughan said: The user is reporting that the application crashes when they right click, and it's corrected when they only have one monitor. Is there an error message? And you didn't answer my question - which version of Delphi are you using? Nothing in the code you have shown should be accessing any monitor-specific functionality, AFAIK. 2 hours ago, Steve Maughan said: Does ClientToScreen work in all cases when the extra monitor is above, below, left and right of the main screen? Yes. Share this post Link to post
Steve Maughan 26 Posted March 18, 2022 16 hours ago, Remy Lebeau said: Is there an error message? And you didn't answer my question - which version of Delphi are you using? Nothing in the code you have shown should be accessing any monitor-specific functionality, AFAIK. Yes. Hi Remy, I'm using Delphi 10.4.2. We have been unsuccessful in replicating the problem, although I did see it for myself on a Zoom call. At this point I'm going to move on and class it as a strange setup issue. Thanks — Steve Share this post Link to post