Tag: user32

C#如何等待弹出窗口并选择它进行输入

我基本上是用C#编写一个专门的宏播放器/录音机。 我需要做的一件事是等待弹出窗口(类似于另存为…对话框),然后我可以选择继续播放宏输入。 理想情况下,我希望能够轮询打开的窗口并搜索其标题以获得匹配的窗口标题。 显然我不能使用Processes.GetProcesses(),因为对话框很可能不会显示为新进程。 我想在哪里打开窗户及其标题?

如何在c#中使用user32.dll从类“ThunderRT6ListBox”的窗口中检索值

我试图从Windows中的extern桌面应用程序检索信息。 我知道如何从Textboxes中提取文本(类“编辑”),但我不知道如何从类名为“ThunderRT6ListBox”和“ThunderRT6ComboBox”的控件中提取值。 我怎样才能做到这一点? 我有这段代码从文本框中提取文本: public static class ModApi { [DllImport(“user32.dll”, EntryPoint = “FindWindowA”, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport(“user32.dll”, SetLastError = true, CharSet = CharSet.Auto)] public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); [DllImport(“user32.dll”, EntryPoint = “SendMessageTimeout”, SetLastError = true, CharSet […]

EnumDisplayDevices返回值是Generic PnP Monitor – c#

当我想要返回它们的实际名称时,我连接了几个监视器 – 例如:LEN L192p,IBM 190p。 我看过这个问题: 如何获取实际的Monitor名称? 如解决方案对话框中所示 但是当我运行它时,我的识别错误。 它检测到我的笔记本电脑,但是我正在使用的其他两个屏幕(LEN L192p,IBM 190p)未被检测到,而是编写了Generic PnP Monitor 。 谁知道会出现什么问题? 这是输出: 和代码: using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Screens { class Program { [DllImport(“user32.dll”)] public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags); [Flags()] public enum […]

使用post / sendmessage做鼠标点击不起作用

可能重复: 如何在C#中模拟鼠标点击? 我试过了 Window = FindWindow(null, “untitled – Paint”); PostMessage(WindowToFind, WM_MOUSEMOVE, 0, location); PostMessage(WindowToFind, WM_LBUTTONDOWN, ((int)Keys.LButton), location); 位置是100 * 0x10000 + 100 100×100等。我怀疑它是错的。 我尝试用0交换((int)Keys.LButton) ,没有用。 我尝试在lbuttondown和thread.sleep之间lbuttondown lbuttonup (以及postmessage应该等待没有thread.sleep但是等等)我使用0x0200进行mousemove和0x0202进行左键按钮。 不知道为什么它根本不起作用。

GetWindowText()抛出错误而不被try / catch捕获

当我为GetWindowText运行下面的代码时,我得到以下错误作为内部exception抛出: {“尝试读取或写入受保护的内存。这通常表示其他内存已损坏。”} [DllImport(“user32.dll”, EntryPoint = “GetWindowTextLength”, SetLastError = true)] internal static extern int GetWindowTextLength(IntPtr hwnd); [DllImport(“user32.dll”, EntryPoint = “GetWindowText”, SetLastError = true)] internal static extern int GetWindowText(IntPtr hwnd, ref StringBuilder wndTxt, int MaxCount); try{ int strLength = NativeMethods.GetWindowTextLength(wndHandle); var wndStr = new StringBuilder(strLength); GetWindowText(wndHandle, ref wndStr, wndStr.Capacity); } catch(Exception e){ LogError(e) } 我有两个问题: 为什么错误没有被try catch捕获? […]

WinForms相当于WPF WindowInteropHelper,HwndSource,HwndSourceHook

我有一块代码,如: IntPtr hWnd = new WindowInteropHelper(this).Handle; HwndSource source = HwndSource.FromHwnd(hWnd); source.AddHook(new HwndSourceHook(WndProc)); NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_CALL, IntPtr.Zero, IntPtr.Zero); 这最初是在WPF应用程序中。 但是,我需要在WinForms应用程序中复制该function。 另外,NativeMethods.PostMessage只是映射到user32.dll PostMessage: [DllImport(“user32”)] public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); 我可以在WinForms应用程序中使用1到1当量的WindowInteropHelper/HwndSource/HwndSourceHook吗?

外部应用程序窗口移动时移动窗口

我有一个总是在顶部的应用程序(基本上是一个状态显示),我想跟随另一个程序,并始终坐在最小化按钮的左侧。 我可以使用以下代码获取表示“目标”过程的Rect ,然后我可以将其与偏移量配对以生成叠加层的初始位置。 获取HWnd IntPtr: private IntPtr HWnd = Process.GetProcessesByName(“targetapplication”)[0].MainWindowHandle; 从user32.dll声明函数: [DllImport(“user32.dll”, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect); 和适当的struct : [StructLayout(LayoutKind.Sequential)] private struct RECT { public int Left; public int Top; public int Right; public int Bottom; } 然后按需调用它。 但是,我想避免不断轮询这个值,所以我想挂钩到目标应用程序并在目标窗口移动时响应。 查看user32.dll文档,我能看到的唯一方法是使用SetWindowsHookEx() 。 但是,我并不完全确定如何从这里拦截一个事件。 我相信目标应用程序是基于WinForms构建的,但我无法确定。 因此,让我响应目标的Move事件或直接响应某些Windows消息的解决方案都很有用。 关于如何进行的任何想法?

是否可以使用IntPtr激活另一个程序中的选项卡?

提前致谢。 是否可以使用IntPtr激活另一个程序中的选项卡? 如果是这样,怎么样? SendKeys不是一个选项。 也许我需要的是钓鱼课程。 我已经筋疲力尽了谷歌和我的首席开发人员。 我希望得到彻底解决方案或建议继续我的Google努力。 基本过程是: 我将快捷方式图标拖到启动器上 这将打开目标应用程序(Notepad ++)并获取IntPtr等。 我想以编程方式在Notepad ++中选择各种项目,例如编辑,编辑下的菜单项或文档选项卡。 我运行的基本代码是: ‘blob’ 第1项:项目的IntPtr 第2项:itemsChild的IntPtr 第3项:第1项的控制案文 第4项:是第1项的矩形参数 root包含类似的信息:

使用C#从任何窗口捕获突出显示的文本

如何使用c#从任何窗口中读取突出显示/选定的文本。 我试过两种方法。 每当用户选择一些东西时发送“^ c”。 但在这种情况下,我的剪贴板充斥着大量不必要的数据。 有时它也会复制密码。 所以我把我的方法改为第二种方法,发送消息方法。 请参阅此示例代码 [DllImport(“user32.dll”)] static extern int GetFocus(); [DllImport(“user32.dll”)] static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach); [DllImport(“kernel32.dll”)] static extern uint GetCurrentThreadId(); [DllImport(“user32.dll”)] static extern uint GetWindowThreadProcessId(int hWnd, int ProcessId); [DllImport(“user32.dll”) ] static extern int GetForegroundWindow(); [DllImport(“user32.dll”, CharSet = CharSet.Auto, SetLastError = false)] static extern int SendMessage(int hWnd, int […]

从任何过程中获取密钥

我在网上看过很多解决方案,但没有一个完全符合我的要求。 我的应用程序在后台运行时,在给定进程(而不是我的控制台应用程序)中按下任何键的最佳/最简单方法是什么? 我不需要修改器或任何东西。