I can see a number of issues, I'll address them one by one.
Firstly, the Rectangle function doesn't just draw a border, but it also _fills_ the rect, using the current brush, which in this case is the background brush.
Next, you only call BeginPaint/EndPaint once per WM_PAINT message.
You need to pay attention to the expected return values if you process messages, failing to do so can mean that the message is sent over and over while the system waits to be informed that it has been handled. For WM_PAINT, you should return 0.
I've fixed these oversights and added a new function, which takes both the HWND and the HDC. This is designed to draw a border 10 pixels in from the edge of the client area. You can see that if you put it after the other two in the onPaint function, it appears as though they haven't worked - this is simply because it draws over the top of them.
Here you go:
#include <windows.h>
LPCTSTR ClassName = "BasicApp";
LPCTSTR WindowName = "A Simple Window";
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void onPaint(HWND hwnd);
void myRect1(HDC hdc);
void myRect2(HDC hdc);
void myRect3(HWND hwnd, HDC hdc);
INT WINAPI WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
HWND hWindow;
MSG messages;
WNDCLASSEX WndClsEx;
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WindowProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClassName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&WndClsEx);
hWindow = CreateWindowEx (
0,
ClassName,
WindowName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);
if( !hWindow )
return 0;
ShowWindow (hWindow, SW_SHOWNORMAL);
UpdateWindow(hWindow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_PAINT:
onPaint(hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
return 0;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
}
void onPaint(HWND hwnd)
{
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
myRect3(hwnd, hdc);
myRect1(hdc);
myRect2(hdc);
EndPaint(hwnd, &ps);
}
void myRect1(HDC hdc)
{
Rectangle(hdc, 10, 10, 50, 50);
}
void myRect2(HDC hdc)
{
Rectangle (hdc, 110, 110, 150, 150);
}
void myRect3(HWND hwnd, HDC hdc)
{
RECT clientRect;
GetClientRect(hwnd, &clientRect);
InflateRect(&clientRect, -10, -10);
Rectangle(hdc, clientRect.left, clientRect.top, clientRect.right, clientRect.bottom);
}