About a window with NULL_BRUSH
Dear all:
In my code , I created a Window whose background is NULL_BRUSH , and
it's no menu and title . That is , it is a Transparnt window . And I created
a Timer to updatewindow.When the WM_PAINT message come , I DrawText on the
window.Every time I draw different text on the window.
But now , I have a problem.
The window isn't redraw.The text drawn at last time is'nt erased.So my
window will be too bad.
What should I do?
Some code is here:
VOID CTextWindow::WindowClass()
{
m_wcWNDCLASS.style = 0; //Caution: CS_HREDRAW or CS_VREDRAW styles often
introduce flicker.
m_wcWNDCLASS.lpfnWndProc = CTextWindow::StaticWindowProc;
m_wcWNDCLASS.cbClsExtra = 0;
m_wcWNDCLASS.cbWndExtra = 0;
m_wcWNDCLASS.hInstance = 0;
m_wcWNDCLASS.hIcon = NULL;
m_wcWNDCLASS.hCursor = LoadCursor(NULL, IDC_ARROW);
m_wcWNDCLASS.hbrBackground = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
m_wcWNDCLASS.lpszMenuName = NULL;
m_wcWNDCLASS.lpszClassName = m_szClassName;
}
LRESULT CTextWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam)
{
PAINTSTRUCT ps;
HDC hDC ;
switch (uMsg)
{
case WM_PAINT:
hDC = ::BeginPaint(hWnd, &ps);
OnPaint(hDC);
::EndPaint(hWnd, &ps);
break;
case WM_COMMAND:
case WM_MOUSEMOVE:
case WM_LBUTTONUP:
case WM_LBUTTONDOWN:
case WM_TIMER:
OnCommand(uMsg ,wParam, lParam);
break ;
case WM_NOTIFY:
OnNotify(wParam, lParam);
break ;
case WM_DESTROY:
OnDestroy();
break;
default:
if (m_pWindowProc)
{
return ::CallWindowProc(m_pWindowProc , hWnd , uMsg , wParam , lParam );
}
else
{
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
// Now hand all messages to the default process
if (m_pWindowProc)
{
return ::CallWindowProc(m_pWindowProc , hWnd , uMsg , wParam , lParam );
}
else
{
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
BOOL CTextWindow::OnPaint(HDC hDC)
{
RECT rect;
TCHAR szText[MAX_PATH+1] = _T("\0");
int i = 0 ;
CircularListNode *p;
::GetClientRect(m_hWnd , &rect);
SetBkMode(hDC , TRANSPARENT);
p = m_DrawFirst;
while (p != m_DrawLast)
{
szText[i] = p->text;
p = p->next;
i++;
}
szText[i+1] = m_DrawLast->text ;
szText[i+2] = _T('\0');
DrawText(hDC , szText , -1 , &rect ,DT_TOP | DT_LEFT | DT_SINGLELINE );
return TRUE;
}
BOOL CTextWindow::OnCommand(UINT uMsg , WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_TIMER)
{
switch(wParam)
{
case SPACETIMER:
m_DrawFirst = m_DrawFirst->next;
m_DrawLast = m_DrawLast->next;
InvalidateRect(m_hWnd , NULL , TRUE);
break;
default:
break;
}
return TRUE;
}
return TRUE;
}