如何在基于mfc对话框的另一个类文件中访问afx保护方法 [英] How to access afx protected method in another file of class in mfc dialog based

查看:79
本文介绍了如何在基于mfc对话框的另一个类文件中访问afx保护方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用一个按钮在主对话框中完成了GUI。如果我按下那个按钮,我将获得一个带有一个按钮和编辑框的无模式另一个对话框。我的目标是,如果我按下主对话框按钮,按钮应该访问另一个对话框按钮。



一般按钮功能默认处于保护模式,如何访问受保护主对话框按钮功能中的afx按钮功能。



我尝试过:



我在主对话框中以公共模式创建了另一个对话框的对象。通过该对象我厌倦了访问另一个对话框保护函数。

解决方案

创建一个访问器(公共方法)以操纵受保护的属性。


所以你有一个主对话框,按下按钮时会创建另一个(无模式)对话框(或者如果已存在则希望激活无模式对话框)。



在这种情况下,主对话框通常包含第二个对话框的成员。您可以使用该成员访问其他对话框及其公共成员。要访问受保护的成员,您可以添加允许一般访问的函数(返回指向成员的指针)或执行特定操作的函数。



如果您引用一条消息处理程序通过afx按钮功能,只需将相应的消息发送到窗口即可。如果你想在无模式对话框中模拟一个按钮点击,你只需要该对话框的 CWnd 和按钮的ID:

 m_pModelessDialog-> SendMessage(
WM_COMMAND,
MAKEWPARAM(ID_OF_BUTTON,BN_CLICKED),
// 也可以在这里传递NULL(在大多数情况下都有效)
m_pModelessDialog-> GetDlgItem(ID_OF_BUTTON) - > GetSafeHwnd()
) ;


I have done a GUI with main dialog box with one button. if I press that button I will get modeless another dialog box with one button and edit box. My aim is if I press main dialog box button the button should access the another dialog box button .

Generally Button function is in protected mode by default, how to access protected afx button function in main dialog box button function.

What I have tried:

I created object of another dialog box in public mode in main dialog box. Thru that object I tired to access another dialog box protected function.

解决方案

Make an accessor (a public method) in order to manipulate the protected property.


So you have a main dialog which creates another (modeless) dialog upon a button press (or hopefully activates the modeless dialog if it exists already).

In such cases your main dialog usually contains a member for the second dialog. You can use that member to access the other dialog and it's public members. For access to protected members you can add functions that allow general access (return a pointer to the member) or functions that perform specific actions.

If you refer to a message handler by "afx button function", just send the corresponding message to the window. If you want for example to simulate a button click in the modeless dialog all you need is the CWnd of that dialog and the ID of the button:

m_pModelessDialog->SendMessage(
    WM_COMMAND,
    MAKEWPARAM(ID_OF_BUTTON, BN_CLICKED),
    // May also pass NULL here (works in most cases)
    m_pModelessDialog->GetDlgItem(ID_OF_BUTTON)->GetSafeHwnd()
);


这篇关于如何在基于mfc对话框的另一个类文件中访问afx保护方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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