示例#1
0
        static public void UnProtect(IntPtr hWnd)
        {
            if (NativeCode.IsWindow(hWnd))
            {
                try
                {
                    if ((int)NativeCode.GetProp(hWnd, "protect_affinity") == 1)
                    {
                        NativeCode.SetWindowDisplayAffinity(hWnd, 0);
                        NativeCode.RemoveProp(hWnd, "protect_affinity");
                    }
                }
                catch (System.Exception ex)
                {
                    LogFile.Error("exception in UnProtect() while removing affinity:", ex);
                }


                try
                {
                    if ((int)NativeCode.GetProp(hWnd, "protect_layer_added") == 1)
                    {
                        NativeCode.SetWindowLong(hWnd, NativeCode.GWL_EXSTYLE, NativeCode.GetWindowLong(hWnd, NativeCode.GWL_EXSTYLE) & (~NativeCode.WS_EX_LAYERED));
                        NativeCode.RemoveProp(hWnd, "protect_layer_added");
                    }
                }
                catch (System.Exception ex)
                {
                    LogFile.Error("exception in UnProtect() while removing layered attribute:", ex);
                }


                try
                {
                    if ((int)NativeCode.GetProp(hWnd, "protect_mag") == 1)
                    {
                        if (NativeCode.IsWindow(NativeCode.GetProp(hWnd, "protect_mag_hwnd")))
                        {
                            NativeCode.DestroyWindow(NativeCode.GetProp(hWnd, "protect_mag_hwnd"));
                        }
                        NativeCode.RemoveProp(hWnd, "protect_mag");
                        NativeCode.RemoveProp(hWnd, "protect_mag_hwnd");
                    }
                }
                catch (System.Exception ex)
                {
                    LogFile.Error("exception in UnProtect() while removing magnification component:", ex);
                }
            }
            else
            {
                LogFile.Error("no vailid window handle forwarded to UnProtect()");
            }
        }
示例#2
0
 public void ToggleFullscreen()
 {
     if (isFullscreen)
     {
         try
         {
             if (Program.IsProtected)
             {
                 //Protected window cannot set style with FormBorderStyle.Sizable, because this seems to remove layered style!
                 NativeCode.SetWindowLong(this.Handle, NativeCode.GWL_STYLE, NativeCode.WS_VISIBLE | NativeCode.WS_OVERLAPPEDWINDOW | NativeCode.WS_MAXIMIZE);
                 NativeCode.ShowWindow(this.Handle, NativeCode.SW_SHOWNORMAL);
                 //this.WindowState = lastState;
                 this.Invalidate();
                 this.Refresh();
                 //NativeCode.RedrawWindow(this.Handle, IntPtr.Zero, IntPtr.Zero, NativeCode.RDW_FRAME | NativeCode.RDW_UPDATENOW | NativeCode.RDW_INVALIDATE);
                 //NativeCode.UpdateWindow(this.Handle);
                 isFullscreen = false;
             }
             else
             {
                 this.FormBorderStyle = FormBorderStyle.Sizable;
                 this.WindowState     = lastState;
                 isFullscreen         = false;
             }
         }
         catch (System.Exception ex)
         {
             LogFile.Error("Error in ToggleScreen() 1", ex);
         }
     }
     else
     {
         try
         {
             if (Program.IsProtected)
             {
                 //Protected window cannot set style with FormBorderStyle.Sizable, because this seems to remove layered style!
                 NativeCode.SetWindowLong(this.Handle, NativeCode.GWL_STYLE, NativeCode.WS_VISIBLE | NativeCode.WS_POPUP);
                 NativeCode.ShowWindow(this.Handle, NativeCode.SW_SHOWNORMAL); //Makes sure that the taskbar is not visible!
                 NativeCode.ShowWindow(this.Handle, NativeCode.SW_SHOWMAXIMIZED);
                 this.Invalidate();
                 this.Refresh();
                 //NativeCode.RedrawWindow(this.Handle, IntPtr.Zero, IntPtr.Zero, NativeCode.RDW_FRAME | NativeCode.RDW_UPDATENOW | NativeCode.RDW_INVALIDATE);
                 //NativeCode.UpdateWindow(this.Handle);
                 isFullscreen = true;
             }
             else
             {
                 lastState            = this.WindowState;
                 this.FormBorderStyle = FormBorderStyle.None;
                 this.WindowState     = FormWindowState.Normal;//Makes sure that the taskbar is not visible!
                 this.WindowState     = FormWindowState.Maximized;
                 isFullscreen         = true;
             }
         }
         catch (System.Exception ex)
         {
             LogFile.Error("Error in ToggleScreen() 2", ex);
         }
     }
 }
示例#3
0
        static public void Protect(IntPtr hWnd)
        {
            bool isProtected = false;

            if (NativeCode.IsWindow(hWnd))
            {
                if (IsDWMEnabled())
                {
                    try
                    {
                        isProtected = NativeCode.SetWindowDisplayAffinity(hWnd, NativeCode.WDA_MONITOR);
                        if (isProtected)
                        {
                            NativeCode.SetProp(hWnd, "protect_affinity", (IntPtr)1);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        //Possibly Windows Vista
                        LogFile.Warn("exception in Protect() while setting affinity:" + ex.Message);
                    }
                }

                if (isProtected == false)
                {
                    try
                    {
                        //Disable DWM, that it cannot be enabled while the application is running
                        NativeCode.DwmEnableComposition(NativeCode.DWM_EC_DISABLECOMPOSITION);
                        dwmDisabled = true;
                    }
                    catch (System.Exception ex)
                    {
                        //Possibly Windows XP...
                        LogFile.Warn("exception in Protect() while disabling DWM:" + ex.Message);
                    }


                    try
                    {
                        if ((NativeCode.GetWindowLong(hWnd, NativeCode.GWL_EXSTYLE) & NativeCode.WS_EX_LAYERED) == 0)
                        {
                            NativeCode.SetProp(hWnd, "protect_layer_added", (IntPtr)1);
                        }
                        NativeCode.SetWindowLong(hWnd, NativeCode.GWL_EXSTYLE, NativeCode.GetWindowLong(hWnd, NativeCode.GWL_EXSTYLE) | NativeCode.WS_EX_LAYERED);
                        NativeCode.SetLayeredWindowAttributes(hWnd, 0, 255, NativeCode.LWA_ALPHA);
                    }
                    catch (System.Exception ex)
                    {
                        LogFile.Error("exception in Protect() while setting layered window:", ex);
                    }


                    try
                    {
                        if (magInit)
                        {
                            IntPtr magWnd = NativeCode.CreateWindow(0, NativeCode.WC_MAGNIFIER, "", NativeCode.WS_CHILD, 0, 0, 1, 1, hWnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                            NativeCode.SetProp(hWnd, "protect_mag", (IntPtr)1);
                            NativeCode.SetProp(hWnd, "protect_mag_hwnd", magWnd);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        LogFile.Error("exception in Protect() while creating maginification window:", ex);
                    }


                    try
                    {
                        NativeCode.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero, NativeCode.RDW_FRAME | NativeCode.RDW_UPDATENOW | NativeCode.RDW_INVALIDATE);
                        NativeCode.UpdateWindow(hWnd);
                    }
                    catch (System.Exception ex)
                    {
                        LogFile.Error("exception in Protect() while refreshing window:", ex);
                    }
                }
            }
            else
            {
                LogFile.Error("no vailid window handle forwarded to Protect()");
            }
        }