Try to include this before destroying the dialog:
// hWnd is the dialog handle
ShowWindow(hWnd, SW_HIDE);
UpdateWindow(hWnd);
ReleaseDC(hWnd, GetDC( hWnd )); // not sure about this line
// hWnd is the dialog handle
ShowWindow(hWnd, SW_HIDE);
UpdateWindow(hWnd);
ReleaseDC(hWnd, GetDC( hWnd )); // not sure about this line