GDI object of BRUSH has two major attributes -

  • color in RGB,
  • style of the brush
When BRUSH style is BS_NULL, color is not applicable and it is treated as hollow or transparent. GDI APIs which draws shapes in two steps
  • Draw outer lines
  • Fill inner area as per selected brush
With a style BS_NULL style it will draw a shape whose outer lines are only visible. It will be a hollow or transparent share.

BS_SOLID vs BS_NULL/HOLLOW

For example if this is a rectangle then outer borders will be there and inner area will be see-through.

Solid Style BRUSH Drawing:

  case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    hpen = CreatePen(PS_SOLID, 3, RGB(50,50,50));
    logbrush.lbColor = RGB(200,200,200);
    logbrush.lbStyle = BS_SOLID;
    logbrush.lbHatch = 0;
    hbrush = CreateBrushIndirect(&logbrush);
    old_hbrush = (HBRUSH) SelectObject(hdc, (HGDIOBJ)hbrush);
    old_hpen = (HPEN) SelectObject(hdc, (HGDIOBJ)hpen);
    Rectangle(hdc, 10, 10, 100, 100);
    SelectObject(hdc, (HGDIOBJ)old_hbrush);
    SelectObject(hdc, (HGDIOBJ)old_hpen);
    DeleteObject(hbrush);
    DeleteObject(hpen);
    EndPaint(hWnd, &ps);
    break;
NULL/HOLLOW Style BRUSH Drawing:
  case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    hpen = CreatePen(PS_NULL, 3, RGB(50,50,50));
    logbrush.lbColor = RGB(200,200,200);
    logbrush.lbStyle = BS_NULL;//or BS_HOLLOW
    logbrush.lbHatch = 0;
    hbrush = CreateBrushIndirect(&logbrush);
    old_hbrush = (HBRUSH) SelectObject(hdc, (HGDIOBJ)hbrush);
    old_hpen = (HPEN) SelectObject(hdc, (HGDIOBJ)hpen);
    Rectangle(hdc, 10, 10, 100, 100);
    SelectObject(hdc, (HGDIOBJ)old_hbrush);
    SelectObject(hdc, (HGDIOBJ)old_hpen);
    DeleteObject(hbrush);
    DeleteObject(hpen);
    EndPaint(hWnd, &ps);
    break;

About our authors: Team EQA

Further readings

Where is WinMain() function in MFC application ?

MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.

What is the utility of CWinApp class?

This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...

Basic steps in Win32 GUI Application with source code.

Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.

What is a Window CallBack procedure and what is its utility?

DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.

What are LPARAM and WPARAM in window proc function?

LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.

What are the basic steps of a typical MFC based application?

We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...

#