As a matter of course in my GUI stuff I use the following (borrowed from VB) in the place where you used MessageBeep().
/// @brief Yields execution of the current thread so that
/// the operating system can process other events.
///
/// @returns VOID.
static VOID DoEvents(VOID)
{
MSG Msg;
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
So with the example lets suppose we put the DoEvents() in PushMyButton() like so:
void DeflateRect(RECT* rect)
{
rect->left++;
rect->top++;
rect->bottom--;
rect->right--;
}
#define BTN_NORMAL 0
#define BTN_PRESSED 1
#define BTN_DEFAULT 2
void PushMyButton(HDC dc, RECT *rect, int state)
{
UINT uType = DFCS_BUTTONPUSH;
if (state == BTN_NORMAL) // disabled
uType |= DFCS_INACTIVE;
if (state) // default or pressed
{
FrameRect(dc, rect, GetSysColorBrush(COLOR_WINDOWFRAME));
DeflateRect(rect);
}
if (state & BTN_PRESSED)
{
FrameRect(dc, rect, GetSysColorBrush(COLOR_BTNSHADOW));
DeflateRect(rect);
FillRect(dc, rect, GetSysColorBrush(COLOR_BTNFACE));
}
else
{
DrawFrameControl(dc, rect, DFC_BUTTON, uType);
}
DoEvents(); //Update the view by emptying the message queue
}
static void Main_OnPaint(HWND hwnd)
{
PAINTSTRUCT ps;
RECT rc, rcc;
BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
rcc.top = rcc.left = 10;
rcc.bottom = rcc.right = 42;
PushMyButton(ps.hdc, &rcc, 0);
Sleep(3000);
PushMyButton(ps.hdc, &rcc, 1);
Sleep(3000);
PushMyButton(ps.hdc, &rcc, &rcc), 0);
EndPaint(hwnd, &ps);
}
That should achieve the desired result.