如何在mfc中为动态创建的静态控件添加事件处理程序 [英] How to add event handler for dynamically created static control in mfc
本文介绍了如何在mfc中为动态创建的静态控件添加事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基于mfc对话框的应用程序,可以在单击特定按钮时动态创建静态控件。现在我需要向这些控件添加一个事件处理程序OnClick。请帮我解决这个问题。
我使用的是Visual Studio 2008
我尝试了什么:
我尝试使用ON_CONTROL_RANGE,但点击那些控件没有任何反应
I have an mfc dialog based application that creates static controls dynamically whenever a particular button is clicked. Now I need to add an event handler OnClick to those controls. Please help me to solve out this problem.
I am using Visual Studio 2008
What I have tried:
I tried using ON_CONTROL_RANGE, but nothing happens on clicking those controls
推荐答案
在创建静态控件以启用通知时,必须使用SS_NOTIFY
样式。然后父窗口将获得 STN\_CLICKED通知代码| Microsoft Docs [ ^ ]。
在消息地图中,您可以使用STN_CLICKED
或BN_CLICKED
因为它们具有相同的值。
You have to use theSS_NOTIFY
style when creating the static controls to enable notifications. Then the parent window will get a STN\_CLICKED notification code | Microsoft Docs[^].
In the message map you can useSTN_CLICKED
orBN_CLICKED
because they have the same value.
这篇关于如何在mfc中为动态创建的静态控件添加事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文