标签: user32

C#P在64位系统上调用user32.dll

在64位应用程序中,在64位Windows上pinvoke user32.dll是错误的吗?我成功完成了很多次并且从未出现过错误,但这似乎是矛盾的.我应该寻找user64.dll吗?

c# 64-bit pinvoke 32-bit user32

26
推荐指数
1
解决办法
2万
查看次数

通过user32.dll中的SendInput发送密钥

我使用这块板作为键盘用于演示目的.

无论如何,长话短说一切都很好,除了很少的情况.我使用user32.dll中的SendInput函数发送击键.

所以我的程序看起来像:

static void Main(string[] args)
{
    Console.Write("Press enter an on the next secont the key combination shift+end will be send");
    Console.Read();

    Thread.Sleep(1000);

    SendKeyDown(KeyCode.SHIFT);
    SendKeyPress(KeyCode.END);
    SendKeyUp(KeyCode.SHIFT);

    Console.Read(); 
    Console.Read();
}

[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure);

/// <summary>
/// simulate key press
/// </summary>
/// <param name="keyCode"></param>
public static void SendKeyPress(KeyCode keyCode)
{
    INPUT input = new INPUT {
        Type = 1
    };
    input.Data.Keyboard = new KEYBDINPUT() { …
Run Code Online (Sandbox Code Playgroud)

c# user32 sendkeys sendinput

26
推荐指数
1
解决办法
6万
查看次数

使用我的c#app从谷歌浏览器内部获取文本

我正在编写一个小应用程序,除了其他功能外,还可以在键入时将快捷方式扩展为全文.例如:用户在某处写"BNN"并按下相关的键盘组合,应用程序将用"Hi I am Banana"替换"BNN".

经过一些研究,我了解到它可以使用user32.dll,完成这项任务的过程如下:

1)获取活动窗口句柄
2)获取活动窗口线程句柄
3)将输入连接到活动线程
4)获得聚焦控制句柄(+插入位置但不是问题)
5)从活动线程分离输入
6)得到来自聚焦控件的文本使用其句柄

这是我目前的代码:

try
{
    IntPtr activeWindowHandle = GetForegroundWindow();
    IntPtr activeWindowThread = GetWindowThreadProcessId(activeWindowHandle, IntPtr.Zero);
    IntPtr thisWindowThread = GetWindowThreadProcessId(this.Handle, IntPtr.Zero);
    AttachThreadInput(activeWindowThread, thisWindowThread, true);
    IntPtr focusedControlHandle = GetFocus();

    AttachThreadInput(activeWindowThread, thisWindowThread, false);
    if (focusedControlHandle != IntPtr.Zero)
    {
        TB_Output.Text += focusedControlHandle + " , " + GetText(focusedControlHandle) + Environment.NewLine;
    }
}
catch (Exception exp)
{
    MessageBox.Show(exp.Message);
}

//...
//...

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", CharSet …
Run Code Online (Sandbox Code Playgroud)

.net c# google-chrome user32

15
推荐指数
1
解决办法
751
查看次数

如何以编程方式锁定Windows工作站?

可能重复:
在C#中以编程方式锁定Windows工作站

我目前正在开发一个Visual Studio Windows窗体应用程序,它需要一个锁定工作站的功能.当调用该函数时,如何使用user32.dll进行锁定(Windows + L)?

c# user32

14
推荐指数
1
解决办法
1万
查看次数

如何在Win32上创建新窗口时收到通知?

有没有办法使用Win32,在创建新窗口时注册通知.我正在尝试保留当前打开的窗口列表,但现在只是使用查询当前窗口列表EnumWindows().

有人做过类似的事吗?

谢谢


我不确定我是否正确,但我无法启动SetWindowsHookEx方法.

想到什么?

这是我的剪辑

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(HookType hook, HookProc callback, IntPtr hMod, uint dwThreadId);

[DllImport("user32.dll")]
private static extern int CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
const int HSHELL_WINDOWCREATED = 1;

private static HookProc winDelegate = ShellHookProcDelegate;
internal static void RegisterWindowCreatedEvent()
{
    SetWindowsHookEx(HookType.WH_SHELL, winDelegate, IntPtr.Zero, 0);
}

private static int ShellHookProcDelegate(int code, IntPtr wParam, IntPtr lParam)
{
    if (code != HSHELL_WINDOWCREATED)
    {
        return CallNextHookEx(IntPtr.Zero, code, wParam, lParam);
    }

    //App …
Run Code Online (Sandbox Code Playgroud)

winapi user32

10
推荐指数
2
解决办法
6005
查看次数

指挥鼠标事件[DllImport("user32.dll")]点击,双击

我试过[DllImport("user32.dll")]静态extern bool SetCursorPos(int X,int Y);

并且它可以很好地将光标移动到所需的点.我从来没有尝试过这种类型的DLL导入,但它的工作原理:).但是我想要更多我还能提取什么?主要是我想双击,点击或使用滚轮选项而无需任何鼠标输入,只是代码我该怎么做?以及如何查看user32dll中还包含哪些内容?

感谢名单

c# user32

10
推荐指数
2
解决办法
3万
查看次数

对于C#,在调用Win32函数(如GetWindowText)时,是否存在使用'string'而不是'StringBuilder'的缺点?

考虑这两个定义GetWindowText.一个使用a string作为缓冲区,另一个使用a StringBuilder代替:

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowText(IntPtr hWnd, string lpString, int nMaxCount);
Run Code Online (Sandbox Code Playgroud)

这是你怎么称呼他们:

var windowTextLength = GetWindowTextLength(hWnd);

