c++ - Using a class callback for a custom control? -


I am creating a custom control class and since I want full control of it, I register the class

LRESULT callback OGLTOOLBAR :: ToolProc (HWND, uint, wParam, lParam)

but it does not give me

I am.

  Acdblyuend Oglulberg :: Create (Acdblyuenti guardian, Histain Acaiansti, Int * Tulvedpitiar) {if (Tulhond! = NULL) {return Tulvand; } ToolWidth = toolWidthPtr; ZeroMemory (& amp; RWC, sizeof (RWC)); Rwc.lpszClassName = TEXT ("OGLTool"); Rwc.hbrBackground = GetSysColorBrush (COLOR_BTNSHADOW); Rwc.lpfnWndProc = (WNDPROC) ToolProc; Rwc.h cursor = loaders (0, IDC_ARROWU); RegisterClass (& amp; RWC); ToolhWnd = CreateWindowEx (zero, rwc.lpszClassName, zero, WS_CHILD | WS_VISIBLE, 0, 0, * toolWidth, 900, parent, 0, zero, 0); Return toolhands; }  

What is the correct way to do this?

Thanks!

The compiler says: Error 1 error C2440: 'Type Cast': Can not 'Overloaded Function' change to 'WNDPROC'

If ToolProc is not a static member, you can not pass a member function indicator such as a callback, believe it If you want ToolProc to be a non-static function, you can create a stable member function and to store an indicator, Use GetWindowLong / SetWindowLong and GWL_USERDATA field current object (this), and a steady callback calls to individual objects callback function, which can use different objects data members.

Assuming that ToolProc is not a stable member of your OGLTOOLBAR class, you can tie this pointer to the object to handle the window, so you can do this like:

  Zero OGLTOOLBAR :: SetObjectToHWnd (HWND hWnd, lParam lParam) {LPCREATESTRUCT CS = reinterpret_cast & lt; LPCREAT ESTRUCT & gt; (LParam); Ogglurg * PWND = Reinterf_cast & lt; Ogglurg *> (CS-> LP Crate Perm); SetLastError (0); If (! SetWindowLong (hWnd, GWL_USERDATA, reinterpret_cast & lt; long & gt; (Peedblyuendi)) and amp; amp; GetLastError ()) / Do something about the error} Oglulberg * Oglulberg :: GetObjectFromHWnd (Acdblyuend Acdblyuend) {return Reinterpret_cast & lt; OGLTOOLBAR * & gt; ; (GetWindowLong (hWnd, GWL_USERDATA)); }  

And then you have a stable WndProc (or ToolProc) such member function:

  LRESULT OGLTOOLBAR :: StaticToolProc (HWND hWnd, uint uMsg, WARADAM VIPARAM, LAPARAM LPRAM) (if (UMGS == WM_NCCREATT) set object masswand (HWND, LPAMM); window * PWND = Gateobageframe (HWND); if (PWND) returns PWD-> Toolproc (HWND, UMGS, WPAMM, LPAMM) ; And use Mr. DefWindowProc (hWnd, uMsg, wParam, lParam);}  

And then when you CreateWindow OGLTOOLBAR :: Create function Call, pass reinterpret_cast & lt; zero * & gt; as lpParam argument (last one).

and each of the Overglowworld objects The StaticToolProc function for each tooltroc. Or at least I believe this should work.


Comments