Hi everyone!
I wrote code for the progress bar but the thing is that it is just an empty bar and nothing goes on.
So how can make it update?

#include <windows.h>
#include <commctrl.h>
#include "Resource.h"

//---------------------------------------------------------------------------
RECT rcClient;
HWND hWnd;
HWND hProgress;
HWND hDlg;
HINSTANCE hInst;
int pb_pos;

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_DIALOG1),
	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));
     pb_pos= SendMessage(hProgress, PBM_GETPOS, 0, 0);
         pb_pos += 1; // increase
         SendMessage(hProgress, PBM_SETPOS, pb_pos, 0);
	SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 220));
	return FALSE;
}
#define _AFXDLL
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg,
		       WPARAM wParam, LPARAM lParam)
{
	INITCOMMONCONTROLSEX InitCtrlEx;

	InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
	InitCtrlEx.dwICC  = ICC_PROGRESS_CLASS;
	InitCommonControlsEx(&InitCtrlEx);
  SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 220));
	switch(Msg)
	{
	case WM_INITDIALOG:
		SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 220));
		hProgress=CreateWindowEx(0, PROGRESS_CLASS, NULL,
		               WS_CHILD | WS_VISIBLE | PBS_MARQUEE,
			      20, 20, 17, 260,
			      hWndDlg, NULL, hInst, NULL);

   

	//	SetTimer(hProgress, 1001, 1000, 0);
      MessageBox(hWndDlg,L"Start the bar",L"Start the Bar",MB_OK);
		
	  pb_pos= SendMessage(hWndDlg, PBM_SETMARQUEE, 0, 0);
       pb_pos += 1;
       SendMessage(hWndDlg, PBM_SETPOS, pb_pos, 0);


		SendMessage(hProgress, PBM_SETRANGE, TRUE, MAKELPARAM(0, 220)); 
        SendMessage(hWnd, PBM_SETRANGE, TRUE, MAKELPARAM(0, 220)); 
		//SendMessage(hWnd, PBM_SETSTEP, (WPARAM) 1, 0);
		
		return TRUE;

	case WM_COMMAND:
		switch(wParam)
		{
		case IDOK:
			EndDialog(hWndDlg, 0);
			return TRUE;
		case IDCANCEL:
			EndDialog(hWndDlg, 0);
			return TRUE;
		}
		break;
	}

	
	extern HINSTANCE g_hinst; 



	return FALSE;
}

I've linked the cmmctrl lib and dll.

I've attempted to use SendMessage function but it didn't work.

To update the green portion of a progress bar you need to send the message PBM_DELTAPOS to it.

I also noticed that you are sending the message PBM_SETRANGE to the progress bar before you create it when you handle the WM_INITDIALOG message. That's probably something you want to change.

Edited 5 Years Ago by kerp: n/a

This article has been dead for over six months. Start a new discussion instead.