Thread: Messages problem...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up Messages problem...

    I've got another problem... I have setup my window with an empty child window by doing this:

    Code:
    HWND hchild = CreateWindow( "STATIC", "", WS_CHILD | WS_MAXIMIZE | WS_VISIBLE, 0, 0, 0, 0, hParent, (HMENU)ID_CHILD, GetInstance(), NULL );
    This works all find and dandy, but I also have buttons in this child window. When the button is pressed, I suspect that the message is sent to the empty child window... but I don't have a window procedure to process the message. Is there some way that I redirect the button's message to another window when I declare the button like this?:

    Code:
    CreateWindow( WC_BUTTON, "A Button", WS_VISIBLE | WS_CHILD | WS_TABSTOP, 0, 0, 90, 20, hchild, (HMENU)ID_BUTTON, GetInstance(), NULL );
    Thanks.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Have you tried SetWindowLongPtr() with the GWLP_WNDPROC flag?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Thanks for the reply. I tried doing it like:
    Code:
    SetWindowLongPtr( hParent, GWLP_WNDPROC, (LONG_PTR)WndProc );
    and it compiles fine, but the button doesn't appear anymore. It has literally vanished from the window. Is this good news?

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    You should save the old wndproc (the return of the SetWindowLongPtr) and call it at the end of the new one with CallWindowProc, so the default processing of all the messages you don't want to handle is done.

    Maybe helpful links:
    Safe subclassing
    About Window Procedure Subclassing

  5. #5
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Yes, that gave me enough to work with and it works fine. Thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console problem
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 12-22-2005, 10:41 AM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  4. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM