类帮助内的窗口消息过程 [英] Window Message Procedure inside class help

查看:81
本文介绍了类帮助内的窗口消息过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再见一次.

我有一个可以管理窗口的类.
现在,我现在正在做的是制作另一个使用该窗口管理类"的类,并将Windows消息过程作为我的类.
它在声明为statice时可以正常工作,但是问题是当我尝试在该静态消息处理程序中使用非static veriable时,VS2010不喜欢它.
有没有办法访问那些非静态变量?
在此先感谢.

---编辑---
窗口管理类"创建带有所需图标等的窗口.
而且我还有另一个名为class2的类,并且我希望Windows消息过程LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)在class2内,如果声明为静态的,现在可以工作.
我已经看过传递类实例,但是我看不到方法.

Hi All Again.

i have a class that can manage a window.
now what im doing now is makeing another class that uses that "Window Management Class" and have the Windows Message Procedureide my class.
it works while it is declared as statice, but the problem is when i try to use non static veriables inside that static message handler, VS2010 does not like it.
is there a way to access those non statice variables ?
Thanks in Advance.

---edit---
the "Window Management Class"creates a window with the desired icon etc.
and i have another class called class2 and i want the windows message procedure LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) to be inside class2, now it works if it is declared as static.
and ive looked at passing the class instance but i dont see a way to.

推荐答案

您不能使用静态方法中的成员变量,属性和方法.因此,如果您的消息处理程序仅在声明为静态时才起作用,则无法访问任何非静态成员.

干杯!

--MRB
You can''t use member variables, properties and methods from a static method. So if your message handler only works when declared as static there is no way to access any non static members.

Cheers!

--MRB


您不能在静态方法内访问非静态成员:这是C++规则,而不是VS2010特质.

通常的解决方法是将变量(或变量,对于整个类实例,在最坏的情况下为this)传递给静态方法.如果您不能这样做(例如,由于方法签名是固定的),则可以制作另一个静态方法(接受并返回此类实例变量),然后从窗口消息过程中调用它.
You cannot access non-static members inside a static method: it is a C++ rule, not a VS2010 idiosyncrasy.

The usual workaround is passing the variable (or the variables, at worst this for the whole class instance) to the static method. If you cannot do that (because, for instance, the method signature is fixed) than you can make another static method (that accepts and returns such instance variable) and then call it from your window message procedure.


将窗口过程作为类成员函数 [ ^ ]讨论您问题的不同答案(包括SAKryukov的答案).
欢呼声,
AR
Window Procedures as Class Member Functions[^] discusses different answers (including SAKryukov''s) to your question.
cheers,
AR


这篇关于类帮助内的窗口消息过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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