Exemplo n.º 1
0
        /// <summary>
        ///     Corrige o cursor para o valor original do sistema operacional.
        /// </summary>
        /// <param name="cursor">Cursor.</param>
        public static void FixesForTheOperatingSystemCursor(this Cursor cursor)
        {
            if (!CursorsMatchingValues.ContainsKey(cursor))
            {
                throw new WrongArgumentException(
                          nameof(WindowsApiExtensions),
                          nameof(FixesForTheOperatingSystemCursor),
                          nameof(cursor));
            }

            var cursorsType = typeof(Cursors);

            var cursorsProperty = cursorsType
                                  .GetProperties(BindingFlags.Static | BindingFlags.Public)
                                  .Single(a => a.GetValue(null).Equals(cursor));

            var cursorsFieldName = cursorsProperty.Name[0].ToString().ToLower() + cursorsProperty.Name.Substring(1);

            var cursorsField = cursorsType.GetField(cursorsFieldName, BindingFlags.Static | BindingFlags.NonPublic)
                               ?? throw new ThisWillNeverOccurException();

            var operatingSystemCursorName   = CursorsMatchingValues[cursor];
            var operatingSystemCursorHandle = WindowsApi.LoadCursor(IntPtr.Zero, operatingSystemCursorName);
            var operatingSystemCursor       = new Cursor(operatingSystemCursorHandle);

            cursorsField.SetValue(null, operatingSystemCursor);
        }
Exemplo n.º 2
0
        // Experimental function to set the window background to use Windows 10 acrylic - this part of the win api is poorly documented
        public static void EnableAcrylic(Window window)
        {
            var handle = new WindowInteropHelper(window).EnsureHandle();

            var accent = new WindowsApi.AccentPolicy();

            accent.GradientColor = 0x01000000;

            accent.AccentState = WindowsApi.AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND;

            var accentStructSize = Marshal.SizeOf(accent);

            var accentPtr = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);

            var data = new WindowsApi.WindowCompositionAttributeData();

            data.Attribute  = WindowsApi.WindowCompositionAttribute.WCA_ACCENT_POLICY;
            data.SizeOfData = accentStructSize;
            data.Data       = accentPtr;

            WindowsApi.SetWindowCompositionAttribute(handle, ref data);

            Marshal.FreeHGlobal(accentPtr);
        }
Exemplo n.º 3
0
        static StringDictionary GetEnvironmentVariableDictionary(IntPtr hProcess)
        {
            IntPtr penv = GetPenv(hProcess);

            int dataSize;

            if (!HasReadAccess(hProcess, penv, out dataSize))
            {
                throw new Exception("Unable to read environment block.");
            }

            const int maxEnvSize = 32767;

            if (dataSize > maxEnvSize)
            {
                dataSize = maxEnvSize;
            }

            var  envData = new byte[dataSize];
            var  res_len = IntPtr.Zero;
            bool b       = WindowsApi.ReadProcessMemory(
                hProcess,
                penv,
                envData,
                new IntPtr(dataSize),
                ref res_len);

            if (!b || (int)res_len != dataSize)
            {
                throw new Exception("Unable to read environment block data.");
            }

            return(ParseEnviromentVariables(envData));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets or sets the current value of filter keys setting.
        /// </summary>
        /// <param name="newvalue"></param>
        /// <returns></returns>
        public static bool KeyRepeat(bool?newvalue = null)
        {
            WindowsApi.FILTERKEYS filterKeys = new WindowsApi.FILTERKEYS
            {
                cbSize = Marshal.SizeOf <WindowsApi.FILTERKEYS>()
            };

            WindowsApi.SystemParametersInfoFilterKeys(
                WindowsApi.SPI_GETFILTERKEYS, filterKeys.cbSize, ref filterKeys, 0);

            if (newvalue is not null)
            {
                if (newvalue == true)
                {
                    filterKeys.dwFlags |= WindowsApi.FILTERKEYS.FKF_FILTERKEYSON;
                }
                else
                {
                    filterKeys.dwFlags &= ~WindowsApi.FILTERKEYS.FKF_FILTERKEYSON;
                }

                WindowsApi.SystemParametersInfoFilterKeys(
                    WindowsApi.SPI_SETFILTERKEYS, filterKeys.cbSize, ref filterKeys, 3);
            }

            return((filterKeys.dwFlags & WindowsApi.FILTERKEYS.FKF_FILTERKEYSON)
                   == WindowsApi.FILTERKEYS.FKF_FILTERKEYSON);
        }
Exemplo n.º 5
0
        public static ProcessorArchitecture?GetProcessorArchitecture()
        {
            // var cSystemInfo = new WindowsApi.SYSTEM_INFO();
            WindowsApi.SYSTEM_INFO cSystemInfo;
            WindowsApi.GetSystemInfo(out cSystemInfo);

            switch (cSystemInfo.dummyUnion.DUMMYSTRUCTNAME.wProcessorArchitecture)
            {
            case (UInt16)WindowsApi.ProcessorArchitecture.IA32:
                return(ProcessorArchitecture.X86);

            case (UInt16)WindowsApi.ProcessorArchitecture.ARM:
                return(ProcessorArchitecture.Arm32);

            //case 6: // PROCESSOR_ARCHITECTURE_IA64
            //    return ProcessorArchitecture.Itanium;
            case (UInt16)WindowsApi.ProcessorArchitecture.AMD64:
                return(ProcessorArchitecture.X64);

            //case 11:
            //    return ProcessorArchitecture.Neutral;
            case (UInt16)WindowsApi.ProcessorArchitecture.ARM64:
                return(ProcessorArchitecture.Arm64);

            //case 14:
            //    // NOTE: in our tests, x86 emulation on ARM64 just returned "PROCESSOR_ARCHITECTURE_INTEL" (0)
            //    return ProcessorArchitecture.X86;
            case (UInt16)WindowsApi.ProcessorArchitecture.UNKNOWN:
            default:
                return(null);
            }
        }
Exemplo n.º 6
0
        private static WindowsApi.TOKEN_ELEVATION_TYPE GetProcessTokenElevationType()
        {
            IntPtr hToken = IntPtr.Zero;

            try
            {
                if (!WindowsApi.OpenProcessToken(WindowsApi.GetCurrentProcess(), WindowsApi.TOKEN_QUERY, ref hToken))
                {
                    throw new Win32Exception(WindowsApi.GetLastError());
                }

                WindowsApi.TOKEN_ELEVATION_TYPE elevationType = WindowsApi.TOKEN_ELEVATION_TYPE.TokenElevationTypeDefault;
                uint dwSize;

                if (!WindowsApi.GetTokenInformation(hToken, WindowsApi.TOKEN_INFORMATION_CLASS.TokenElevationType, ref elevationType, (uint)sizeof(WindowsApi.TOKEN_ELEVATION_TYPE), out dwSize))
                {
                    throw new Win32Exception(WindowsApi.GetLastError());
                }

                return(elevationType);
            }
            finally
            {
                if (hToken != IntPtr.Zero)
                {
                    WindowsApi.CloseHandle(hToken);
                }
            }
        }
        public Task StartAsync(Tool tool)
        {
            IntPtr desktopHandle = WindowsUtility.CreateDesktop(DesktopName);

            // embrace the madness -- it seems Windows always wants exactly one instance of "ctfmon.exe" in the new desktop
            var ctfmonStartInfo = new ProcessStartInfo {
                FileName = "ctfmon.exe", WorkingDirectory = "."
            };

            WindowsApi.PROCESS_INFORMATION ctfmonProcess = WindowsUtility.CreateProcess(ctfmonStartInfo, DesktopName);
            AssociateWithJob(ctfmonProcess, false);

            // start the desired process
            var arguments = string.Join(" ", tool.Settings.GetArguments(tool));
            var startInfo = new ProcessStartInfo
            {
                FileName         = tool.ExecutablePath,
                Arguments        = arguments,
                WorkingDirectory = tool.WorkingDirectory
            };

            WindowsApi.PROCESS_INFORMATION targetProcess = WindowsUtility.CreateProcess(startInfo, DesktopName);
            AssociateWithJob(targetProcess, true);

            WindowsApi.CloseDesktop(desktopHandle);
            return(Task.FromResult((object)null));
        }
Exemplo n.º 8
0
 public static void HandleRunningInstance(Process instance)
 {
     //Make   sure   the   window   is   not   minimized   or   maximized
     WindowsApi.ShowWindowAsync(instance.MainWindowHandle, WsShownormal);
     //Set   the   real   intance   to   foreground   window
     WindowsApi.SetForegroundWindow(instance.MainWindowHandle);
 }
        private void Init(Object sender, EventArgs e)
        {
            var invoke = WindowsApi.GetDC(IntPtr.Zero);

            this.ScreenHDc      = invoke.Result;
            this.ColorConverter = new ColorConverter();
        }
Exemplo n.º 10
0
        private static TextMetric GetTextMetrics(IntPtr hwnd, Font font)
        {
            if (Kohl.Framework.Info.MachineInfo.IsUnixOrMac)
            {
                Kohl.Framework.Logging.Log.Fatal("Screen caputure is only supported on Windows at the moment.");
                return(new TextMetric());
            }

            IntPtr hdc = WindowsApi.GetWindowDC(hwnd);

            TextMetric textMetric;
            IntPtr     hFont = font.ToHfont();

            try
            {
                IntPtr hFontPrevious = WindowsApi.SelectObject(hdc, hFont);
                WindowsApi.GetTextMetrics(hdc, out textMetric);
                WindowsApi.SelectObject(hdc, hFontPrevious);
            }
            finally
            {
                WindowsApi.ReleaseDC(hwnd, hdc);
                WindowsApi.DeleteObject(hFont);
            }

            return(textMetric);
        }
Exemplo n.º 11
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="virtualKey">按键</param>
 /// <param name="flags">按键标志</param>
 /// <param name="hEvent">热键事件</param>
 internal HotkeyHelper(uint virtualKey, HotkeyFlags flags, HotKeyEventHandler hEvent)
 {
     Id           = WindowsApi.GlobalAddAtom(Guid.NewGuid().ToString());
     VirtualKey   = virtualKey;
     Flags        = flags;
     HotkeyActive = hEvent;
 }
Exemplo n.º 12
0
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormMessageBox_Load(object sender, EventArgs e)
        {
            _lblTitle.Text = "提示";
            if (_formMode == LoadMode.Error)
            {
                _lblTitle.Text = "错误";
                //this.plShow.BackgroundImage = global::CommonApp.Properties.Resources.error;    // 更换背景
            }
            else if (_formMode == LoadMode.Warning)
            {
                _lblTitle.Text = "警告";
                //this.plShow.BackgroundImage = global::CommonApp.Properties.Resources.warning;  // 更换背景
            }
            else
            {
                //this.plShow.BackgroundImage = global::CommonApp.Properties.Resources.Prompt;   // 更换背景
            }
            //this.lblMessage.Text = ShowMessage;
            int width  = Screen.PrimaryScreen.Bounds.Width;
            int height = Screen.PrimaryScreen.Bounds.Height;
            int top    = height - 35 - Height;
            int left   = width - Width - 5;

            Top     = top;
            Left    = left;
            TopMost = true;
            WindowsApi.AnimateWindow(Handle, 500, WindowsApi.AnimateWindowState.AwSlide + WindowsApi.AnimateWindowState.AwVerNegative);//开始窗体动画
            ShowInTaskbar        = false;
            _timerClose.Interval = 4000;
            _timerClose.Tick    += new EventHandler(Timer_Close_Tick);
            _timerClose.Start();
        }
Exemplo n.º 13
0
        // --------------------------------------------------------------------
        // ウィンドウを最前面に出す(必要に応じて)
        // --------------------------------------------------------------------
        private void TopMostIfNeeded()
        {
            if (!Visible)
            {
                return;
            }

            lock (mCommentInfosLock)
            {
                if (mCommentInfos.Count == 0)
                {
                    return;
                }
            }

            // MPC-BE のフルスクリーンは通常の最大化とは異なり、このフォームの TopMost が効かない
            // MPC-BE が最前面に来ている時は、このフォームを最前面に持って行く必要がある
            // GetForegroundWindow() はマルチディスプレイに関係なく最前面を報告するので、
            // ディスプレイ 2 の最前面が MPC-BE でも、ディスプレイ 1 に他のアプリがあってそれが最前面ならそれを報告する
            // 従って、MPC-BE が当該ディスプレイで最前面かどうか判定不能
            // そこで、このフォームが最前面でない場合は常に最前面に出すことにする
            // タスクスイッチなどシステム系が最前面になっている場合にこのフォームを最前面にしても、今のところ問題ない模様
            IntPtr aFGHandle = WindowsApi.GetForegroundWindow();

            if (aFGHandle != Handle)
            {
                WindowsApi.BringWindowToTop(Handle);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        ///     Obtem o nome da janela.
        /// </summary>
        /// <param name="hWnd">Handle da janela.</param>
        /// <returns>Texto.</returns>
        public static string GetWindowText(this IntPtr hWnd)
        {
            var text = new StringBuilder(255);

            WindowsApi.GetWindowText(hWnd, text, text.Capacity);
            return(text.ToString());
        }
Exemplo n.º 15
0
        public Rect GetForegroundRect()
        {
            var rct = new Rect();

            WindowsApi.GetWindowRect(WindowsApi.GetForegroundWindow(), ref rct);
            return(rct);
        }
 private void Release(Object sender, FormClosingEventArgs e)
 {
     if (this.ScreenHDc != IntPtr.Zero)
     {
         WindowsApi.ReleaseDC(this.Handle, this.ScreenHDc);
     }
 }
Exemplo n.º 17
0
        private void SetForegroundPos(int left, int top, int right, int bottom)
        {
            int w = right - left;
            int h = bottom - top;

            WindowsApi.SetWindowPos(WindowsApi.GetForegroundWindow(), IntPtr.Zero, left, top, w, h, 4);
        }
        private void _timerCursorPoint_Tick(Object sender, EventArgs e)
        {
            this._timerCursorPoint.Enabled = false;

            switch (this.PickerState)
            {
            //当处于选取状态时,才跟随鼠标并获取颜色信息
            case ColorPickerState.Picking:
            {
                Point cursorPos = Form.MousePosition;
                this.ShowMousePoint(cursorPos);
                if (IntPtr.Zero != this.ScreenHDc)
                {
                    var invoke = WindowsApi.GetPixel(this.ScreenHDc, cursorPos.X, cursorPos.Y);
                    if (invoke.Success)
                    {
                        Color color = invoke.Result.Value;
                        this.ShowColor(color);
                    }
                }
                this._timerCursorPoint.Enabled = true;
            }
            break;

            default: break;
            }
        }
        public AdcsTemplate DiscoverTemplate(CipherAlgorithm cipher, WindowsApi api, KeyUsage keyUsage)
        {
            Expression <Func <AdcsTemplate, bool> > query = template => template.Cipher == cipher && template.WindowsApi == api && template.KeyUsage.ToString() == keyUsage.ToString();
            AdcsTemplate results = configurationRepository.Get <AdcsTemplate>(query).First();

            return(results);
        }
        static bool _TryReadIntPtrWow64(IntPtr hProcess, long ptr, out long readPtr)
        {
            bool result;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                int  dataSize = sizeof(long);
                var  data     = Marshal.AllocHGlobal(dataSize);
                long res_len  = 0;
                int  status   = WindowsApi.NtWow64ReadVirtualMemory64(
                    hProcess,
                    ptr,
                    data,
                    dataSize,
                    ref res_len);
                readPtr = Marshal.ReadInt64(data);
                Marshal.FreeHGlobal(data);
                if (status != WindowsApi.STATUS_SUCCESS || res_len != dataSize)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
        public void Stop()
        {
            if (_jobHandle != IntPtr.Zero)
            {
                lock (_jobHandleLock)
                {
                    if (_jobHandle != IntPtr.Zero)
                    {
                        // terminate the job
                        if (!WindowsApi.TerminateJobObject(_jobHandle, 0))
                        {
                            throw new TorSharpException($"Unable to terminate the job object. Error: {WindowsUtility.GetLastErrorMessage()}.");
                        }

                        // wait for all jobs to complete
                        lock (_processIdsLock)
                        {
                            while (_processIds.Any())
                            {
                                if (Process.GetProcesses().All(p => p.Id != _processIds[0]))
                                {
                                    _processIds.RemoveAt(0);
                                }
                            }
                        }

                        _jobHandle = IntPtr.Zero;
                    }
                }
            }
        }
 static UniPtr _GetPeb64(IntPtr hProcess)
 {
     if (Environment.Is64BitProcess)
     {
         return(_GetPebNative(hProcess));
     }
     else
     {
         // Get PEB via WOW64 API.
         var pbi     = new WindowsApi.PROCESS_BASIC_INFORMATION_WOW64();
         int res_len = 0;
         int pbiSize = Marshal.SizeOf(pbi);
         int status  = WindowsApi.NtWow64QueryInformationProcess64(
             hProcess,
             WindowsApi.ProcessBasicInformation,
             ref pbi,
             pbiSize,
             ref res_len);
         if (res_len != pbiSize)
         {
             throw new Exception("Unable to query process information.");
         }
         return(new UniPtr(pbi.PebBaseAddress));
     }
 }
Exemplo n.º 23
0
 protected virtual void SendMessageToParent(Int32 msg, Int32 wParam = 0, Int32 lParam = 0)
 {
     if (this.Parent != null)
     {
         WindowsApi.SendMessage(this.Parent.Handle, msg, wParam, lParam);
     }
 }
        static bool _HasReadAccessWow64(IntPtr hProcess, long address, out int size)
        {
            size = 0;

            WindowsApi.MEMORY_BASIC_INFORMATION_WOW64 memInfo;
            var       memInfoType   = typeof(WindowsApi.MEMORY_BASIC_INFORMATION_WOW64);
            int       memInfoLength = Marshal.SizeOf(memInfoType);
            const int memInfoAlign  = 8;

            long resultLength = 0;
            int  result;

            IntPtr hMemInfo = Marshal.AllocHGlobal(memInfoLength + memInfoAlign * 2);

            try
            {
                // Align to 64 bits.
                IntPtr hMemInfoAligned = new IntPtr(hMemInfo.ToInt64() & ~(memInfoAlign - 1L));

                result = WindowsApi.NtWow64QueryVirtualMemory64(
                    hProcess,
                    address,
                    WindowsApi.MEMORY_INFORMATION_CLASS.MemoryBasicInformation,
                    hMemInfoAligned,
                    memInfoLength,
                    ref resultLength);

                memInfo = (WindowsApi.MEMORY_BASIC_INFORMATION_WOW64)Marshal.PtrToStructure(hMemInfoAligned, memInfoType);
            }
            finally
            {
                Marshal.FreeHGlobal(hMemInfo);
            }

            if (result != WindowsApi.STATUS_SUCCESS)
            {
                return(false);
            }

            if (memInfo.Protect == WindowsApi.PAGE_NOACCESS || memInfo.Protect == WindowsApi.PAGE_EXECUTE)
            {
                return(false);
            }

            try
            {
                size = Convert.ToInt32(memInfo.RegionSize - (address - memInfo.BaseAddress));
            }
            catch (OverflowException)
            {
                return(false);
            }

            if (size <= 0)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 25
0
        public static void SetTopMostTransparent(Window window)
        {
            var handle = new WindowInteropHelper(window).EnsureHandle();

            WindowsApi.SetWindowLong(handle, (int)WindowsApi.WindowLongGroup.GWL_EXSTYLE, TopMostTransparentWindowStyleFlags);
            WindowsApi.SetWindowPos(handle, -1, 0, 0, 0, 0, TopMostWindowSizePositions);
        }
Exemplo n.º 26
0
        protected virtual Bitmap CaptureHandle(IntPtr handle)
        {
            Bitmap memoryImage = null;

            this.images = new Bitmap[1];
            try
            {
                using (Graphics graphics = Graphics.FromHwnd(handle))
                {
                    Rectangle rc = WindowsApi.GetWindowRect(handle);

                    if ((int)graphics.VisibleClipBounds.Width > 0 && (int)graphics.VisibleClipBounds.Height > 0)
                    {
                        memoryImage = new Bitmap(rc.Width, rc.Height, graphics);

                        using (Graphics memoryGrahics = Graphics.FromImage(memoryImage))
                        {
                            memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, CopyPixelOperation.SourceCopy);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Screen capture failed.", ex);
            }

            this.images[0] = memoryImage;
            return(memoryImage);
        }
Exemplo n.º 27
0
        static bool TryReadIntPtr(IntPtr hProcess, IntPtr ptr, out IntPtr readPtr)
        {
            bool result;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                int    dataSize = IntPtr.Size;
                var    data     = Marshal.AllocHGlobal(dataSize);
                IntPtr res_len  = IntPtr.Zero;
                bool   b        = WindowsApi.ReadProcessMemory(
                    hProcess,
                    ptr,
                    data,
                    new IntPtr(dataSize),
                    ref res_len);
                readPtr = Marshal.ReadIntPtr(data);
                Marshal.FreeHGlobal(data);
                if (!b || (int)res_len != dataSize)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 28
0
        public static ulong?FindPatternAddresses(Process process, BytePattern pattern)
        {
            List <ulong> matchAddresses = new List <ulong>();
            var          addressRange   = pattern.AddressRange;
            ulong        currentAddress = addressRange.Start;

            while (currentAddress < addressRange.End && !process.HasExited)
            {
                WindowsApi.MEMORY_BASIC_INFORMATION64 memoryRegion;
                if (WindowsApi.VirtualQueryEx(process.Handle, (IntPtr)currentAddress, out memoryRegion, (uint)Marshal.SizeOf(typeof(WindowsApi.MEMORY_BASIC_INFORMATION64))) > 0 &&
                    memoryRegion.RegionSize > 0 &&
                    memoryRegion.State == (uint)WindowsApi.RegionPageState.MEM_COMMIT &&
                    CheckProtection(pattern, memoryRegion.Protect))
                {
                    var regionStartAddress = memoryRegion.BaseAddress;
                    if (addressRange.Start > regionStartAddress)
                    {
                        regionStartAddress = addressRange.Start;
                    }

                    var regionEndAddress = memoryRegion.BaseAddress + memoryRegion.RegionSize;
                    if (addressRange.End < regionEndAddress)
                    {
                        regionEndAddress = addressRange.End;
                    }

                    ulong  regionBytesToRead = regionEndAddress - regionStartAddress;
                    byte[] regionBytes       = new byte[regionBytesToRead];

                    if (process.HasExited)
                    {
                        break;
                    }

                    int lpNumberOfBytesRead = 0;
                    WindowsApi.ReadProcessMemory(process.Handle, (IntPtr)regionStartAddress, regionBytes, regionBytes.Length, ref lpNumberOfBytesRead);

                    var matchIndices = FindPatternMatchIndices(regionBytes, pattern);

                    foreach (var matchIndex in matchIndices)
                    {
                        var matchAddress = regionStartAddress + (ulong)matchIndex;
                        matchAddresses.Add(matchAddress);

                        Logger.Log(LogLevel.Info, $"Found '{pattern.Config.Name}' at address 0x{matchAddress.ToString("X8")}");

                        break;
                    }
                }

                if (matchAddresses.Any())
                {
                    break;
                }

                currentAddress = memoryRegion.BaseAddress + memoryRegion.RegionSize;
            }

            return(matchAddresses.Count > 0 ? matchAddresses[0] : (ulong?)null);
        }
            internal static System.Collections.Generic.List <string> ReadStandaloneWindowTitles()
            {
                var parameter = new EnumWindowsParameter
                {
                    Titles    = new System.Collections.Generic.List <string>(),
                    ProcessId = WindowsApi.GetCurrentProcessId(),
                };

                var parameterGCHandle = GCHandle.Alloc(parameter);

                try
                {
                    WindowsApi.EnumWindows(EnumWindowsCallback, GCHandle.ToIntPtr(parameterGCHandle));
                }
                finally
                {
                    parameterGCHandle.Free();
                }

                if (parameter.LastWin32Error != 0)
                {
                    throw new Exception("Unknown error: " + parameter.LastWin32Error);
                }

                if (!parameter.Found)
                {
                    throw new Exception("No window found");
                }

                return(parameter.Titles);
            }
Exemplo n.º 30
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     WindowsApi.SetProcessDpiAwareness(ProcessDPIAwareness.ProcessPerMonitorDPIAware);
     Application.Run(new ColorPickerForm());
 }