Send message problem to subclassed child window

This is a discussion on Send message problem to subclassed child window within the Windows Programming forums, part of the Platform Specific Boards category; EDIT: Problem resolved. Pretty stupid of me. I had declared the "font" globally for using it multiple times (I send ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    12

    [problem resolved] Send message problem to subclassed child window

    EDIT: Problem resolved. Pretty stupid of me. I had declared the "font" globally for using it multiple times (I send the message in another function than where I first used it). I finally tried declaring it within the function I use to set up the containers and now it works fine.

    ---- Cut original problem ------ See below

    Another slight problem I also have is that the subclassed statics don't redraw correctly so in my subclassed proc I used this:
    Code:
    LRESULT CALLBACK FrameProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {   
            case WM_PAINT:
            {
                PAINTSTRUCT ps;
                HDC         hdc;
                RECT        r;
                GetClientRect (hwnd,             &r);
                hdc=BeginPaint(hwnd,            &ps);
                Rectangle     (hdc,-10,-10,800,600 );
                EndPaint      (hwnd,            &ps);
                break;
            }
            case WM_CTLCOLORSTATIC:
            {
                 return (LONG) GetStockObject(WHITE_BRUSH);
            }
    The Rectangle function is used to update the static container so that it's background stays white and doesn't get redrawn with crap when things overlap it. I'm sure this isn't the proper way of handling this.

    A screenshot of this problem (overlapping) is found here: http://programming-designs.com/error.gif

    Any help is greatly appreciated! If I haven't made myself clear enough please specify what you want to know. Thanks.
    Last edited by pdesigns; 08-01-2006 at 04:00 PM.

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Alright fixed my original problem but am hoping to get answers on my 2nd.

    Regards.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    >>Rectangle (hdc,-10,-10,800,600 );

    Its not possible (AFAIK) to draw off the edge of a DC (starts at 0,0 through to x,y).

    Check what the PAINTSTRUCT RECT element is. ie ps.rsPaint.

    If this is not a rect of sufficent size (x>=800, y>=600) then you can not draw the rect you are trying to.

    How are you sending the WM_PAINT msg?

    InvalidateRect(hWnd, NULL, TRUE); //update the whole client area and background
    UpdateWindow(hWnd);//send WM_PAINT directly to the callback, bypassing the OS msg que
    "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

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Quote Originally Posted by novacain
    >>Rectangle (hdc,-10,-10,800,600 );

    Its not possible (AFAIK) to draw off the edge of a DC (starts at 0,0 through to x,y).

    Check what the PAINTSTRUCT RECT element is. ie ps.rsPaint.

    If this is not a rect of sufficent size (x>=800, y>=600) then you can not draw the rect you are trying to.

    How are you sending the WM_PAINT msg?

    InvalidateRect(hWnd, NULL, TRUE); //update the whole client area and background
    UpdateWindow(hWnd);//send WM_PAINT directly to the callback, bypassing the OS msg que
    Starting at -10, -10 prevents the border of the rectangle from being seen when its drawn in the area. I did this out of laziness so I wouldn't have to add the extra code to remove the border.

    The WM_PAINT message doesn't get sent via the program, only gets sent as it would for any other application on it's own. I'm just trying to get it to refresh properly without having to touch it's DC.

    Will try the code you provided.

    Edit: Didn't work =/
    Last edited by pdesigns; 08-02-2006 at 09:45 AM.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    What does the rect in the paint struct contain?

    How do you draw the screen originally?


    >>The WM_PAINT message doesn't get sent via the program,

    All my applications send themselves paint msgs. How else do you know when to redraw the screen because your app has changed the display?

    You must also set up so paint msgs generated externally will be processed as quickly as possible (ie only draw the area that was invalid, in the paint struc rect)

    >>only gets sent as it would for any other application on it's own.

    Sorry not sure what you mean exactly. As I said other apps send themselves paint msgs all the time.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in message handling VC++
    By 02mca31 in forum Windows Programming
    Replies: 5
    Last Post: 01-16-2009, 08:22 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. buttons won't work when in child window!?
    By psychopath in forum Windows Programming
    Replies: 5
    Last Post: 06-17-2004, 02:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21