繁体   English   中英

C#:FindWindowEx无法按预期工作

[英]C#: FindWindowEx not working as anticipated

好的,首先我是C#的新手,所以这可能真的很简单,我只是在整个Google / SO中都找不到答案。

我有一个尝试使用FindWindowEx的类,但是Visual Studio不允许我使用“空”参数,我不确定为什么。

到目前为止,该类具有以下代码:

    [DllImport("user32.dll")]
    public static extern IntPtr FindWindowEx(IntPtr handleParent, IntPtr handleChild, string className, string WindowName);

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

    public void SomeWindow()
    {

        String someHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", NULL);

    }

在撰写本文时,它告诉我在当前上下文中不存在“ NULL”。 我也尝试写成:

FindWindowEx(null, null, "SomeWindowClass", null)

这会在前两个“ null”说“参数#:无法从'null'转换为'IntPtr'”时产生错误(“ null”实际上包含<和>,尽管SO并未与它们一起显示)

Windows开发人员中心说我应该能够按原样使用它: https//msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v = vs.85).aspx

就像我说的那样,这可能非常简单,我只是没有足够的C#经验来弄清楚。

FindWindow返回类型为IntPtr,而您正在尝试将其分配给字符串。

尝试这个。

IntPtr wnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SomeWindowClass", null);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM