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. C / C++ / MFC
  4. Window Class Encapsulation and WNDPROC

Window Class Encapsulation and WNDPROC

Scheduled Pinned Locked Moved C / C++ / MFC
oopquestion
8 Posts 3 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.
  • Q Offline
    Q Offline
    qmuffs
    wrote on last edited by
    #1

    I cannot figure out a way to get the WndProc as a member function of my window class I am building. Any Suggestions? :confused: QMuffs

    J 1 Reply Last reply
    0
    • Q qmuffs

      I cannot figure out a way to get the WndProc as a member function of my window class I am building. Any Suggestions? :confused: QMuffs

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Do you mean you're designing your own C++ framework for encapsulation of Win32 windows? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      Q 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        Do you mean you're designing your own C++ framework for encapsulation of Win32 windows? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        Q Offline
        Q Offline
        qmuffs
        wrote on last edited by
        #3

        Yes, I'm designing my own. It has to do with the hidden 'this' argument that is passed to member functions of a class. It gives me this error. Compiling... cWindow.cpp c:\projects\cwindow\cwindow.h(86) : error C2440: 'type cast' : cannot convert from '' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)' None of the functions with this name in scope match the target type Error executing cl.exe. cWindow.exe - 1 error(s), 0 warning(s) QMuffs

        A J 2 Replies Last reply
        0
        • Q qmuffs

          Yes, I'm designing my own. It has to do with the hidden 'this' argument that is passed to member functions of a class. It gives me this error. Compiling... cWindow.cpp c:\projects\cwindow\cwindow.h(86) : error C2440: 'type cast' : cannot convert from '' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)' None of the functions with this name in scope match the target type Error executing cl.exe. cWindow.exe - 1 error(s), 0 warning(s) QMuffs

          A Offline
          A Offline
          alex barylski
          wrote on last edited by
          #4

          Use static member functions "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

          Q 2 Replies Last reply
          0
          • A alex barylski

            Use static member functions "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

            Q Offline
            Q Offline
            qmuffs
            wrote on last edited by
            #5

            Would that make the call to it unique to that instance? If not, how could I make it unique. QMuffs

            1 Reply Last reply
            0
            • Q qmuffs

              Yes, I'm designing my own. It has to do with the hidden 'this' argument that is passed to member functions of a class. It gives me this error. Compiling... cWindow.cpp c:\projects\cwindow\cwindow.h(86) : error C2440: 'type cast' : cannot convert from '' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)' None of the functions with this name in scope match the target type Error executing cl.exe. cWindow.exe - 1 error(s), 0 warning(s) QMuffs

              J Offline
              J Offline
              Joaquin M Lopez Munoz
              wrote on last edited by
              #6

              As you pointed out, the problem lies in the hidden this parameter. One usual workaround to this goes as follows. Store the this parameter into the internal data kept by HWNDs with SetWindowLong(hwnd,GWL_USERDATA,reinterpret_cast<LONG>(this)) and set as your window proc a static function that merely recovers the this parameter and forwards the call to the real, per-object window proc:

              class cwindow
              {
              cwindow(HWND hwnd) // constructor
              {
              SetWindowLong(hwnd,GWL_USERDATA,reinterpret_cast<LONG>(this));
              }
               
              static LRESULT CALLBACK stub_WindowProc(
              HWND hwnd,
              UINT uMsg,
              WPARAM wParam,
              LPARAM lParam)
              {
              cwindow object=reinterpret_cast<object*>(GetWindowLong(hwnd,GWL_USERDATA));
              return object->WindowProc(hwnd,uMsg,wParam,lParam);
              }
               
              LRESULT CALLBACK stub_WindowProc(
              HWND hwnd,
              UINT uMsg,
              WPARAM wParam,
              LPARAM lParam) // the "real" window proc
              {
              ...
              }
              };

              Get the idea? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

              Q 1 Reply Last reply
              0
              • A alex barylski

                Use static member functions "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                Q Offline
                Q Offline
                qmuffs
                wrote on last edited by
                #7

                Thank you for your help. QMuffs

                1 Reply Last reply
                0
                • J Joaquin M Lopez Munoz

                  As you pointed out, the problem lies in the hidden this parameter. One usual workaround to this goes as follows. Store the this parameter into the internal data kept by HWNDs with SetWindowLong(hwnd,GWL_USERDATA,reinterpret_cast<LONG>(this)) and set as your window proc a static function that merely recovers the this parameter and forwards the call to the real, per-object window proc:

                  class cwindow
                  {
                  cwindow(HWND hwnd) // constructor
                  {
                  SetWindowLong(hwnd,GWL_USERDATA,reinterpret_cast<LONG>(this));
                  }
                   
                  static LRESULT CALLBACK stub_WindowProc(
                  HWND hwnd,
                  UINT uMsg,
                  WPARAM wParam,
                  LPARAM lParam)
                  {
                  cwindow object=reinterpret_cast<object*>(GetWindowLong(hwnd,GWL_USERDATA));
                  return object->WindowProc(hwnd,uMsg,wParam,lParam);
                  }
                   
                  LRESULT CALLBACK stub_WindowProc(
                  HWND hwnd,
                  UINT uMsg,
                  WPARAM wParam,
                  LPARAM lParam) // the "real" window proc
                  {
                  ...
                  }
                  };

                  Get the idea? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                  Q Offline
                  Q Offline
                  qmuffs
                  wrote on last edited by
                  #8

                  Thank you for your help QMuffs

                  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