Progress Control addition to a Dialog Box

G

Guest

Please excuse this elementary question...but I am just dumb....

I have taken a simplistic Dialog Box and added a Progress Control.
When I did that, my Dialog Box was no longer able to intialize using the
DialogBox macro.

If I remove the Progress Control from the form, the form displays
appropriately.

Is there something that needs to be done in addition to providing a callback
function for the dialog?

Here is a brief outline of the code (which is quite simplistic).

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
int wmId, wmEvent, rtn_val = 0;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
rtn_val = (int)DialogBox(hInst, (LPCTSTR)IDD_FORMVIEW, hWnd,
(DLGPROC)Formview);

break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:

hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for progress bar form.
LRESULT CALLBACK Formview(HWND hDlg, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

The resource (IDD_FORMVIEW) is a simplistic dialog box with a couple of
Static Text fields and a "STOP" Button.

So I am stuck with the following:
1.) How can I get the form to display (i.e. should I ditch the DialogBox
macro?)
2.) How do I dynamically change the progress bar appearance (i.e. how do I
directly call into the form to change the appearance of the bar)?

Any help or shove in the right direction would be appreciated.
 
I

ismailp

Nobody is dumb here!

1. Do following in your WinMain function:

int __stdcall WinMain()
{
// ...
INITCOMMONCONTROLSEX ics = {0};
ics.dwICC = ICC_BAR_CLASSES;
ics.dwSize = sizeof(INITCOMMONCONTROLSEX);
// ...
}

Also, add
#include <CommCtrl.h>

to beginning of your source file, and link your application with
comctl32.lib

2. usually, another thread deals with the progress bar update and
dialog itself does not. check progress bar control reference for
further information about messages. but if you really want to learn how
bar works, insert a button into dialog and in your BN_CLICKED handler,
send a PBM_STEPIT or PBM_SETPOS message to progress bar control. in
your WM_INITDIALOG handler, set progress range with PBM_SETRANGE
message before using these messages. if you want to use PBM_STEPIT
message. also, if you consider using PBM_STEPIT, you need to use
PBM_SETSTEP message to set your stepping interval.

Ismail
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top