首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通用视窗平台上的User32视窗UI Api

通用视窗平台上的User32视窗UI Api
EN

Stack Overflow用户
提问于 2018-09-28 20:47:42
回答 1查看 419关注 0票数 0

我在UWP编程方面没有太多经验,我创建了一个应用程序,可以在蓝牙上做一些事情。现在我必须通过API获取一些信息。但不知何故,"SendMessage“不起作用。下面是我使用的代码

代码语言:javascript
复制
public static class ApiComm
{
    [DllImport("User32.dll")]
    public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

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

    public static string DelphiFormClassName = "TFrmMain";//"wsdk_delphi_api_test";
    public static string DelphiFormCaptionName = "Deneme";

    private static IntPtr FindDelphiForm(string delphiFormClassName, string delphiFormCaptionName)
    {
        return FindWindow(delphiFormClassName, delphiFormCaptionName);
    }
    private static IntPtr FindDelphiForm()
    {
        return FindDelphiForm(DelphiFormClassName, DelphiFormCaptionName);
    }

    public static int TextToID(string text)
    {
        int mu = (text == null ? 0 : text.Length);
        int result = 0;
        for (int i = 0; i < mu; i++)
            result = result + (((i + 1) * 256) + (byte)(text[i]));

        return result;
    }

    private const int WM_COMMAND = 0x0111;
    private const int StartFrom = 500;

    private static int EventID(RemoteDeviceUpdate anEvent)
    {
        return StartFrom + (int)anEvent;
    }

    public static void SendInfo(int remoteID, RemoteDeviceUpdate anEvent)
    {
        IntPtr wP = FindDelphiForm();
        if (wP != null && wP != IntPtr.Zero)
        {
            int eID = EventID(anEvent);
            SendMessage(wP, WM_COMMAND, eID, remoteID);
        }
    }
    public static void SendInfo(string remoteID, RemoteDeviceUpdate anEvent)
    {
        SendInfo(TextToID(remoteID), anEvent);
    }
}

当我在另一个.net项目中尝试SendInfo时,它工作得很好,但在UWP上就不行了(而且它也不会给出任何错误)

我是否必须在我的项目中添加包或其他东西..

任何帮助都会很感谢,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-09-30 13:53:35

从此case派生,您需要检查该API是否可用于Windows Runtime应用程序。

应用程序可以p-调用与应用程序包一起部署的DLL。DLL将在应用程序的上下文中运行,并具有与应用程序本身相同的API访问。有关Windows Runtime应用程序可用的Win32 API的概述,请参阅Win32和COM API。

如果你只是想构建一个应用程序,那么你可以在蓝牙上做一些事情。你可以做这一切与uwp蓝牙api。这是official document。对于RFFCOMM,这是您可以参考的uwp code sample

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52555704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档