1. Rick Domogalik
  2. PowerBuilder
  3. Wednesday, 11 December 2019 19:25 PM UTC

I have written an add on for Microsoft Word that opens my powerbuilder app when the user clicks a button on the ribbon in Word.  I would like to have to the powerbuilder app always open directly over where ever the user has put the Word window.  Most of our users have 2 monitors.  If the user moves word to their second monitor, then clicks the add on button, the powerbuild app will open on the primary monitor in the default location and sometimes the user doesn't see where it opened.

Is there a way to get the location of the active Word window and its specific monitor?

 

Thanks for any help.

 

Rick

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 12 December 2019 06:22 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Rick,

If you don't want to deal with Windows API function you may simply specify the position you want to open you application as commandline parameters. You can get the position of your Word window using the Word API.

HTH,

René

Comment
  1. Rick Domogalik
  2. Thursday, 12 December 2019 14:45 PM UTC
Worked like a charm. Thanks for the help!
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 11 December 2019 22:31 PM UTC
  2. PowerBuilder
  3. # 1

Greetings, Rick -

What version of PB are you using to developing your application? Are you creating it as a 32-bit or 64-bit application? How much experience do you have calling Windows API functions from PB? These are all important factors in being able to accomplish what you are requesting.

To build slightly on Michael's response, I agree you will need to use the FindWindowW API function (the trailing "W" in the name indicates this API is for use with Unicode (Wide) strings. To use this API, you will need the exact and complete title of the MS Word window. If I were attempting this, I would pass the window title/caption to my PowerBuilder application as a string argument (and capture it's value in the PB Application object's Open event).

The FindWindowW API function will return the Windows handle (ID number) of the requested window. Using this value, the GetWindowRect API function can then be called to obtain the current bounding rectangle (structure) of the MS Word window, in pixel coordinates. These coordinates can then be converted to PowerBuilderUnits (PBU's) with the PB PixelsToUnits function.

I hope this helps get you started.

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Wednesday, 11 December 2019 20:54 PM UTC
  2. PowerBuilder
  3. # 2

Hi Rick, there is!

There are several Windows API calls involved. First of all you the PB app needs to "find" the Word window. There is a FindWindow API for that. Then you need to find the X+Y+Width+Height of the Word window (other API calls) and move+resize your PB app window accordingly. There are also Windows API calls to query across monitors. It will likely take several calls and some testing to get all coordinates right. Note: Sometimes an app window spans across multiple monitors and each monitor may have separate scaling percentage. You may even see an app choose to have its own custom scaling differing from monitor's standard scaling. So coordinate calculation is sometimes tricky.

Unfortunately I'm in the middle of installing all dev tools on new laptop after a short circuit on the laptop where all my PB samples are stored. Hopefully others can chime in regarding the right API calls.

If I had to start all over, I would start at TopWiz Programming's web-site of free code samples. High chance you can find almost every Windows API call including PB code samples that you will need in real-world apps. Roland is doing a great service to the full PB community with his rich code samples.

HTH /Michael.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.