Title Name not showing and background color not changing

Your MessageRouter is missing default processing. Add DefWindowProc as shown

LRESULT CALLBACK AbstractWindow::MessageRouter ( HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param ) {
    AbstractWindow* abstract_window = 0;

    if ( message == WM_NCCREATE ) {
        abstract_window = ( AbstractWindow* ) ( ( LPCREATESTRUCT ( l_param ) )->lpCreateParams );
        SetWindowLong ( hwnd, GWL_USERDATA, long ( abstract_window ) );
        abstract_window->OnCreate ( hwnd );
        return DefWindowProc(hwnd, message, w_param, l_param);//ADD THIS LINE
    }
    ...

For background, you can either handle WM_ERASEBKGND or you can set hbrBackground

Method 1: handle WM_ERASEBKGND

virtual LRESULT EraseBackground(HWND hwnd, WPARAM w_param)
{
    RECT rect;
    GetClientRect(hwnd, &rect);
    FillRect((HDC)w_param, &rect, GetSysColorBrush(COLOR_BTNFACE));
    return 1;
}

Method 2: set hbrBackground and let window do the rest

hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);

virtual LRESULT EraseBackground(HWND hwnd, WPARAM w_param)
{
    //let window do this
    return DefWindowProc(hwnd, WM_ERASEBKGND, w_param, 0);
}

………
Edit #2

class AbstractWindow
{
    virtual void OnPaint()=0;
    ...
};

AbstractWindow::MessageRouter()
{
case WM_PAINT:
    abstract_window->OnPaint();
    return 0;
...
}

void GameWindow::OnPaint()
{
    PAINTSTRUCT ps; 
    HDC hdc = BeginPaint(hwnd, &ps); 
    TextOut(hdc, 0, 0, "Hello, Windows!", 15); 
    EndPaint(hwnd, &ps); 
}

Browse More Popular Posts

Leave a Comment