Setting the transparency key on a powerpoint window RRS feed

  • Question

  • Hi,

    First of all, this question is not entirely related to office development, but this forum seems to be the most suitable place for this question. I am trying to create an application which is able to switch between multiple powerpoint presentations and also movies etc. The interface of this program is running on the primary monitor and powerpoint would be on the secondary monitor. To control powerpoint I am using the powerpoint automation library.

    Since it is necessary that the presentations are continuing while the powerpoint window doesn't have the focus I am using the "Browsed by an individual" slide show setting. To ensure that only the slide show is visible on the monitor I am using the SetParent function from the user32 library. This part of the program works fine. However I also want to be able to set a transparent color to the powerpoint window, this to make it possible to have for instance some text in the presentation as subtitles. 

    To set a transparent color I use the SetLayeredWindowAttributes function also from the user32 library. But it seems that powerpoint has problems handling a transparency key. When testing my program I noticed that setting the transparency key works fine when the Windows 7 basic theme is selected, but if windows aero is enabled the color is not transparent.

    During testing I also observed that when using the Spy++ utility that when I hovered the finder tool above the powerpoint window that suddenly the first slide of the presentation becomes visible and transparent with the correct transparent color. However, when changing the slide this effect is gone and when reusing the finder tool the first slide becomes transparent and visible again, even when the actual selected slide is not the first slide.

    To resolve this issue I tried to remove the CS_OWNDC window class style from the powerpoint window since that class style is not compatible with the WS_EX_LAYERED window style according to the documentation (I was able to remove this class by injecting code into the powerpoint process which calls the SetClassLongPtr function). However that got me stuck with a blue screen of death when exiting my application (when my application was still running I did not notice any difference with or without the CS_OWNDC window class). 

    To make sure that all the calls to SetParent etc. are not part of the problem I stripped down my code to the following:

    private static void SetWindowTransparencyKey(IntPtr HWND, COLORREF TransparentColor)
       // Add WS_EX_LAYERED to the window style
       uint OldWindowStyle = (uint)GetWindowLongPtr(HWND, (int)GWL.GWL_EXSTYLE);
       uint NewWindowStyle = OldWindowStyle | (uint)WindowStyles.WS_EX_LAYERED;
       SetWindowLongPtr(HWND, (int)GWL.GWL_EXSTYLE, (IntPtr)NewWindowStyle);
       // Set the transparent color
       SetLayeredWindowAttributes(HWND, TransparentColor.ColorDWORD, 255, LWA_COLORKEY);

    When I use this code directly on the main window of a manually opened powerpoint instance running in the "browsed by an individual" mode all the observations stated above stay the same. This means that somehow there is something very strange happening within powerpoint which is able to disable the transparency key when aero is used. Interesting is that when exiting the "browsed by an individual" mode and returning to the edit mode the transprancy key suddenly is working. 

    So basically my question boils down to what I can do to get a transparency key working on a powerpoint window running in "browsed by an individual" mode using aero. Any help would be appreciated!

    Kind regards,
    Wednesday, October 16, 2013 8:27 PM

All replies

  • Hi,

    I failed to reproduce your issue on my computer.

    My code is below and please correct me if I have any misunderstanding.

    SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) ^ WS_EX_LAYERED);
    SetLayeredWindowAttributes(hWnd, 0, 100, LWA_ALPHA);

    I suggest you to refer article about troubleshooting about the aero problems

    Thanks & Regards,

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 17, 2013 1:07 PM
  • Hi,

    Thanks for checking out the problem. The code your testing is setting the LWA_ALPHA, but the problem exist when using the LWA_COLORKEY. The easiest way to reproduce the problem is to create a new presentation with a couple of slides with some text and a white background and then you run the presentation (in the "browsed by an individual mode") and try to set the LWA_COLORKEY on white. Probably you will first see the desired effect (the white background is transparent), but when changing a slide this effect is gone. 

    I hope you have enough information to reproduce the problem now, this issue has been tested on multiple systems and all the systems show the same problems. 

    Kind regards,

    Thursday, October 17, 2013 2:01 PM