Advertisement

Using a Progress Bar

Started by December 12, 2000 06:54 PM
6 comments, last by 1kevgriff 24 years ago
Here is a quick question I have: I have a dialog with a text label and a progress bar. When I run my Game_Init() function, I want it to load the dialog (which I know how to do), but I want it as it loads stuff to update the dialog with 1) what it is doing (ex: "Loading Background Music", "Loading Sprites", etc.) and 2) Update the progress bar. How would I go about doing this? Could someone point me in the right direction? This is from using the Dialog Resource Editor in VC6. Thanks
Basically u can use SendMessage to set certain things about the progress bar. Using GetDlgItem u can get the item''s handle.
SendMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
example:
SendMessage(GetDlgItem(hDlg, IDC_PBAR), 0, MAKELPARAM(0, 100));
That will set the min, max range.

SendMessage(GetDlgItem(hDlg, IDC_LABEL1), WM_SETTEXT, 0, (LPARAM) "Whatever");

Copied from the Visual C++ Help File
---------------------------------------------------------------
PBM_DELTAPOS
wParam = (WPARAM) nIncrement
lParam = 0;

Advances the current position of a progress bar by a specified increment and redraws the bar to reflect the new position.

Returns the previous position.
nIncrement
Amount to advance the position.
=======================================================
PBM_GETPOS
wParam = 0;
lParam = 0;

Retrieves the current position of the progress bar.

Returns a UINT value that represents the current position of the progress bar.
=======================================================
PBM_GETRANGE
wParam = (WPARAM)(BOOL) fWhichLimit;
lParam = (LPARAM)(PPBRANGE) ppBRange;

Retrieves information about the current high and low limits of a given progress bar control.

Returns an INT that represents the limit value specified by fWhichLimit. If lParam is not NULL, lParam must point to a PBRANGE structure that is to be filled with both limit values.
fWhichLimit
Flag value specifying which limit value is to be used as the message''s return value. This parameter can be one of the following values: TRUE Return the low limit.
FALSE Return the high limit.

ppBRange
Address of a PBRANGE structure that is to be filled with the high and low limits of the progress bar control. If this parameter is set to NULL, the control will return only the limit specified by fWhichLimit.
=======================================================
PBM_SETBARCOLOR
wParam = 0;
lParam = (LPARAM)(COLORREF)clrBar;

Sets the color of the progress indicator bar in the progress bar control.

Returns the previous progress indicator bar color, or CLR_DEFAULT if the progress indicator bar color is the default color.
clrBar
COLORREF value that specifies the new progress indicator bar color. Specify the CLR_DEFAULT value to cause the progress bar to use its default progress indicator bar color.
========================================================
PBM_SETBKCOLOR
wParam = 0;
lParam = (LPARAM)(COLORREF)clrBk;

Sets the background color in the progress bar.

Returns the previous background color, or CLR_DEFAULT if the background color is the default color.
clrBk
COLORREF value that specifies the new background color. Specify the CLR_DEFAULT value to cause the progress bar to use its default background color.
===========================================================
PBM_SETPOS
wParam = (WPARAM) nNewPos;
lParam = 0;

Sets the current position for a progress bar and redraws the bar to reflect the new position.

Returns the previous position.
nNewPos
Signed integer that becomes the new position.
=================================================
PBM_SETRANGE
wParam = 0;
lParam = MAKELPARAM(nMinRange, nMaxRange);

Sets the minimum and maximum values for a progress bar and redraws the bar to reflect the new range.

Returns the previous range values if successful, or zero otherwise. The low-order word specifies the previous minimum value, and the high-order word specifies the previous maximum value.
nMinRange
Minimum range value. By default, the minimum value is zero.
nMaxRange
Maximum range value. By default, the maximum value is 100.
===============================================
PBM_SETRANGE32
wParam = (WPARAM)(int) iLowLim;
lParam = (LPARAM)(int) iHighLim;

Sets the range of a progress bar control to a 32-bit value.

Returns a DWORD value that holds the previous 16-bit low limit in its low word and the previous 16-bit high limit in its high word. If the previous ranges were 32-bit values, the return value consists of the low words of both 32-bit limits.
iLowLim
A signed integer that represents the low limit to be set for the progress bar control.
iHighLim
A signed integer that represents the high limit to be set for the progress bar control.
=========================================================
PBM_SETSTEP
wParam = (WPARAM) nStepInc;
lParam = 0;

Specifies the step increment for a progress bar. The step increment is the amount by which the progress bar increases its current position whenever it receives a PBM_STEPIT message. By default, the step increment is set to 10.

Returns the previous step increment.
nStepInc
New step increment.
=========================================================
PBM_STEPIT
wParam = 0;
lParam = 0;

Advances the current position for a progress bar by the step increment and redraws the bar to reflect the new position. An application sets the step increment by sending the PBM_SETSTEP message.

Returns the previous position.
When the position exceeds the maximum range value, this message resets the current position so that the progress indicator starts over again from the beginning.
Advertisement
quote: Original post by Silent

SendMessage(GetDlgItem(hDlg, IDC_PBAR), 0, MAKELPARAM(0, 100));



Aren''t there supposed to be 4 parameters? I''m still trying to learn Windows Message Query and stuff like that.
Eeek, my bad :D

Yeah SendMessage(GetDlgItem(hDlg, IDC_LABEL1), PBM_SETRANGE
, 0, MAKELPARAM(0, 100)),
New problem that I''ve been trying to work on.

1) The dialog box won''t appear whenever I have a the progress bar in the dialog.

2) The SendMessage(...) will only work inside my WM_INITDIALOG. It won''t work from inside my Game_Init(). Could it be caused by my dialog box properties? Thanks.

Here is a sample portion of code:
[source]
BOOL CALLBACK LoadDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
{
} break;
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, IDOK);
default:
return FALSE;
} break;
}
return FALSE;
}

int TestInitialize()
{
SendMessage(GetDlgItem(hwnd, IDC_LOADSTAT), WM_SETTEXT, 0, (LPARAM) "Loading Music. . .");
Fade = new Mp
return 0;
}
New problem that I''ve been trying to work on.

1) The dialog box won''t appear whenever I have a the progress bar in the dialog.

2) The SendMessage(...) will only work inside my WM_INITDIALOG. It won''t work from inside my Game_Init(). Could it be caused by my dialog box properties? Thanks.

Here is a sample portion of code:
  BOOL CALLBACK LoadDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam){	switch(Message)	{	case WM_INITDIALOG:		{		} break;		return 0;	case WM_COMMAND:		switch(LOWORD(wParam))		{		case IDOK:			EndDialog(hwnd, IDOK);		default:			return FALSE;		} break;	}	return FALSE;}int TestInitialize(){SendMessage(GetDlgItem(hwnd, IDC_LOADSTAT), WM_SETTEXT, 0, (LPARAM) "Loading Music. . .");Fade = new Mpreturn 0;}  
Advertisement
I have a class in my code archive on my site that does what you want, check it out

Tim

--------------------------
glvelocity.gamedev.net
www.gamedev.net/hosted/glvelocity
Tim--------------------------glvelocity.gamedev.netwww.gamedev.net/hosted/glvelocity
Is there some reason why I can''t create more than one? I can get my Loading one working, but when I try run one for when the program is exiting, it doesn''t show on the screen. Any idea?

This topic is closed to new replies.

Advertisement