Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 19-Mar-16 11:20am
v2
Comments
Richard MacCutchan 19-Mar-16 12:30pm    
Almost 2 hours wasted for that problem.
Sorry, but that does not explain what your problem is, or what you have tried.

1 solution

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 in stdafx.h

Example :

Utils.h
C++
class Utils
{
    public:
    static BOOL SaveTextToFile(CString strText,CWnd *pCaller);
}

Utils.cpp
C++
#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:
C++
void MyDialogClass::OnBnClickedButtonABC()
{
    BOOL bResult = Utils::SaveTextToFile(_T("Hello world"),this);
}

C++
void MyOtherDialogClass::OnBnClickedButtonXYZ()
{
    BOOL bResult = Utils::SaveTextToFile(_T("Hello world"),this);
}
 
Share this answer
 
Comments
Arthur V. Ratz 21-Mar-16 2:54am    
Good one. +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900