你如何表明在窗口过程处理消息的错误? [英] How do you indicate errors in handling messages in window procedures?

查看:125
本文介绍了你如何表明在窗口过程处理消息的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在创作一图书馆从原始输入API处理信息,我用的级联功能处理一切的。这导致了一些非常小,可读性很强,而且非常注重功能。

I'm currently authoring a library to handle information from the Raw Input API and I'm handling everything with cascading functions. This has resulted in several, very small, very readable, and very focused functions.

不过,它刚刚打我,我不知道如何为正确表示失败到Windows。我具备的功能:

But, it has just hit me that I don't understand how to properly indicate failure to Windows. I have the function:

/* OnInput: Handle data received from Windows via a `WM_INPUT` message. */
static LRESULT CALLBACK OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    BOOL DispatchRawInput(CONST PRAWINPUT);

    assert(msg == WM_INPUT);

    return DefWindowProc(hWnd, msg, wParam, lParam);
}

和作为文档指出它应该一>;但这种假设的成功。

And it returns zero as the documentation states it should; but this assumes success.

实际文本规定:

如果一个应用程序处理此消息,它应该返回零。

"If an application processes this message, it should return zero."

不过,我该怎么办,如果我的无法的处理呢?我本来以为你只需要调用 DefWindowProc函数,并留在这一点,但是这并不意味着到Windows发生了什么情况。

But what do I do if I can't handle it? I originally assumed you'd just call DefWindowProc and leave it at that but that doesn't signal to Windows that anything happened.

消息 WM_CREATE 似乎是我能找到的唯一实例返回其他的东西比为零:

The message WM_CREATE seems to be the only instance I can find that returns something other than zero:

如果一个应用程序处理此消息时,它应该返回零来继续窗口的创建。如果应用程序返回-1,窗口被破坏,是CreateWindowEx或CreateWindow函数返回NULL句柄。

"If an application processes this message, it should return zero to continue creation of the window. If the application returns –1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle."

时的错误处理实际上只是由程序员/团队,而不是一个必要通知操作系统?关于如 WM_CREATE 事件失败,需要prevent窗口的创建是什么?

Is error handling really just up to the programmer/team and not a necessity to inform the operating system? What about events like WM_CREATE that fail and need to prevent the creation of a window?

推荐答案

您根据每条消息的文件指示错误。如果该消息并没有说明任何错误,那么你就可以放心地假设该消息没有错误指示。这是通知消息,其中OS只是告诉你,事情发生普遍。它并不需要你的回应。

You indicate errors according to the documentation for each message. If the message doesn't say anything about errors, then you can safely assume that the message has no error indicator. That's common for notification messages, where the OS is simply telling you that something has happened. It doesn't need a response from you.

这篇关于你如何表明在窗口过程处理消息的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