是否有一种惯用的 .net 方式来实现“培训卡帮助”?

发布于 2024-09-10 13:34:22 字数 205 浏览 10 评论 0原文

我们有一个 VB6 应用程序,它实现了来自 HTML 帮助文件的 WM_TCARD 消息的处理程序。 它在应用程序内导航并打开相关屏幕等。

如何在 WinForms 应用程序中执行此操作?

我能立即看到的唯一方法是处理窗口过程并处理 WM_TCARD 消息,其方式与我们对 VB6 应用程序所做的完全相同。

有没有更 .net 的方式来做到这一点?

We have a VB6 app that has implemented a handler for WM_TCARD messages from an HTML Help file.
It navigates within the application and opens the relevant screens etc.

How does one do this in a WinForms app?

The only way I can immediately see is to handle the window procedure and process the WM_TCARD message in exactly the same way we were doing for the VB6 app.

Is there a more .net way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻了热茶 2024-09-17 13:34:22

您必须自己处理这些消息。但是,创建一个为您执行此操作的类非常容易。例如:

public class HelpCards : IMessageFilter {
    const int WM_TCARD = 0x52;
    const int ID_NOTIFICATION = 4242;

    public enum TCardAction: int {
        IDOK = 1,
        IDCANCEL = 2,
        IDABORT = 3,
        IDRETRY = 4,
        IDIGNORE = 5,
        IDYES = 6,
        IDNO = 7,
        IDCLOSE = 8,
        IDHELP = 9,

        HELP_TCARD = 0x8000,
        HELP_TCARD_DATA = 0x0010,
        HELP_TCARD_OTHER_CALLER = 0x0011,
        HELP_TCARD_OTHER_NEXT = 0x0011,
    }

    public HelpCards() {
        Application.AddMessageFilter(this);
    }

    public delegate void OKReceived();
    public event OKReceived OnOKReceived; 

    public bool PreFilterMessage(ref Message m) {
        if (m.Msg == WM_TCARD && (int)m.WParam == ID_NOTIFICATION) {
            switch ((TCardAction)m.LParam) {
                case TCardAction.IDOK:
                    if (OnOKReceived != null) {
                        OnOKReceived();
                    }
                    break;
                    // etc.
            }

            return true; // true means message was handled
        }

        return false;
    }
}

然后,在您要订阅的地方(可能在您的表单中的某个地方)使用

hc = new HelpCards();
hc.OnOKReceived += new OKReceived(hc_OnOKReceived);

并在表单的类定义中定义 hc 。就像这样

HelpCards hc;

,某个地方有处理功能:

void hc_OnOKReceived() {
    throw new NotImplementedException();
}

显然你需要自己做剩下的事情。但这应该可以帮助您开始。

You'll have to handle the messages yourself. However, it's pretty easy to make a class which does this for you. E.g.:

public class HelpCards : IMessageFilter {
    const int WM_TCARD = 0x52;
    const int ID_NOTIFICATION = 4242;

    public enum TCardAction: int {
        IDOK = 1,
        IDCANCEL = 2,
        IDABORT = 3,
        IDRETRY = 4,
        IDIGNORE = 5,
        IDYES = 6,
        IDNO = 7,
        IDCLOSE = 8,
        IDHELP = 9,

        HELP_TCARD = 0x8000,
        HELP_TCARD_DATA = 0x0010,
        HELP_TCARD_OTHER_CALLER = 0x0011,
        HELP_TCARD_OTHER_NEXT = 0x0011,
    }

    public HelpCards() {
        Application.AddMessageFilter(this);
    }

    public delegate void OKReceived();
    public event OKReceived OnOKReceived; 

    public bool PreFilterMessage(ref Message m) {
        if (m.Msg == WM_TCARD && (int)m.WParam == ID_NOTIFICATION) {
            switch ((TCardAction)m.LParam) {
                case TCardAction.IDOK:
                    if (OnOKReceived != null) {
                        OnOKReceived();
                    }
                    break;
                    // etc.
            }

            return true; // true means message was handled
        }

        return false;
    }
}

Then, in the place where you want to subscribe (probably in your form somewhere) use

hc = new HelpCards();
hc.OnOKReceived += new OKReceived(hc_OnOKReceived);

And have hc defined in the class definition of the form. Like so

HelpCards hc;

And somewhere have the handling function:

void hc_OnOKReceived() {
    throw new NotImplementedException();
}

Obviously you will need to do the rest yourself. But that should get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文