// You can use either of these as they both work
var buffer = new string('\0', windowTextLength);
//var buffer = new StringBuilder(windowTextLength);

// Add 1 to windowTextLength for the trailing null character
var readSize …
Run Code Online (Sandbox Code Playgroud)

c# winapi user32

9
推荐指数
1
解决办法
232
查看次数

无法将User32.dll导入Visual Studio

我试过了:

  • 要添加user32.dll中参考经理,并从进口它的Windows\SYSTEM32\user32.dll中,我得到了错误信息:

    无法添加对"C:\ Windows\System32\user32.dll"的引用.请确保该文件是可访问的,并且它是有效的程序集或COM组件.

  • using System.Runtime.InteropServices; [DllImport("user32")]

  • 以管理员身份启动Visual Studio

什么都行不通......它让我感到紧张我试着用2个小时来导入这个该死的.dll ......

c# user32 visual-studio-2012

8
推荐指数
1
解决办法
2万
查看次数

Unity3d user32.dll拖动窗口并重新获得焦点

我创建了一个无边框窗口应用程序和一个"假"标题栏来拖动它.

我正在使用user32.dll,

这开始拖动窗口(由统一IBeginDragHandler触发):

public const int WM_NCLBUTTONDOWN = 0xA1;
public const int WM_NCLBUTTONUP = 0x00A2;
public const int WM_LBUTTONUP = 0x0202;

[DllImport("User32.dll")]
public static extern bool ReleaseCapture();

[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

IntPtr window = GetActiveWindow();
...
...
ReleaseCapture();
SendMessage(window, WM_NCLBUTTONDOWN, HTCAPTION, 0);
Run Code Online (Sandbox Code Playgroud)

这是为了停止拖动(不确定这部分):

    ReleaseCapture();
    SendMessage(window, WM_NCLBUTTONUP, HTCAPTION, 0);
    SendMessage(window, WM_LBUTTONUP, HTCAPTION, 0);
Run Code Online (Sandbox Code Playgroud)

它在编辑器和构建上运行良好,但在developpement构建上产生错误:

发生了异常情况:已经递归调用了PlayerLoop内部函数.请通过示例项目联系客户支持,以便我们重现问题并对其进行故障排除.LauncherWindow:SendMessage(IntPtr,Int32,Int32,Int32)LauncherWindow:StartWindowDrag()(在E:\ Unity Projects\Crime Club Launcher\Assets\Scripts\Lib\LauncherWindow.cs:115)WindowDragZone:UnityEngine.EventSystems.IBeginDragHandler.OnBeginDrag (PointerEventData)(在E:\ Unity Projects\Crime Club Launcher\Assets\WindowDragZone.cs:9)UnityEngine.EventSystems.ExecuteEvents:Execute(IBeginDragHandler,BaseEventData)(在C:\ buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents.cs:64)UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject,BaseEventData,EventFunction`1)(在C:\ buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\ExecuteEvents) .cs:261)UnityEngine.EventSystems.PointerInputModule:ProcessDrag(PointerEventData)(在C:\ buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\PointerInputModule.cs:261)UnityEngine.EventSystems.StandaloneInputModule: ProcessMouseEvent(Int32)(在C:\ buildslave\unity\build\Exte nsions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:434)UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent()(在C:\ buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\EventSystem\InputModules\StandaloneInputModule.cs:412)UnityEngine.EventSystems.StandaloneInputModule:Process()(在C:\ …

c# user32 unity-game-engine

8
推荐指数
1
解决办法
1229
查看次数

C#最小化窗口没有通过调用System.Diagnostics.Process.GetProcesses()返回

我正在尝试找到一个最小化的窗口并显示它.

该程序可以从三星下载,标题为"SideSync".要完全复制我的问题,您需要安装此问题并使用三星手机插入计算机.

以下是完全配置和运行的屏幕截图:

在此输入图像描述

观察到有两个窗口,A和B.我使用一个名为Microsoft Inspect的工具来确定两个程序窗口是正常的窗口.他们没有孩子的父母关系.但是,当我启动SideSync时,只显示窗口A. 然后我必须单击"电话屏幕",然后出现窗口B(除了窗口A).这可能是解决这个问题的线索吗?我们会看到.

以下是Microsoft Inspect中出现的两个窗口:

在此输入图像描述

两个窗口都有窗口标题.使用下面的代码我可以检索Process窗口(这是我的目标).

服务器代码:

public static Process GetProcessByWindowTitle(string windowTitleContains)
{
    foreach (var windowProcess in GetWindowProcesses())
        if (windowProcess.MainWindowTitle.Contains(windowTitleContains))
            return windowProcess;

    return null;
}
Run Code Online (Sandbox Code Playgroud)

然而,一些奇怪的行为正在发生.GetProcessByWindowTitle()将返回一个但不是两个进程.我假设因为有两个窗口必须有两个进程.

Process则返回依赖于这是我和我的鼠标点击最后一个窗口.

例如,如果我上次点击了窗口A; 然后GetProcessByWindowTitle("SideSync")将返回Process,但随后GetProcessByWindowTitle("SAMSUNG")将返回void.

...反之亦然,如果我上次点击窗口B,GetProcessByWindowTitle("SideSync")将返回一个void,但随后GetProcessByWindowTitle("SAMSUNG")将返回Process.

客户代码:

[Ignore("Requires starting SideSync and clicking one of the windows. Only the last clicked will return a Process.")]
[Test]
public void NonMinimizedWindowProcessIsDetected()
{

    Process p1 …
Run Code Online (Sandbox Code Playgroud)

c# windows user32

8
推荐指数
1
解决办法
319
查看次数