Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Using WTL controls in an MFC app

Using WTL controls in an MFC app

Scheduled Pinned Locked Moved ATL / WTL / STL
c++tutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    armentage
    wrote on last edited by
    #1

    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.

    J A 2 Replies Last reply
    0
    • A armentage

      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.

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      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 called GetResourceHandle(). It should just return the HINSTANCE 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.

      A 1 Reply Last reply
      0
      • A armentage

        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.

        A Offline
        A Offline
        armentage
        wrote on last edited by
        #3

        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)

        J 1 Reply Last reply
        0
        • A armentage

          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)

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            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 called GetResourceHandle(). It should just return the HINSTANCE 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.

            A Offline
            A Offline
            armentage
            wrote on last edited by
            #5

            Thanks for the explicit examples! There are so many hot (trendy?) WTL controls out there that I'd love to use in my apps, but getting the code to compile together has always been a bottle neck.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups