How to declare global variables or functions in MFC
We can declare static member variables or member functions in CWINAPP derived classes, so you can access them from all classes:
E.g:
// myapp.h
Class CMYAPP: Public CWINAPP
{
PUBLIC:
CMYAPP ();
Static int g_nmyvariable; // Declare a global variable
Static void g_myfunction (); // Declare a global function
...
ETC
...
}
// myapp.cpp
INT CMYAPP :: g_nmyvariable = null; // global variable definition and initialization CMYAPP :: g_myfunction () // global function definition
{
}
Now, this variable and function can be accessed from other classes:
CMYAPP :: G_nmyvariable and cmyapp :: g_myfunction