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. How to declare WindowProc function in class

How to declare WindowProc function in class

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 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.
  • M Offline
    M Offline
    mmhu
    wrote on last edited by
    #1

    I declared WindowProc function in public section: static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { } But I receive following errors: c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'CALLBACK' c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'WindowProc' c:\ABE\DTS\Form1.h(51) : error C2501: 'DTS::Form1::CALLBACK' : missing storage-class or type specifiers c:\ABE\DTS\Form1.h(51) : error C2061: syntax error : identifier 'HWND' c:\ABE\DTS\Form1.h(84) : warning C4183: 'WindowProc': missing return type; assumed to be a member function returning 'int' How shall I solve it????

    S 1 Reply Last reply
    0
    • M mmhu

      I declared WindowProc function in public section: static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { } But I receive following errors: c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'CALLBACK' c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'WindowProc' c:\ABE\DTS\Form1.h(51) : error C2501: 'DTS::Form1::CALLBACK' : missing storage-class or type specifiers c:\ABE\DTS\Form1.h(51) : error C2061: syntax error : identifier 'HWND' c:\ABE\DTS\Form1.h(84) : warning C4183: 'WindowProc': missing return type; assumed to be a member function returning 'int' How shall I solve it????

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      Hmm. You don't have HWND defined. This would imply that you haven't included the windows.h header...

      Steve S Developer for hire

      M 1 Reply Last reply
      0
      • S Steve S

        Hmm. You don't have HWND defined. This would imply that you haven't included the windows.h header...

        Steve S Developer for hire

        M Offline
        M Offline
        mmhu
        wrote on last edited by
        #3

        Thanks... I added windows.h and ifndef undef to my code and make it work now. :)

        M 1 Reply Last reply
        0
        • M mmhu

          Thanks... I added windows.h and ifndef undef to my code and make it work now. :)

          M Offline
          M Offline
          mmhu
          wrote on last edited by
          #4

          I declared WndProc() as static public function in a form class. It needs to access non-static member function when wparam is DBT_DEVICEARRIVAL. This non-static function will modify the form panel displaying content. But static member function can only access other static member functions. How shall I solve this problem???

          S 1 Reply Last reply
          0
          • M mmhu

            I declared WndProc() as static public function in a form class. It needs to access non-static member function when wparam is DBT_DEVICEARRIVAL. This non-static function will modify the form panel displaying content. But static member function can only access other static member functions. How shall I solve this problem???

            S Offline
            S Offline
            Steen Krogsgaard
            wrote on last edited by
            #5

            (Disclaimer: This is for VC++6.0 and for MFC, and I'm pretty sure that this is not exactly what you use. Anyway, it may give you some ideas.) (Disclaimer: Untested code) You have the window handle as a parameter to WndProc, so it's easy to get the MFC C++ class corresponding to the window:

            static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
            {
            if (wparam == DBT_DEVICEARRIVAL) {
            CYourWnd* wnd = (CYourWnd*)CWnd::FromHandlePermanent(hWnd);
            if ((wnd != NULL) && (wnd->IsKindOf(RUNTIME_CLASS(CYourWnd))) {
            // access CYourWnd members by wnd->
            }
            }
            }

            More on-beat C++ programmers will probably object to using the old-style typecasts, but it's safe when checking wnd for NULL and checking the runtime class.

            Cheers Steen. "Are you gonna check your makeup when you're done whining?" John Simmons, 05/31/2006

            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