Rob and all,
I solved the problem (with some help from MikeR on the progdigy.com
forum) by using a combination of making my window Topmost
(HWND_TOPMOST), and finding the the Powerpoint Show's handle to call
windows.SetForegroundWindow(h). That sets Powerpoint to foreground
with every timer tick of my program.
I'll paste the code below.
Thanks,
Tim.
--- In delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com, Rob Kennedy <rkennedy
...> wrote:
> Apparently, PowerPoint pauses when it loses focus. ...
> On the other hand, maybe you could arrange for your program's window to
> be always on top, and then redirect focus back to the PowerPoint
window.
> You'll have to find which window that is. Use WinSight of Spy++ to
> figure out what PowerPoint's window class is, and use FindWindow in
your
> program to get a handle to that window. Then use SetFocus.
>
> --
> Rob
>
function EnumWindowsProc(wHandle: HWND; slT: TStringList): Bool;
stdcall; export;
var
Title, ClassName: array[0..255] of char;
begin
Result := True;
GetWindowText(wHandle, Title, 255);
GetClassName(wHandle, ClassName, 255);
if IsWindowVisible(wHandle) then
slT.Add(string(Title) + '^' + string(ClassName));
end;
procedure TForm1.UpdateClock(Sender: TObject);
Var
Xo, Yo, X, Y : Integer;
TimerStr : string;
StringListT : TStringList;
T_string,C_string,TC_string : string;
z,ix,sp : integer;
h: hwnd;
begin
with Self do {Form1,...}
SetWindowPos(Handle, // handle to window
HWND_TOPMOST, // placement-order handle {*}
Left, // horizontal position
Top, // vertical position
Width,
Height,
// window-positioning options
SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
if not noPPT then begin
StringListT := TStringList.create;
try
Windows.EnumWindows(
EnumWindowsProc, Integer(StringListT));
if DebugMode then begin
StringListT.SaveToFile('enum.txt');
DebugMode := False;
end;
ix := -1;
for Z := 0 to StringListT.count-1 do begin
sp := pos('PowerPoint Slide Show',StringListT[Z]);
if sp <> 0 then begin // found it
ix := Z;
break;
end;
end;
if ix <> -1 then begin
TC_String := StringListT[ix];
sp := pos('^',TC_String);
T_string := copy(TC_string,1,sp-1);
C_string := copy(TC_string,sp3;1,255);
h := Windows.FindWindow(pchar(C_STring),nil); // find
using class name from enum
if h<>0 then
windows.SetForegroundWindow(h)
else begin
noPPT := true;
// ShowMessage('FindWindow Failed: Is Powerpoint Show
Running?');
end
end {if ix}
else begin
// ShowMessage('Powerpoint Slide Show not found');
noPPT := true;
end;
finally
StringListT.Free;
end;
end; {if not noPPT}
TimerStr := FormatDateTime('n:ss',Countdown);
{ Set font properties }
Canvas.Font.Style:=[fsBold];
Canvas.Font.Name:='TimesNewRoman';
Canvas.Brush.Style:=bsSolid;
Canvas.Font.Size:=TextSize;
Canvas.Font.Color:=FGColor;
{ Set center point }
Xo:=Form1.Width Div 2;
Yo:=Form1.Height Div 2;
if ExtraTextMode then begin
X := Xo - (Canvas.TextWidth(ExtraText) div 2);
Y := Yo - (Canvas.TextHeight(ExtraText) + (TextMargin div 2));
{top of upper text is up by text height and half margin}
Canvas.TextOut(X,Y,ExtraText);
X := Xo - (Canvas.TextWidth(TimerStr) div 2);
Y := Yo + (TextMargin div 2); {top of lower text is half of
margin between two lines}
Canvas.TextOut(X,Y,TimerStr);
end
else begin
X := Xo - (Canvas.TextWidth(TimerStr) div 2);
Y := Yo - (Canvas.TextHeight(TimerStr) div 2);
Canvas.TextOut(X,Y,TimerStr);
end;
if Countdown <= 0 then with application do begin
Timer1.enabled := False;
Close; // quit program at count of 0
end;
End;
.