如何在一个项目的不同形式中管理两个相同的事件。 [英] How to manage two same events in the different forms of one projects.
本文介绍了如何在一个项目的不同形式中管理两个相同的事件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我用Visual C ++编写代码。
一个项目处理两种形式(例如A-form, B-form)
单击A-form按钮的事件与B-form的另一个按钮点击完全相同
例如,同一事件是调用CFile Dialogue并保存或加载一个文件。
你能不能告诉我管理代码为方便起见。
谢谢
我尝试了什么:
这个问题浪费了近2个小时。
Hi,
Now I am coding in the Visual C++.
One projects handle two forms (ex. A-form, B-form)
The event of one button click of A-form is exact same to that of another button click of B-form
For example, the same event is call CFile Dialogue and save or load one file.
Could you tell me to manage easily codes for the convenience.
Thank you
What I have tried:
Almost 2 hours wasted for that problem.
推荐答案
创建一个名为Utils的类或者其他什么,实现你常用的程序作为静态函数
然后你可以在stdafx.h
之后的任何地方调用它们
例如:
Utils.h
Create a class called Utils or whatever ,implement your commonly used procedures as static functions
And then you can call them from anywhere after included instdafx.h
Example :
Utils.h
class Utils
{
public:
static BOOL SaveTextToFile(CString strText,CWnd *pCaller);
}
Utils.cpp
Utils.cpp
#include "Utils.h"
BOOL Utils::SaveTextToFile(CString strText,CWnd *pCaller)
{
//open file dialog ,get target path
//save text to file
//return the result
return TRUE;
}
用法:
Usage:
void MyDialogClass::OnBnClickedButtonABC()
{
BOOL bResult = Utils::SaveTextToFile(_T("Hello world"),this);
}
void MyOtherDialogClass::OnBnClickedButtonXYZ()
{
BOOL bResult = Utils::SaveTextToFile(_T("Hello world"),this);
}
这篇关于如何在一个项目的不同形式中管理两个相同的事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文