Friday 15 March 2013

c++ - Why can't my WndProc be in a class? -


It seems that it should be very simple. I have my class:

  class simple {public: LRESULT callback WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {...}};   

and my WinMain :

  int WINAPI WinMain (Histyine H Instance, Histores H Prev Instance, LPT command line, int CMD Show) {simple * simple = new simple (); ... wndClass.lpfnWndProc = Simple-> WndProc; ...}   

Whenever I try, I get:

  error C2440: '=': 'LRESULT (__stdcall Simple: What is the reason that I can not do this in a  WndProc  class? * * ('* * * * * * *] It seems to be really useful.   

c - a it to do pointer To use, and usually pass it as a hidden parameter As a result, an N-logic member task will be similar to one (n + 1) -regulation free function, which means that your code is trying to call WndProc , arguments The wrong number will be in. / P>

You can declare WndProc as a stable member function, which will be this This code should work by terminating the pointer:

  class simple {public: static LRESULT callback WndProc (hwnd h Bludi, Uaianti message, WPARAM wParam, LPARAM lParam) {...}}; Int WINAPI WinMain (Histyine H Instance, Histones HAPEInstance, LPT Commandline, Int CMD Show) {Simple * Simple = New Simple (); ... wndClass.lpfnWndProc = Simple-> WndProc; ...}   

Of course, this means that you can not reach the classroom areas directly. You can get around this by embedding a pointer in the class in the extra bytes reserved for each window instance around it, perhaps by using once you do this, you write something like this to the Receiver Object Pointer Can be retrieved:

  class simple {public: static LRESULT callback WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM LParam) {simple * me = stabilized_test & lt; Simple * & gt; (GetWondo Longprint (HWD, GWLP_USRDATA)); If (i) return me-> actual WPRCC (HWD, MMS, WPAM, LPAMM); Return DefWindowProc (hwnd, msg, wParam, lParam); } Private: LRESULT callback realWndProc (HWND hwnd, UINT msg, WPARam wParam, LPARAM lParam) {// yay! I am a member function! }};   

Hope it helps!

No comments:

Post a Comment