You are leaking GDIs.
In Taskmanager, select 'View', then 'Select Columns'. Check 'GDI Objects' and run your app, look for a leak (comment out the paint).
The reason is that you have to return the DC back to the default state and you can not delete STOCK GDI objects (though usually nothing bad happens).
Also CreateFontIndirect() is probably failing to create a font based on an uninitialzed structure.
SelectObject() 'pushes' out the current/default object and you should 'catch' it and put it back when you clean up.
Code:
//not at a complier so my not be 100% bug free
//change the font, but catch default
HFONT *hOriginalFont = (HFONT*)SelectObject(hdc, SomeFont);
//draw
//clean up font
SelectObject(hdc, hOriginalFont); //put the DC back teh way we got it
DeleteObject(SomeFont);//delete any GDI we got from a CreateXXX()
//If we used GetDC() call ReleaseDC()
The DC will also probably already contain the default GUI font (the paint DC has the windows current brush, pen, font etc)
Have a look at FillRect() to clear previous text.
I would also be worried if GetStatus() is a long process.
It might be better to have some pump looking for status changes. This is because paint has to be as fast as possible and can be called repeatedly by the OS. (Drag a msgbox over your app and see if it 'shears')
Code:
wstr = GetStatus();
if(wstr != m_wstrCurrentStatus)//see if status changed
{
//set member string
m_wstrCurrentStatus = wstr;
//send a paint msg
InvalidateRect(m_hWnd, NULL, FALSE);
//send direct to callback for faster response
UpdateWindow(m_hWnd);
}
in paint just use m_wstrCurrentStatus in Drawtext() (instead of calling GetStatus() )