Is it possible to avoid static or global variables in dialog functions

喜欢而已 提交于 2019-12-11 09:16:12

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/3601763/is-it-possible-to-avoid-static-or-global-variables-in-dialog-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!