[delphi-en] Re: Controlling Powerpoint from Delphi app
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@yahoogroups.com, Rob Kennedy [EMAIL PROTECTED] 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,sp+1,255); h := Windows.FindWindow(pchar(C_STring),nil); // find using class name from enum if h0 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; {try} 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;
Re: [delphi-en] Re: Controlling Powerpoint from Delphi app
kc0fcp wrote: AFIK, Powerpoint knows nothing about my program. I don't know why the presentation pauses - it seems to be a built-in characteristic of PPT. I reviewed all the show setup options in PPT and didn't see anything about pausing for other windows, though. Apparently, PowerPoint pauses when it loses focus. I've seen a couple of recommendations to use PowerShow to solve that. It looks like overkill, but it might be worth the money to not have to write a solution yourself. http://officeone.mvps.org/powershow/powershow.html 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
Re: [delphi-en] Re: Controlling Powerpoint from Delphi app
- Original Message - kc0fcp wrote: AFIK, Powerpoint knows nothing about my program. I don't know why the presentation pauses - it seems to be a built-in characteristic of PPT. I reviewed all the show setup options in PPT and didn't see anything about pausing for other windows, though. Rob wrote: 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. . I have a program i can send to get the win type if you should need one. I've done similar code as Rob suggests to solve a similar problem eg: getting the win handle and killing the win to remove it off the screen in my case. Cheers, Charlie I [Non-text portions of this message have been removed]
Re: [delphi-en] Re: Controlling Powerpoint from Delphi app
Hi, kc0fcp I wonder if this is a Delphi thing or a Windows thing. I have noticed that when any application losses focus, then the Windows are not updated. For example, if you have an active progress gauge and go and do something else, the gauge apparently stops. It does not restart even if the window gets focus, until the event is complete, when the gauge jumps to 100%. This is a new feature in XP. Changing the hardware accelerator does not help. In other words, I am suggesting that this is nothing to do with PowerPoint, that PowerPoint is making the new slides but that they are not displayed. You could check the Windows Task Manager and see if PowerPoint takes processing time every ten seconds (or whatever you photo change rate is). You could also tell by noticing which slide is shown after a freeze. Is it the next in sequence or an apparently random one caused by the intervening ones being created but not being shown? (To prove next in sequence you would need to do the test many times as this slide could also be selected randomly.) I have no suggestions for fixing this but think that you might be looking in the wrong place. Bobby Clarke kc0fcp wrote: Rob, Thanks for the reply. My program is not started by PPT, nor does it start PPT. The application is in a lobby kiosk. A PPT slide show runs in an infinite loop. Twice a day, my app is supposed to appear on top of the running PPT slide show and announce an event and show a countdown timer. When the countdown reaches 0, my app closes and disappears. My app is launched as a Scheduled Task. AFIK, Powerpoint knows nothing about my program. I don't know why the presentation pauses - it seems to be a built-in characteristic of PPT. I reviewed all the show setup options in PPT and didn't see anything about pausing for other windows, though. Thanks, Tim. --- In delphi-en@yahoogroups.com, Rob Kennedy [EMAIL PROTECTED] wrote: What's the relationship between PowerPoint and your program. Why does the presentation pause? Does PowerPoint even _know_ about your program? What does your program do? I'm guessing that either your program started PowerPoint, or PowerPoint started your program. Which is it? Is this a presentation that's supposed to advance automatically? -- Rob No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.15.26/598 - Release Date: 22/12/2006 15:22 [Non-text portions of this message have been removed]
Re: [delphi-en] Re: Controlling Powerpoint from Delphi app
Bobby Clarke wrote: I wonder if this is a Delphi thing or a Windows thing. It's neither. It's a PowerPoint thing. http://groups.google.com/groups?q=powerpoint+pauses+loses+focus I have noticed that when any application losses focus, then the Windows are not updated. For example, if you have an active progress gauge and go and do something else, the gauge apparently stops. It does not restart even if the window gets focus, until the event is complete, when the gauge jumps to 100%. This is a new feature in XP. Changing the hardware accelerator does not help. I've never noticed such behavior. Are you sure you're not using Windows 3.1? -- Rob
[delphi-en] Re: Controlling Powerpoint from Delphi app
Hi Charlie, I am facing a similar situation, where I write javascript codes through my application, that wil interact with Acrobat Reader or Viewer. My dilemna is that the Javascript is loaded only when Acrobat reader is started. So, I need to kill the Acrobat Reader process, and restart a new instance everytime I want to update the javascript codes. I really think that your program could help, if you don't mind sharing it with me. TIA. Emmanuel --- In delphi-en@yahoogroups.com, Charlie Chambers [EMAIL PROTECTED] wrote: - Original Message - kc0fcp wrote: AFIK, Powerpoint knows nothing about my program. I don't know why the presentation pauses - it seems to be a built-in characteristic of PPT. I reviewed all the show setup options in PPT and didn't see anything about pausing for other windows, though. Rob wrote: 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. . I have a program i can send to get the win type if you should need one. I've done similar code as Rob suggests to solve a similar problem eg: getting the win handle and killing the win to remove it off the screen in my case. Cheers, Charlie I [Non-text portions of this message have been removed]
Re: [delphi-en] Re: Controlling Powerpoint from Delphi app
Hi Emmanuel, I really think that your program could help, if you don't mind sharing it with me. TIA. I'm sending to you private mail box. I'll zip it up. I've put in several items: (1) exe to get running processes - visible and invisible - handles, Win classes, Win Title Thread ID (2) Code from my program - example (3) Unit code to send key messages If you have questions - feel free to write me. Cheers, Charlie [Non-text portions of this message have been removed]
Re: [delphi-en] Re: Controlling Powerpoint from Delphi app
Bobby Clarke wrote: Rob Kennedy wrote: Are you sure you're not using Windows 3.1? XP is only at SP2. v3.1 isn't out yet! Windows 3.1 was released over 14 years ago. :) -- Rob
[delphi-en] Re: Controlling Powerpoint from Delphi app
Rob, Thanks for the reply. My program is not started by PPT, nor does it start PPT. The application is in a lobby kiosk. A PPT slide show runs in an infinite loop. Twice a day, my app is supposed to appear on top of the running PPT slide show and announce an event and show a countdown timer. When the countdown reaches 0, my app closes and disappears. My app is launched as a Scheduled Task. AFIK, Powerpoint knows nothing about my program. I don't know why the presentation pauses - it seems to be a built-in characteristic of PPT. I reviewed all the show setup options in PPT and didn't see anything about pausing for other windows, though. Thanks, Tim. --- In delphi-en@yahoogroups.com, Rob Kennedy [EMAIL PROTECTED] wrote: What's the relationship between PowerPoint and your program. Why does the presentation pause? Does PowerPoint even _know_ about your program? What does your program do? I'm guessing that either your program started PowerPoint, or PowerPoint started your program. Which is it? Is this a presentation that's supposed to advance automatically? -- Rob