Windows过程和多态函数调用 [英] Windows Procedure and Polymorphic function calls

查看:76
本文介绍了Windows过程和多态函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为自己创建的游戏创建屏幕管理器.屏幕管理器的基本操作基于指向屏幕对象继承的基类的指针.这是声明:

I am creating a screen manager for a game I am creating. The fundamental operation of the screen manager is based on a pointer to a base class that screen objects inherit. Here is the declaration:

class screen_base
{
friend class screen_manager;
public:
    virtual bool init()=0;
    virtual bool deinit()=0;
    virtual bool render()=0;
    virtual bool update()=0;
    virtual void event_handle(HWND, UINT, WPARAM, LPARAM)=0;
protected:
    app_data win_data;
    unsigned int state;
    float fim;
};



每当我尝试在窗口过程(从指针)中调用event_handle()函数时,该程序只是返回0结束执行,就永远不会创建该窗口.我尝试将调用放入一个单独的函数中,然后在窗口过程中调用它,但这也不起作用.



whenever I try to call the event_handle() function inside the window procedure (from the pointer) The program just ends execution returning 0, the window is never even created. I tried putting the call into a separate function and calling that in the window procedure but that didn''t work either.

Is there any way to call this function?

推荐答案

我注意到您的句柄是void 函数.
窗口过程是LRESULT 返回函数.

不幸的是,一些嵌套消息应该将有意义的LRESULT 值返回给调用方.
通过丢弃结果,在特定点上您将返回给WM_NCCREATE,这将使所有创建过程失败.

只需考虑具有正确原型LRESULT handle(HWND,UINT,WPARAM,LPARAM)的句柄并正确管理返回值即可.
I note your handle is a void function.
The window procedure is instead an LRESULT returning function.

Unfortunately, some nested messages are supposed to return meaningful LRESULT values to the calling ones.
By throwing away the result, at a certain point you end up by returning "false" to WM_NCCREATE, that makes all the creation process to fail.

Just consider a handle with proper prototype LRESULT handle(HWND,UINT,WPARAM,LPARAM) and manage the return value properly.


这篇关于Windows过程和多态函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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