screen pixel to point?

D

djpnewton

Hi,

I am automating PowerPoint and I want to use AddPolyLine to put a line
a specific place on the screen/slide.

For example say make a line with the points ((100, 100), (200, 200)) in
"pixels".

I was using "ActivePresentation.SlideMaster.Width / Screen.Width" as a
ratio to convert to "points" but now I realise that the slide is
actually offset down a bit on the y axis because it uses a different
aspect ratio to the screen.

So I need to find the slide x/y offset to put a ((100, 100), (200,
200)) line (in pixels) into powerpoint (converting into its points
units).

Can anyone help me?

Thanks :)

Daniel
 
A

Austin Myers

Daniel,

Before going much further, have you tested this on a machine with a
different resolution or different DPI setting? If not I would do so as I
think you'll see it gets a bit more complicated. Are you first reading the
screen resolution?

Austin Myers
MS PowerPoint MVP Team

PowerPoint Video and PowerPoint Sound Solutions www.pfcmedia.com
 
D

djpnewton

Thats not a problem, I am actually drawing on a different transparent
window on top of the presentation. Then I want to copy the line I just
drew into the powerpoint presentation - this is working so far except
for the x/y offset errors
 
S

Steve Rindsberg

Hi,

I am automating PowerPoint and I want to use AddPolyLine to put a line
a specific place on the screen/slide.

For example say make a line with the points ((100, 100), (200, 200)) in
"pixels".

I was using "ActivePresentation.SlideMaster.Width / Screen.Width" as a
ratio to convert to "points" but now I realise that the slide is
actually offset down a bit on the y axis because it uses a different
aspect ratio to the screen.

So I need to find the slide x/y offset to put a ((100, 100), (200,
200)) line (in pixels) into powerpoint (converting into its points
units).

There's a problem, or at least a feature of PPT that might translate to a
problem for you here. PowerPoint sizes the slide presentation to the current
video resolution of the computer it's running on (in slide show view). At
least it does that in full screen mode. In window mode, the presentation's
sized to the current window.

If you know you're in full screen mode, you could probably call the WinAPI to
get the current video x and y rez, and use a ratio against the current
Presentation.PageSetup.SlideHeight and .SlideWidth to work out a points to
pixels conversion factor for the current situation.

But before you tramp down that long, hot, dusty road, how come you need to work
in pixels in the first place?
 
A

Austin Myers

Ah, afraid that's not going to work well for you as you are reading the
form's coordinates which are not the slides coordinates. To explain, when
you are in edit mode there is more on the screen than just the slide, (i.e.
tool bars, etc.) But I suspect your form is reading it's coordinates as if
it has the full screen. When you place your mouse, say at the very top left
corner of the slide, you are really at say 50 pix down and 75 pix right of
the full screen. (Just example numbers and they change depending on screen
resolution.)

As you have seen, there will always be an "offset" once PPT goes into
playback mode and your placement will be off. Does that make sense?


Austin Myers
MS PowerPoint MVP Team

PowerPoint Video and PowerPoint Sound Solutions www.pfcmedia.com
 
D

djpnewton

Hi Steve,

Yes I am running in full screen mode.

I have been using a ratio based on the slide height/width but my
problem now is trying to figure out the x/y offset of the slide (as the
slide has a different aspect ratio to my screen and seems to be offset
about 20 pixels from the top). I want to be able to figure this out
programmatically so I can apply it to other presentations as well

The reason I want to do this is because I have a window overlaying the
powerpoint presentation window which I can draw on (using the mouse)
and I want to copy these drawings into the presentation once the
drawing is finshed.

thanks
 
D

djpnewton

Yes you are right my form is full screen.

But I am doing the operation with the powerpoint presentation running
and in full screen also. The problem is the slide still does not take
up the full screen area I need to find the x/y offset of the slide in a
running presentation.

thanks

dan
 
A

Austin Myers

I hear ya, but, that is going to depend upon screen resolution and it's dpi
settings. You might get it to work on your machine using some Kentucky
Windage but moving it to any other machine will be problematic.

Austin Myers
MS PowerPoint MVP Team

PowerPoint Video and PowerPoint Sound Solutions www.pfcmedia.com
 
D

djpnewton

If anyone is interested I have figured it out myself.

here is a Delphi code snippet of how to get the useful variables (for a
running full screen presentation):

PixelsPerPoint - how many screen pixels per powerpoint-point units

XOffset - the offset in screen pixels of the slide from the left of the
screen

YOffset - the offset in screen pixels of the slide from the top of the
screen

procedure TfrmMain.InitTranslationVariables(var PixelsPerPoint,
XOffset, YOffset: Double);
var
PPAspectRatio, ScreenAspectRatio: Double;
PPWidthInPixels, PPHeightInPixels: Double;
begin
PPAspectRatio := PPApp.ActivePresentation.PageSetup.SlideWidth /
PPApp.ActivePresentation.PageSetup.SlideHeight;
ScreenAspectRatio := Screen.Width / Screen.Height;
if PPAspectRatio > ScreenAspectRatio then begin
PixelsPerPoint := Screen.Width /
PPApp.ActivePresentation.PageSetup.SlideWidth;
XOffset := 0;
PPHeightInPixels := PPApp.ActivePresentation.PageSetup.SlideHeight
* PixelsPerPoint;
YOffset := (Screen.Height - PPHeightInPixels) / 2;
end
else begin
PixelsPerPoint := Screen.Height /
PPApp.ActivePresentation.PageSetup.SlideHeight;
YOffset := 0;
PPWidthInPixels := PPApp.ActivePresentation.PageSetup.SlideWidth *
PixelsPerPoint;
XOffset := (Screen.Width - PPWidthInPixels) / 2;
end;
end;
 
D

djpnewton

oh yeah, it seems to work on different screen resolutions and different
slide sizes too :)
 
S

Steve Rindsberg

oh yeah, it seems to work on different screen resolutions and different
slide sizes too :)

You may also want to factor in the PPT version. 97 doesn't quite fill the
screen even if the slide aspect ratio matches the screen aspect ratio.

If you need to support '97, that is. ;-)

Thanks for posting back with your results by the way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top