Click to See Complete Forum and Search --> : Globals


timber
July 28th, 1999, 03:43 PM
Hi,
I have a modeless dialog which according to the utility Spy++ has no parent. I need to be able to set focus to this dialog across files. What I mean is if I'm in another code file I may need to access this dialog's members. I can't seem to find a way to gain access outside of the file that creates the dialog. Everything is "0".
Could someone show me how to make a global varialble that has a pointer to the dialog?

Thanks
Steve

Wayne Fuller
July 28th, 1999, 04:02 PM
Put it in your App class so you will have to access it through it.
For example

class CMyApp : public CWinApp
{
...
public:
CMyDialog * m_MyDialog;
...
};

Make sure you set it to NULL in the constructor and when it is destroyed. If you do that then now you can do the following in any project file.

if ( AfxGetApp()->m_MyDialog != NULL )
{
// Get my data
}
else
{
// I don't know maybe create it
}

Is this what you are talking about?

Wayne

timber
July 28th, 1999, 05:07 PM
Wayne,
does it make a difference if my app is a Dll and another third party app is running and using my dll?

Steve

Wayne Fuller
July 28th, 1999, 05:42 PM
If it is a non COM DLL then no it does not matter, because your code is loaded in the same memory space as the exe. If it is a COM Dll, then ?. When I answered your question, I thought it was in a regular EXE. If it is in a DLL then you would not call AfxGetApp(). What I would do is just declare a global pointer to it in the DLL and manipulate it that way. Just make sure you manage it the same way with setting it to NULL if it is not used.

Wayne

timber
July 28th, 1999, 05:48 PM
Wayne,
I get a m_MyDialog not a member of CWinApp error.

Steve

timber
July 28th, 1999, 05:54 PM
Wayne,
My dll is part of the same memory space. You need to explain how to make a global pointer. I don't understand where to put the declaration or the assignment. Everywhere I've tried the variable isn't seen by my other files.

Steve

Wayne Fuller
July 29th, 1999, 07:49 AM
First of all, by your other files, you do mean in the same project, right?

Let me know,

Wayne