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. Managed C++/CLI
  4. How to use WndProc or WindowsProc function

How to use WndProc or WindowsProc function

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++dotnettutorialquestion
7 Posts 2 Posters 1 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'm writing VC++ .net framework code. I need to retrieve the windows WM_DEVCHANGE message Shall I use virtual void WndProc( Message* m ) override function or LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) function?? How shall I add either of them to my Form class??? May you write down the format?

    M 1 Reply Last reply
    0
    • M mmhu

      I'm writing VC++ .net framework code. I need to retrieve the windows WM_DEVCHANGE message Shall I use virtual void WndProc( Message* m ) override function or LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) function?? How shall I add either of them to my Form class??? May you write down the format?

      M Offline
      M Offline
      Milton Karimbekallil
      wrote on last edited by
      #2

      No need to go for WindowPrc as this is an additional work. Becase its already available as part of the framework class library. Given below is a working sample on VS2005. Copy this code in to the .h file of your Form. virtual void WndProc( Message% m ) override { // Listen for operating system messages. switch ( m.Msg ) { case WM_ACTIVATEAPP: this->Invalidate(); break; } Form::WndProc( m ); } you have to include windows.h for WM_ACTIVATEAPP to work. cheers..Milton Kb.

      M 1 Reply Last reply
      0
      • M Milton Karimbekallil

        No need to go for WindowPrc as this is an additional work. Becase its already available as part of the framework class library. Given below is a working sample on VS2005. Copy this code in to the .h file of your Form. virtual void WndProc( Message% m ) override { // Listen for operating system messages. switch ( m.Msg ) { case WM_ACTIVATEAPP: this->Invalidate(); break; } Form::WndProc( m ); } you have to include windows.h for WM_ACTIVATEAPP to work. cheers..Milton Kb.

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

        m.LParam is a System::IntPtr, I have problem to convert m.LParam to a PDEV_BROADCAST_HDRstructure. I tried: PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m->LParam); compiler gives error: error C2440: 'type cast' : cannot convert from 'System::IntPtr' to 'PDEV_BROADCAST_HDR'No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called I tried: lpdb = (PDEV_BROADCAST_HDR)(m->GetLParam(__typeof(PDEV_BROADCAST_HDR))); compiler generates following error: error C3181: 'PDEV_BROADCAST_HDR' : invalid operand for __typeof, expected a fully defined managed type What is the correct way?

        M 1 Reply Last reply
        0
        • M mmhu

          m.LParam is a System::IntPtr, I have problem to convert m.LParam to a PDEV_BROADCAST_HDRstructure. I tried: PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m->LParam); compiler gives error: error C2440: 'type cast' : cannot convert from 'System::IntPtr' to 'PDEV_BROADCAST_HDR'No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called I tried: lpdb = (PDEV_BROADCAST_HDR)(m->GetLParam(__typeof(PDEV_BROADCAST_HDR))); compiler generates following error: error C3181: 'PDEV_BROADCAST_HDR' : invalid operand for __typeof, expected a fully defined managed type What is the correct way?

          M Offline
          M Offline
          Milton Karimbekallil
          wrote on last edited by
          #4

          try PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m.LParam.ToPointer()); cheers..Milton KB.

          M 1 Reply Last reply
          0
          • M Milton Karimbekallil

            try PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m.LParam.ToPointer()); cheers..Milton KB.

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

            Thanks a lot Milton, It works. Vicky

            M 1 Reply Last reply
            0
            • M mmhu

              Thanks a lot Milton, It works. Vicky

              M Offline
              M Offline
              Milton Karimbekallil
              wrote on last edited by
              #6

              Guess u forgot the fact that C++/CLI ^ pointer operator and the tracking reference operator % are not equivalent to its native like counterpart operators * pointer and the & reference. Actually ^ is a handle to its managed heap object and its not a pointer to that. But the handle can provide us with the underlying pointer just like we did. cheers..Milton KB

              M 1 Reply Last reply
              0
              • M Milton Karimbekallil

                Guess u forgot the fact that C++/CLI ^ pointer operator and the tracking reference operator % are not equivalent to its native like counterpart operators * pointer and the & reference. Actually ^ is a handle to its managed heap object and its not a pointer to that. But the handle can provide us with the underlying pointer just like we did. cheers..Milton KB

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

                Yup, You are right. Thanks for the detail explaination for C++/CLI handle which is new to me. vicky

                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