Using WTL controls in an MFC app
-
I've been trying to use WTL controls in my large MFC based project. I've got the WTL7 libraries installed on my VC6 system. I can compile the WTL ctrl's sample code just fine, but when I try using it with MFC code, I'm getting all sorts of namespace collisions. CEdit, CButton, etc. Can WTL and MFC code be intermingled? Does anyone have an example of how to do this? I'm guessing careful use of "using ... { ... }" is the key, or being more explicit with class names.
-
I've been trying to use WTL controls in my large MFC based project. I've got the WTL7 libraries installed on my VC6 system. I can compile the WTL ctrl's sample code just fine, but when I try using it with MFC code, I'm getting all sorts of namespace collisions. CEdit, CButton, etc. Can WTL and MFC code be intermingled? Does anyone have an example of how to do this? I'm guessing careful use of "using ... { ... }" is the key, or being more explicit with class names.
WTL7.1 in an ATL7 environment (VS.NET and later) will assume there is a global variable called
_AtlBaseModule
. I can't remember all functions it must have, but you'll figure it out as you see the compilation errors. I know it needs a function calledGetResourceHandle()
. It should just return theHINSTANCE
for your resources. I would suggest that you do something like this in your stdafx.h:#include "youratlbasemodule.h"
extern YourAtlBaseModuleEmulator _AtlBaseModule;
// WTL-includes
#include <atlapp.h>
#include <atlctrls.h>
...And then in your youratlbasemodule.h:
class class YourAtlBaseModuleEmulator {
HINSTANCE m_hInstance;
public:
void SetResourceInstance(HINSTANCE hInstance) { m_hInstance = hInstance; }
HINSTANCE GetResourceInstance() { return m_hInstance; }
};And then in your "main" cpp file:
#include "youratlbasemodule.h"
...
YourAtlBaseModuleEmulator _AtlBaseModule;
...
// somewhere in the code where you have access to the
// resource instance (typically the HINSTANCE of your EXE)
_AtlBaseModule.SetResourceInstance(hInstance);I think something along those lines should work. I have never done it before. :) -- He just smiled and gave me a vegemite sandwich.
-
I've been trying to use WTL controls in my large MFC based project. I've got the WTL7 libraries installed on my VC6 system. I can compile the WTL ctrl's sample code just fine, but when I try using it with MFC code, I'm getting all sorts of namespace collisions. CEdit, CButton, etc. Can WTL and MFC code be intermingled? Does anyone have an example of how to do this? I'm guessing careful use of "using ... { ... }" is the key, or being more explicit with class names.
aha, CodeProject to the rescue. http://www.codeproject.com/wtl/mix_wtl_mfc.asp Apparently there are some #define's you can set to cause WTL to not define symbols that will clash with MFC (which puts everything in the global namespace)
-
aha, CodeProject to the rescue. http://www.codeproject.com/wtl/mix_wtl_mfc.asp Apparently there are some #define's you can set to cause WTL to not define symbols that will clash with MFC (which puts everything in the global namespace)
Please not that is for VC6/ATL3. It may not work with your development environment if it's VS.NET/ATL7. Come to think of it, there is some wizard in VS.NET that allows "adding ATL support to MFC projects". Please try that before trying my previous response. And the #define stuff mentioned in the article too. -- He just smiled and gave me a vegemite sandwich.
-
WTL7.1 in an ATL7 environment (VS.NET and later) will assume there is a global variable called
_AtlBaseModule
. I can't remember all functions it must have, but you'll figure it out as you see the compilation errors. I know it needs a function calledGetResourceHandle()
. It should just return theHINSTANCE
for your resources. I would suggest that you do something like this in your stdafx.h:#include "youratlbasemodule.h"
extern YourAtlBaseModuleEmulator _AtlBaseModule;
// WTL-includes
#include <atlapp.h>
#include <atlctrls.h>
...And then in your youratlbasemodule.h:
class class YourAtlBaseModuleEmulator {
HINSTANCE m_hInstance;
public:
void SetResourceInstance(HINSTANCE hInstance) { m_hInstance = hInstance; }
HINSTANCE GetResourceInstance() { return m_hInstance; }
};And then in your "main" cpp file:
#include "youratlbasemodule.h"
...
YourAtlBaseModuleEmulator _AtlBaseModule;
...
// somewhere in the code where you have access to the
// resource instance (typically the HINSTANCE of your EXE)
_AtlBaseModule.SetResourceInstance(hInstance);I think something along those lines should work. I have never done it before. :) -- He just smiled and gave me a vegemite sandwich.