My question is how to place a window belonging to our win32 application inside of MS Word, when Word has been set as the parent of that window using Windows API SetParent(HandleOfMyWindow, HandleOfWord).
The background of my question is that we have lots of code built around a system where we have installed a macro in Word that when started from a button on the ribbon sends a message to our app to tell it to create a given window and show it inside of Word. This window can then insert text etc. into Word by using Word as a OLE Automation server. This has worked fine for the most part for many years. It still is, but occasionally the window is displayed far out of the visible area of Word. For example it can be 900 pixels to the right of the right edge of Word. It can often be found by making Word very wide across multiple monitors. The problem is only there on multi monitor systems. It is often affected by how our app and Word is placed on the monitors. It might also be affected by what monitors is set as the main monitor.
Our app is made using Delphi creating standard win32 exe's. The problem might have gotten worse after we started using VCL Styles.
I have tried placing our window using Windows API SetBounds and SetWindowPos, just the top and left properties of the form, and some other things. It just never pops up where I think my code is telling it to. Most of the time it is visible and all is well, but still at another position than I set. I just can figure out any system to where it is placed.
However, when writing this I found something that might be relevant, but still no solution:
- https://en.delphipraxis.net/topic/4882-a-big-and-very-strange-bug-with-high-dpi-vcl-style-and-form-constraints/
- From SetParent documentation: "Unexpected behavior or errors may occur if hWndNewParent and hWndChild are running in different DPI awareness modes."