예제 #1
0
        public FileView(FileMapping fileMapping, uint desiredAccess, int numberOfBytesToMap)
        {
            this._Handle = NativeMethods.MapViewOfFile(new HandleRef(fileMapping, fileMapping.Handle), desiredAccess, 0, 0, new IntPtr(numberOfBytesToMap));

            if (this._Handle == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }
예제 #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && (Interlocked.Exchange(ref this._Disposed, 1) == 0))
            {
                if (this._MouseHook != null)
                {
                    this._MouseHook.Dispose();
                    this._MouseHook = null;
                }

                if (this._KeyboardHook != null)
                {
                    this._KeyboardHook.Dispose();
                    this._KeyboardHook = null;
                }

                if (this._InstanceId != null)
                {
                    bool IsFirstInstance = this._InstanceId.IsNew;

                    this._InstanceId.Dispose();
                    this._InstanceId = null;

                    if (IsFirstInstance)
                    {
                        Application.RemoveMessageFilter(this);

                        if (this._SelectedWindow != IntPtr.Zero)
                        {
                            RedrawWindow(this._SelectedWindow);
                            this._SelectedWindow = IntPtr.Zero;
                        }
                    }
                }

                if ((Interlocked.Exchange(ref this._SettingsFormState, FORM_STATE_DISPOSED) == FORM_STATE_READY) && (this._SettingsForm != IntPtr.Zero))
                {
                    NativeMethods.PostMessageW(new HandleRef(this, this._SettingsForm), NativeMethods.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    this._SettingsForm = IntPtr.Zero;
                }
            }

            base.Dispose(disposing);
        }
예제 #3
0
        private ApplicationManager(string[] e)
        {

#warning move to StartApplication?
#if !DEBUG
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException, false);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.OnUnhandledException);
#endif
            
            this._InstanceId = new FileMapping(@"Local\Goletas.ScreenCapture");

            if (this._InstanceId.IsNew)
            {
                Application.SetCompatibleTextRenderingDefault(false);

                if ((Configuration.Current.Settings == null) || (Configuration.Current.FileTypes == null))
                {
                    throw new InvalidOperationException();
                }

                if (!IsBackgroundMode(e))
                {
                    this.ShowSettingsForm();
                }

                Application.AddMessageFilter(this);
                this._InstanceId.Write(NativeMethods.GetCurrentThreadId());

                this._KeyboardHook = new Hook(new LowLevelKeyboardProc(this.OnKeyboardEvent));
                this._MouseHook = new Hook(new LowLevelMouseProc(this.OnMouseEvent));
            }
        }