InvalidateRect custom-drawn trackbar

This is a discussion on InvalidateRect custom-drawn trackbar within the Windows Programming forums, part of the Platform Specific Boards category; I want to redraw a custom-drawn trackbar. I've tried InvalidateRect, UpdateWindow, and RedrawWindow. The only thing that works is EnableWindow ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    93

    InvalidateRect custom-drawn trackbar

    I want to redraw a custom-drawn trackbar.
    I've tried InvalidateRect, UpdateWindow, and RedrawWindow.
    The only thing that works is EnableWindow FALSE, EnableWindow TRUE.
    What can I change to make InvalidateRect to work?
    Thanks
    Code:
    // window flags
    tmbColor=gray; chColor=gray;
    slider = CreateWindow(TRACKBAR_CLASS, NULL, WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_NOTICKS, x1,y1,x2,y2, hWnd, (HMENU)ID_SLIDE, hInst, NULL);
    
    // I want to redraw it with new colors
    tmbColor=blue; chColor=blue;
    InvalidateRect(slider, NULL, FALSE);
    
    // NM_CUSTOMDRAW
    case CDDS_PREPAINT:
    	return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT;
    case CDDS_PREERASE:
    case CDDS_POSTERASE:
    case CDDS_ITEMPREERASE:
    case CDDS_ITEMPOSTERASE:
    	return CDRF_DODEFAULT;
    case CDDS_ITEMPREPAINT:
    	switch(itemSpec)
    	{
    	case TBCD_CHANNEL:
    		return CDRF_DODEFAULT | CDRF_NOTIFYPOSTPAINT;
    	case TBCD_THUMB:
    		/* code to draw thumb with tmbColor */
    		return CDRF_SKIPDEFAULT;
    	}
    	break;
    case CDDS_ITEMPOSTPAINT:
    	switch(itemSpec)
    	{
    	case TBCD_CHANNEL:
    		/* code to draw channel with chColor */
    		return CDRF_SKIPDEFAULT;
    	case TBCD_THUMB:
    		return CDRF_SKIPDEFAULT;
    	}
    	break;
    case CDDS_POSTPAINT:
    	return CDRF_DODEFAULT;
    }

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    93
    bump

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    "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
    Feb 2010
    Posts
    93
    Amazingly, you found the example I used to begin with.
    I decided to go back through it though and see if I might discover anything.
    Nope.
    Oh well.
    For now, I will just do the EnableWindow trick.
    Thanks for trying.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Have you tried setting the last param of InvalidateRect() to TRUE? (so the background of the window is redrawn, not just the client area)

    Also always follow an InvalidateRect() with an UpdateWindow() (so the paint msg bypasses the OS msg queue and is posted directly to the window's callback).

    This is because WM_PAINT is the lowest priority msg in the queue and the only msg that can be pre-processed while in the OS queue (all paints in the queue are concatinated into the smallest possible redraw region and dropped back into the queue).
    "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

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    93
    Oh well.
    That didn't work either.
    What's weird is that when color=newcolor (nothing changes) and I hover over the thumb, then the thumb instantly changes to the new color, but not the track. But then if I click on another program's button in the taskbar and then the button back to my program to cause it to repaint, the track has the new color too.

    I guess I just need to add code at ever 'case' to log all the steps this thing flows through.
    I'll do that later, when I have some extra time.

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    93
    I did some 'case' logging and InvalidateRect does nothing, so I went back to Google:
    Custom draw trackbar

    I've obviously somehow already read this I think. I don't remember.
    I am refactoring my code and ran across the EnableWindow trick and thought, what the heck.
    Wow, this is a good example of how comments would have saved time and headaches - man.

    Sorry I wasted your time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. InvalidateRect() + DrawText()
    By ineedmunchies in forum Windows Programming
    Replies: 5
    Last Post: 05-14-2010, 11:56 PM
  2. Invalidaterect
    By Ducky in forum Windows Programming
    Replies: 10
    Last Post: 10-26-2008, 04:12 PM
  3. TrackBar
    By ricalbery in forum C++ Programming
    Replies: 1
    Last Post: 04-24-2008, 05:58 AM
  4. Trackbar controls
    By dalek in forum Windows Programming
    Replies: 2
    Last Post: 05-12-2004, 11:39 PM
  5. using InvalidateRect()
    By agerealm in forum Windows Programming
    Replies: 6
    Last Post: 04-17-2003, 08:43 AM

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