是否可以避免对话功能中的静态或全局变量 [英] Is it possible to avoid static or global variables in dialog functions

查看:122
本文介绍了是否可以避免对话功能中的静态或全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在对话框功能中需要某种状态,那么您似乎需要某种静态变量。例如,GetOpenFileName的钩子过程在WM_INITDIALOG调用中提供了OPENFILENAME结构的地址的对话框函数,但不包括任何后续调用,OPENFILENAME结构包含一个可用于在对话过程和GetOpenFileName调用者。如果对话框功能需要这些状态,似乎唯一的选择是静态或全局变量。

If one needs some sort of state in a dialog function, it seems you need some sort of static variable. For example, the hook procedure for GetOpenFileName provides the dialog function with the address of the OPENFILENAME structure on its WM_INITDIALOG call but not on any subsequent calls and the OPENFILENAME structure contains a place for lCustData which could be used to pass information between the dialog procedure and the GetOpenFileName caller. If the dialog function needs either of these states, it seems the only alternative is a static or global variable.

推荐答案

可以使用SetProp在WM_INITDIALOG如此KB 建议或SetWindowLongPtr(..,GWLP_USERDATA)如果您有自定义控件(模板)

You can use SetProp in WM_INITDIALOG like this KB recommends, or SetWindowLongPtr(..,GWLP_USERDATA) if you have custom controls (template)

这篇关于是否可以避免对话功能中的静态或全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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