0

I want to show pictureBox infront of the VLC player while it in fullscreen mode in Windows Form Application.

 `if(axVLCPlugin21.video.fullscreen == true)
        {
            Debug.WriteLine("Is fullscreen");
            pictureBox2.BringToFront();
            pictureBox2.Focus();
            pictureBox2.Show();
        }`

I tried this method and another method (Draw semi transparent overlay image all over the windows form having some controls) which use Windows Form to pop out it but it only appear behind of the fullscreen.

If anyone willing to share their solution will be appreciate.

Jin Wei
  • 1
  • 6
  • This is too specific a question for anyone to help you without doing the work to get a VLC ActiveX plugin showing in winforms, playing a video, and then switching to fullscreen. – Warty Apr 26 '18 at 02:07
  • When you tried the alternative methods, what happened? Why weren't they good enough? Have you tried creating a new form, `form.TopMost = true`, putting the picture box there? What happens then? – Warty Apr 26 '18 at 02:08
  • @Warty yup I tried with the `from.TopMost = true` yet still the same it only appear behind the fullscreen. – Jin Wei Apr 26 '18 at 02:13
  • That is because full screen isn't just a borderless window, just like games hijack the entire display... – Ron Beyer Apr 26 '18 at 02:17
  • @RonBeyer ya it hijack the entire display and I couldn't find any method to hijack back. – Jin Wei Apr 26 '18 at 02:23
  • Using a Form as overlay, if you set `.SetTopLevel(true);` `.TopMost = true;` it will stay on top of a VLC Player in full screen view (F11). – Jimi Apr 26 '18 at 04:53
  • @Jimi It does stay on top of the form but seems didn't work for me because I using `axVLCPlugin21.video.fullscreen = true;` and the VLC full screen still cover the pictureBox. – Jin Wei Apr 26 '18 at 05:12
  • I don't have the plug-in. I've tested it with the VLC application in full screen mode. My overlay stays on top of it, because it's completely transparent and untouchable. If I have the time, I'll test it with the plug-in. I'll let you know. – Jimi Apr 26 '18 at 05:16
  • @Jimi Thanks and will look forward to your solution. – Jin Wei Apr 26 '18 at 05:19
  • I've tested the VLC PlugIn. There's really no problem at all in bringing an overlay form on top of it when in full screen. The only problem you might have is to make it stay there, without using SetWindowPosition() with HWND_TOPMOST, because it's annoying for all other processes. What I usually do, is hooking the overlay to a process or one of its children. [You can see an example here](https://stackoverflow.com/questions/48767318/move-window-when-external-applications-window-moves?answertab=active#tab-top). See if it can give you some hints. The overlay class, I could post it to PasteBin. – Jimi Apr 26 '18 at 07:50
  • Hi @Jimi your solution from link which works brilliant that able to show picture box front of the VLC fullscreen with charm. Would you mind to share some thought on control the pictureBox position I know like bit out of topic. – Jin Wei Apr 27 '18 at 05:06

1 Answers1

0

Thanks to @Jimi who suggest me to use the hook method and it working nice and below is my code hope can help others.

public partial class Test : Form
{
    private IntPtr testPic;
    private IntPtr hWinEventHook;
    private Process Target;
    private WinApi.RECT rect = new WinApi.RECT();
    protected Hook.WinEventDelegate WinEventDelegate;

    public Test(Form toCover, AxAXVLC.AxVLCPlugin2 ply)
    {
        InitializeComponent();
        WinEventDelegate = new Hook.WinEventDelegate(WinEventCallback);

        this.SetTopLevel(true);
        this.TopMost = true;
        this.ControlBox = false;
        this.ShowInTaskbar = false;
        this.StartPosition = FormStartPosition.Manual;
        this.AutoScaleMode = AutoScaleMode.None;
        this.Show(toCover);
        toCover.Focus();

        try
        {
            Target = Process.GetProcessesByName("TestPlayer").FirstOrDefault(p => p != null);
            if (Target != null)
            {
                testPic = Target.MainWindowHandle;
                uint TargetThreadId = Hook.GetWindowThread(testPic);

                if (testPic != IntPtr.Zero)
                {

                    hWinEventHook = Hook.WinEventHookOne(Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE,
                                                         WinEventDelegate,
                                                         (uint)Target.Id,
                                                         TargetThreadId);
                    rect = Hook.GetWindowRect(testPic);

                }

                if (ply.video.fullscreen == true) 
                {
                    Debug.WriteLine("yes is ");
                    this.WindowState = FormWindowState.Maximized;
                }
            }

        }
        catch (Exception e)
        {
            throw e;
        }
    }

    protected void WinEventCallback(IntPtr hWinEventHook,
                                Hook.SWEH_Events eventType,
                                IntPtr hWnd,
                                Hook.SWEH_ObjectId idObject,
                                long idChild,
                                uint dwEventThread,
                                uint dwmsEventTime)
    {
        if (hWnd == testPic &&
            eventType == Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE &&
            idObject == (Hook.SWEH_ObjectId)Hook.SWEH_CHILDID_SELF)
        {
            WinApi.RECT rect = Hook.GetWindowRect(hWnd);
            //this.Location = new System.Drawing.Point(rect.Left, rect.Top);
        }
    }

    private void Overlay_FormClosing(object sender, FormClosingEventArgs e)
    {
        Hook.WinEventUnhook(hWinEventHook);
    }

    private void Overlay_FormShown(object sender, EventArgs e)
    {

        this.BeginInvoke(new Action(() => this.Owner.Activate()))
        this.Location = toCover.PointToScreen(System.Drawing.Point.Empty);
        if (Target == null)
        {
            this.Hide();
            MessageBox.Show("Player not found!", "Target Missing", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            this.Close();
        }
    }

    private const int DWMWA_TRANSITIONS_FORCEDISABLED = 3;
    [DllImport("dwmapi.dll")]
    private static extern int DwmSetWindowAttribute(IntPtr hWnd, int attr, ref int value, int attrLen);

    private void Test_load(object sender, EventArgs e)
    {
        this.CenterToScreen();
        this.Location = new System.Drawing.Point(this.Location.X, this.Location.Y); 
    }

    private void closeFullScreen_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }

}
Jin Wei
  • 1
  • 6