How to use WndProc or WindowsProc function
-
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?
-
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?
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. -
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.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.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?
try
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m.LParam.ToPointer());
cheers..Milton KB. -
try
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m.LParam.ToPointer());
cheers..Milton KB. -
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 -
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