Object Required??

Started by
4 comments, last by Sand_Hawk 22 years, 1 month ago
Hi, I have made my WinProc a member of one of my classes. Now when an event occurs I need to call a function do to stuff. But this always requires an object. It says: "Member spelers cannot be used without object". My WinProc(just the standard windows one) is implemented like this:
  
LRESULT CALLBACK CWindow::WinProc(...)
...
   Case 1001:
   {
      for (lTeller = 0; lTeller <= MAX_PLAYERS; lTeller++)
         Spelers[lTeller] = LegeSpeler;
      return(0);
   }break;

  
Spelers is an (private) variabele of the CWindow class. Why does this goed wrong? I already tried it with a function but that one failed too. Sand Hawk Member of the Stupid Coders. http://www.stupidcoders.cjb.net -Earth is 98% full. Please delete anybody you can.
----------------(Inspired by Pouya)
Advertisement
This question gets asked extremely often, I''m sure that you''ll find your answer if you do a search on this forum for something like ''WndProc member class''. Or you could just go to www.relisoft.com/win32
On that site they don''t place the WinProc inside the class, like I did. Can someone point me directly to an good tutorial/post that explains how I can fix this error?

Sand Hawk

Member of the Stupid Coders.
http://www.stupidcoders.cjb.net

-Earth is 98% full. Please delete anybody you can.
----------------(Inspired by Pouya)
The variables you used are nonstatic and your function is a static member function. To access the members, an instance of the class must be provided and accessed using the . or -> operators.

Edited by - SilentCoder on February 16, 2002 11:49:46 AM
http://www.gamedev.net/community/forums/topic.asp?topic_id=59171

I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
I admit that the examples on www.relisoft.com aren''t very clear or good, but the second tutorial (generic) does explain what you are looking for: getting to a certain window instance''s data in a static or global WindowProc.

In the tutorial each window has a controller, CreateWindow/SetWindowLong are used to couple the pointer to the controller with the window handle, the global WindowProc can get to the controller by using the windowhandle and GetWindowLong.

You probably don''t want to use the controller, but that doesn''t really matter: the point is that you can attach a pointer to anything to the window handle. In your case, you probably want a CWindow pointer, once you can reach the CWindow instance, you can easily call a non-static WindowProc for that instance, pWnd->WindowProc().

This topic is closed to new replies.

Advertisement