Im trying to refresh one part of the window with InvalidateRect but it wont get refreshed right away. It will be if you move another window over it.

What am I doing wrong?

Code:
#include <windows.h>
#include <iostream>
using namespace std;

#pragma comment(linker,"/subsystem:\"console\" /entry:\"WinMainCRTStartup\"")

#define IDB_SOURCE    1008

const RECT rText={20,100,420,25};
char buf[260]="aaaaaaaaaaaaa";
HWND hwnd;
LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hThisInst,
                   HINSTANCE hPrevInst,
                   LPSTR Args,int WinMode)
{
    MSG Message;
    WNDCLASS WinClass={0};

    char * Class="Find Files";

    WinClass.hInstance    =hThisInst;
    WinClass.lpszClassName=Class;
    WinClass.lpfnWndProc  =WindowFunc;
    WinClass.style        =0;
    WinClass.hIcon        =LoadIcon(NULL,IDI_APPLICATION);
    WinClass.hCursor      =LoadCursor(NULL,IDC_ARROW);
    WinClass.lpszMenuName =NULL;
    WinClass.cbClsExtra   =0;
    WinClass.cbWndExtra   =0;
    WinClass.hbrBackground=(HBRUSH) GetStockObject(LTGRAY_BRUSH);

    if(!RegisterClass(&WinClass)) return 0;

    DWORD dwStyle=(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
                   WS_MINIMIZEBOX | WS_VISIBLE);
    hwnd=CreateWindow(Class,
                        TEXT("Search"),
                        dwStyle,
                        100,100,
                        600,400,
                        NULL,
                        NULL,
                        hThisInst,
                        NULL);
    if(hwnd==NULL)
    {
        //ReportError("CreateWindow");
        return 0;
    }

    while(GetMessage(&Message,NULL,0,0))
    {
        TranslateMessage(&Message);
        DispatchMessage(&Message);
    }
    return Message.wParam;
}
/// ////////////////////////////////////////////////////
///
LRESULT CALLBACK WindowFunc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
    HDC hdc=0;
    PAINTSTRUCT ps;

    switch(Message)
    {
    case WM_CREATE:
    {
        CreateWindowEx(0,TEXT("button"),
                       TEXT("Clickme"),
                       WS_VISIBLE | WS_CHILD,
                       20,140,60,20,
                       hwnd,(HMENU)IDB_SOURCE,0,NULL);

        return 0;
    }

    case WM_COMMAND:
        switch(wParam)
        {
        case IDB_SOURCE:
            sprintf(buf, "bbbbbbbbbbbbbb");
            InvalidateRect(hwnd, &rText, TRUE);
            UpdateWindow(hwnd);
            break;
        }
        return 0;

    case WM_PAINT:
    {
        cout << " WM PAINT.\n";
        hdc=BeginPaint(hwnd,&ps);
        TextOut(hdc, 20, 100, buf, strlen(buf));
        EndPaint(hwnd,&ps);
    }
    return 0;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hwnd,Message,wParam,lParam);
    }
    return 0;
}