Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace System.Windows.Forms {
- /// <summary>
- /// Locks Window's Update with the LockWindowUpdate winapi
- /// </summary>
- public class LockWindow:IDisposable {
- [System.Runtime.InteropServices.DllImport("User32")]
- public static extern bool LockWindowUpdate(IntPtr hWndLock);
- #region static
- public static bool LockWindowUpdate(IWin32Window window) {
- return LockWindowUpdate(window.Handle);
- }
- public static bool LockWindowUpdate() {
- return LockWindowUpdate(IntPtr.Zero);
- }
- public static LockWindow Lock(IntPtr winHandle) {
- return new LockWindow(winHandle);
- }
- public static LockWindow Lock(IntPtr winHandle,bool lockwindow) {
- return new LockWindow(winHandle,lockwindow);
- }
- public static LockWindow Lock(IWin32Window window) {
- return new LockWindow(window);
- }
- #endregion
- readonly IntPtr _handle;
- bool _windowlocked;
- #region ctr
- public LockWindow(IntPtr winHandle)
- : this(winHandle,true) {
- }
- public LockWindow(IntPtr winHandle,bool lockwindow) {
- _windowlocked = false;
- _handle = winHandle;
- if(lockwindow)
- LockUpdate();
- }
- public LockWindow(IWin32Window window)
- : this(window.Handle) {
- }
- #endregion
- public bool LockUpdate() {
- if(!_windowlocked && _handle != IntPtr.Zero)
- _windowlocked = LockWindowUpdate(_handle);
- return _windowlocked;
- }
- public void UnLockUpdate() {
- if(_windowlocked && _handle != IntPtr.Zero)
- LockWindowUpdate(IntPtr.Zero);
- }
- #region IDisposable Pattern
- protected bool IsDisposed { get; private set; }
- public virtual void Dispose() {
- if(IsDisposed)
- throw new ObjectDisposedException(this.GetType().Name);
- try {
- this.Dispose(true);
- }
- finally {
- GC.SuppressFinalize(this);
- }
- }
- protected virtual void Dispose(bool disposing) {
- try {
- if(!IsDisposed) {
- if(disposing) {
- UnLockUpdate();
- }
- }
- }
- finally {
- this.IsDisposed = true;
- }
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment