Advertisement
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.Threading.Tasks;
- namespace ПоискОкна
- {
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Text;
- public static class НайтиОкно
- {
- private const uint WM_GETTEXT = 0x000D;
- [DllImport("user32.dll", SetLastError = true)]
- private static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
- private static IEnumerable<IntPtr> EnumerateProcessWindowHandles(Process process)
- {
- var handles = new List<IntPtr>();
- foreach (ProcessThread thread in process.Threads)
- {
- EnumThreadWindows(thread.Id, (hWnd, lParam) =>
- {
- handles.Add(hWnd);
- return true;
- }, IntPtr.Zero);
- }
- return handles;
- }
- [DllImport("user32.dll", CharSet = CharSet.Unicode)]
- private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
- [DllImport("user32.dll", CharSet = CharSet.Unicode)]
- private static extern int GetClassName(
- IntPtr hWnd,
- StringBuilder lpClassName,
- int nMaxCount
- );
- [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
- public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
- public static extern bool IsWindowVisible(IntPtr hWnd);
- public static void ПоказатьОкно(string НазваниеОкна)
- {
- string Заголовок="1С:Предприятие";
- foreach (var processRunning in System.Diagnostics.Process.GetProcesses())
- {
- if (processRunning.ProcessName.StartsWith("1cv7"))
- foreach (IntPtr handle in EnumerateProcessWindowHandles(processRunning))
- {
- var wndCaption = new StringBuilder(1000);
- SendMessage(handle, WM_GETTEXT, wndCaption.Capacity, wndCaption);
- if (wndCaption.Length >= Заголовок.Length)
- if (wndCaption.ToString(0,Заголовок.Length)==Заголовок)
- if (!IsWindowVisible(handle))
- ShowWindow(handle, 5);
- // var wndClass = new StringBuilder(255);
- // GetClassName(handle, wndClass, wndClass.Capacity);
- // Console.WriteLine("[{0:X8}] '{1}' '{2}'", handle, wndCaption, wndClass);
- }
- // Console.ReadLine();
- }
- }
- #region Nested type: EnumThreadDelegate
- private delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement