Thread: my wndProc is out of scope

  1. #31
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    Thanks for giving me examples to help me and i understand your last example clearly. But i hope this next set of qn wont make ur blood boil:
    So what is it that make my virtual wndProc() not considered a window procedure and that it's fine to call it directly? Is it just because it is virtual? What if i make it static? I will to call it with CallWindowProc()?

  2. #32
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I think you're reading WAY too much into this "don't call a WNDPROC" directly stuff. It's important only to allow Windows to function correctly as it needs to do certain default actions. Callbacks are simply functions that Windows uses to call YOU. If it was not a function that you at some point give to windows in the form of a pointer, then you can say it is not a WNDPROC.

    There's no magic to it. Your virtual wndproc is nothing more than just another function that gets called from within your code. Windows never gets its grubby little hands on it. Therefore, windows can't call back with it.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #33
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by Raison
    So what is it that make my virtual wndProc() not considered a window procedure and that it's fine to call it directly? Is it just because it is virtual? What if i make it static? I will to call it with CallWindowProc()?
    In addition to the thorough discussion given by FYB, also consider:

    A window procedure is of type WNDPROC which is typedef'd in winuser.h as follows:
    Code:
    typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
    ie. is a pointer to a function taking four parameters - HWND, UINT, WPARAM and LPARAM and returning an LRESULT. CALLBACK is just a placeholder for the stdcall calling convention. Any c++ class 'window procedure' clearly doesn't match the type WNDPROC because it comes encumbered with this so you can't use it directly in winapi functions that require a WNDPROC as a parameter (functions such as CallWindowProc, for example). When you declare the c++ class function as static then it matches the type and can be safely used (no implicit this ).

    If you want more information about window procedures in general then start at this msdn page. It includes information on window subclassing, superclassing and when and how to use each.

    Refer back to the thread that Dante suggested earlier in this thread for further discussion, links and examples.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #34
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    ok, I am going to conclude like this:

    1.My virtual wndProc is encumbered with "this" pointer, so it is not a WNPROC. Therefore, i just call it directly.

    2.For any CALLBACK function i need to call in my static wndProc to process a window msg, i will forward that msg to the CALLBACK function using CallWindowProc.

    So my last qn is, should i make that virtual wndProc a CALLBACK? It doesnt have to be one,right? or it makes no difference?

  5. #35
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    if you don't plan on giving it to windows, I don't see why you would make it in the CALLBACK form. Personally, I think leaving it in the class is ideal because you are going to be manipulating data inside the object I assume.

    Although I should point out, even if you make it a static or global in the form of a CALLBACK, that doesn't mean it is actually a callback function. It doesn't become a callback function until you give a pointer to it to Windows.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #36
    Registered User
    Join Date
    Sep 2003
    Posts
    133
    yes i get that. As long as i am not registering a function in window class as a WNDPROC or use that function to replace a WNDPROC using SetWindowLong, I wont have to make it a CALLBACK function and or call it using CallWindowProc. Because only Windows need to call functions by the stdcall way.

    Thanks for all the help, FYB,Ken and Dante.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM
  5. Putting WndProc into a class?
    By Eber Kain in forum Windows Programming
    Replies: 3
    Last Post: 12-13-2001, 06:46 PM