Thread: WM_PAINT problem

  1. #1

    WM_PAINT problem

    I'm creating a new control to add to my growing library of custom controls, this one is a menu bar type one to replace rebar because it doesn't work well enough for me.

    I've already hit a snag though. I was just setting up the basics and I whent to test it when I found that the bar dissapears when you move the bottom of the window just behind the application bar at the bottom of the screen.



    And, when you maximize another app and the minimize it (so that it covers the window) the menu bar is there again!

    This code paints the window-
    Code:
    void DrawMCB(HWND hwnd,HDC dc)
    {
      
      //Setup the bounding rect
      RECT rc;
      GetWindowRect(hwnd,&rc);
      rc.right-=rc.left;
      rc.left = 0;
      rc.bottom-=rc.top;
      rc.top = 0;
      
      //Create pens and brushes
      HPEN dark = CreatePen(PS_INSIDEFRAME,1,GetSysColor(COLOR_3DDKSHADOW));
      HPEN light = CreatePen(PS_INSIDEFRAME,1,GetSysColor(COLOR_3DHILIGHT));
      HPEN none = CreatePen(PS_NULL,1,RGB(0,0,0));
      HBRUSH face = CreateSolidBrush(RGB(223,223,223));
      
      //Fill it in
      FillRect(dc,&rc,face);
      
      //Draw the basic frame
      SelectObject(dc,light);
      line(rc.left,rc.top,rc.right,rc.top);
      line(rc.left,rc.top,rc.left,rc.bottom);
      SelectObject(dc,dark);
      line(rc.left,rc.bottom-1,rc.right,rc.bottom-1);
      line(rc.right-1,rc.bottom,rc.right-1,rc.top);
    }
    This is the procedure for it -
    Code:
    LRESULT CALLBACK MCBProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
      switch(msg)
      {
      case WM_SIZE:
      {
        //Make it span the parent's width!
        RECT rc;
        GetWindowRect(GetParent(hwnd),&rc);
        int width = rc.right-=rc.left;
        GetWindowRect(hwnd,&rc);
        int height = rc.bottom-rc.top;
        SetWindowPos(hwnd,HWND_TOPMOST,0,0,width,height,SWP_NOZORDER);
        return 0;
      }break;
      case WM_PAINT:
      {
        PAINTSTRUCT ps;
        BeginPaint(hwnd,&ps);
        DrawMCB(hwnd,GetDC(hwnd));
        EndPaint(hwnd,&ps);
        return 0;
      }break;
      default:
        return DefWindowProc(hwnd,msg,wParam,lParam);
      }
      return 0;
    }
    I suspect my problem is I'm not telling it to pain after an event... Of course, I could be wrong.

    http://mhtml.ithium.net/offsite/nowyousee.jpg
    http://mhtml.ithium.net/offsite/nowyoudont.jpg
    Last edited by Mithoric; 12-15-2003 at 07:00 AM.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try adding

    InvalidateRect()//with the whole app area
    UpdateWindow()//get it to draw imediately without waiting for the msg to be processed

    You have a GDI leak as well

    You GetDC() but never release it (llok up ReleaseDC() )

    Try
    hdc=BeginPaint();
    "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
    Thanks I'll change some of my code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM