Results 1 to 6 of 6

Thread: DefWindow, CallWindow..wut Proc??

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    DefWindow, CallWindow..wut Proc??

    Alright, I know I asked this before, but I never really got a straightforward understandable answer and seeing I am beginning to run into problems.....

    All my controls are subclassed.
    There is a static message router which derives the right control class from the window long and calls a private wnd proc.

    All I want to know is when to call: CallWindowProc and DefWindowProc.

    does it matter?
    is there a case where I only call one?
    is there a case where I call neither?
    do I always call CallWindowProc()?
    What does CallWindowProc return usually?
    Can I deal with CallWindowProc returning 0 to call DefWindow?


    whenever I send messages to my subclassed controls, it never worked out right because I was always returning 1 or 0 depending on if a command was found. Instead I have to return CallWindowProc from the private WndProc to get the data from the sendmessage.

    So, if I call CallWindowProc should I still call DefWindowProc?

    If I deal with a message, any message...should I
    return 0;
    return DefWindowProc first or CallWindowProc first...neither...


    This is beginning to confuse me, and I am way to far into this project to get confused on this subject now.


    This is what the basics look like
    PHP Code:
    //------------------
    //Msg Router
    //------------------
    LRESULT CALLBACK ControlSet::MsgRouter(HWND hwndUINT msgWPARAM wParamLPARAM lParam)
    {
        static 
    long iRet 0;


        
    ControlSetcset=0;
        
    cset reinterpret_cast<ControlSet *>(GetWindowLong(hwndGWL_USERDATA));
        
        if (
    cset)    iRet cset->WndProc(hwndmsgwParamlParam);
        else        
    iRet=0;

        
    cset 0;


        if (
    iRet == 0)
            return 
    DefWindowProc(hwndmsgwParamlParam);
        else
            return 
    iRet;
    }


    //----------------------
    //Private Subclassed WndProc
    //----------------------
    long ListBox::WndProc(HWND hwndUINT msgWPARAM wParamLPARAM lParam)
    {
        
    //check through user-defined events
        
    for (iterEvent m_Events.begin(); iterEvent != m_Events.end(); iterEvent++)
            if ( 
    msg == (*iterEvent).CallWord )        return (*iterEvent).p();
        
        
    //switch through pre-defined events
        
    switch (msg)
        {
            case 
    WM_LBUTTONDOWN:
            {
                
    typedef void (*VoidType)();
                
    VoidType lpFunc = (VoidType)EventClick;
                if (
    EventClick != 0lpFunc();
            }
            break;
        }
        
        return    
    CallWindowProc(m_OldWndProchwndmsg,wParamlParam); 



    HELP!!!!!!!!
    Last edited by Halsafar; Oct 31st, 2004 at 01:53 PM.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  2. #2
    Member
    Join Date
    May 2004
    Posts
    44
    DefWindowProc just calls the default handler for the window, and CallWindowProc calls the original window procedure that the system used for the control before you subclassed it. Generally, you _want_ to call this in your subclassed controls. However, in some situations I have used DefWindowProc and then return'd 0 (return 0 if you want to ignore the message).

  3. #3

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Ah, so in my subclassed wndproc for a listbox for example.
    If I send LB_GETTEXTLEN, whatever my static MsgRouter WndProc returns is what SendMessage(..,..,..,..) returns.

    So, if I choose to not handle LB_GETTEXTLEN in my wndproc, then I should let the default system wndproc (CallWindowProc) do it?
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Correct.

    You never call DefWindowProc when subclassing. You call CallWindowProc for unhandled or partially handled messages, i.e. when you still want the default action to happen.

    What CallWindowProc returns is entirely dependent on the message and should not concern you. You decided to pass the message on; you shouldn't worry what is done with it then.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Never call DefWindowProc eh???

    I have it set up to do both if a message is unhandled or at least always CallWindowProc....

    So if I am intend to handle a subclassed message I better be sure of dealing with it right or in the least put my bit of code there and pass it on to the CallWindowProc afterwards.

    Alrighty, thanks CB.

    Edit: ONe more things, what does CallWindowProc return, a long? a DWORD? wut is a safe variable to use?
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It returns an LRESULT, like all window procedures. But you usually don't care because you simply write your WndProc like this:
    Code:
    LRESULT SubclassWndProc(HWND h, UINT m, WPARAM w, LPARAM l)
    {
      switch(m)
      {
      case WM_IWANTTHIS:
        handleThis(h, w, l);
        return 0;  // This stops handling completely.
    
      case WM_IMONITORTHIS:
        log("Monitoring...");
        break; // Message not really handled, so let oldWndProc have it.
      }
      // Everything else, too, is passed to oldWndProc.
    
      // And please don't ask me why you have to go through the indirection.
      return CallWindowProc(oldWndProc, h, m, w, l);
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width