Hi, I try to send messages to update the progress bar as it counts to 100, but the progress bar does not update, and then it says the program is not responding.

Code:
#include <windows.h>
#include <commctrl.h>
#include "progress_bar.h"

#define length 100

//---------------------------------------------------------------------------
HWND hWnd;
HINSTANCE hInst;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	hInst = hInstance;

	DialogBox(hInst, MAKEINTRESOURCE(IDD_CONTROLS_DLG),
	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));

	return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg,
		       WPARAM wParam, LPARAM lParam)
{
	INITCOMMONCONTROLSEX InitCtrlEx;

	InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
	InitCtrlEx.dwICC  = ICC_PROGRESS_CLASS;
	InitCommonControlsEx(&InitCtrlEx);

	switch(Msg)
	{
	case WM_INITDIALOG:
		CreateWindowEx(0, PROGRESS_CLASS, NULL,
		               WS_CHILD | WS_VISIBLE | PBS_SMOOTH ,
			      20, 20, 260, 17,
			      hWndDlg, NULL, hInst, NULL);
			      
		return TRUE;

	case WM_COMMAND:
		switch(wParam)
		{
		case IDOK: 
        {
            int pb_pos;
            SendMessage(hWndDlg, PBM_SETRANGE, 0, MAKELPARAM(0, length ));
			while(pb_pos != length)
            {           
                        pb_pos = SendMessage(hWndDlg, PBM_GETPOS, 0, 0);
                        pb_pos++;
                        SendMessage(hWndDlg, PBM_SETPOS, pb_pos, 0);
            }
			return TRUE;
        }
		case IDCANCEL:
        {
			EndDialog(hWndDlg, 0);
			return TRUE;}
		}
		break;
	}

	return FALSE;
}
Code:
#define IDD_CONTROLS_DLG 100
Code:
#include "progress_bar.h"
#include <afxres.h>

IDD_CONTROLS_DLG DIALOG 260, 200, 200, 120
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Windows Controls"
FONT 8, "MS Shell Dlg"
BEGIN
    DEFPUSHBUTTON   "Load", IDOK, 30, 100, 50, 14
    DEFPUSHBUTTON   "Close", IDCANCEL, 120, 100, 50, 14
END
Thanks for the help