Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Common Controls (Progress bar) in C

Status
Not open for further replies.

aluaya

Programmer
Nov 2, 2005
8
0
0
DE
Hi all,
I am programming a windows application in C (not C++), and so far with basic controls things are going fine,

But now i need to use a Progress Bar in my application. and things dont seem to work good.

i need your help since all examples i saw uses C++.

Thanks,
And hear from you soon
 
Any reason why you're using C instead of C++? Most of the SDKs come with C++ unless you're maintaining pre-1993 software. You can program in C++ without going into MFC.
 
Basic reason is that i am embedded applications programmer, not windows one, and i need this now onlz for this project and for simple sample application.

 
At a guess, the dialog containing the common controls doesn't even launch. You have to do several things to get it to work.

1) In the dialog source file

#include <commctrl.h>

2) When handling the WM_INITDIALOG message, the first thing you need to do is
Code:
INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof (icc);
icc.dwICC  = ICC_PROGRESS_CLASS;
InitCommonControlsEx (&icc);
If you don't want to call this whenever you use it, just call it in WinMain before you start the message loop. If you intend to use different types of controls, just use ICC_WIN95_CLASSES instead of ICC_PROGRESS_CLASS.

3) Add the following to the list of libraries your are linking to

comctl32.lib

And that's it - you should have progress bars now.
 
thanx , but where can i assign the position and the size values?
 
Also in the WM_INITDIALOG. Something like
Code:
SendDlgItemMessage (hDlg, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
SendDlgItemMessage (hDlg, IDC_PROGRESS, PBM_SETSTEP, 5, 0);
This will give you a range of 0 to 100 with a step of 5. When you want to move it on
Code:
SendDlgItemMessage (hDlg, IDC_PROGRESS, PBM_STEPIT, 0, 0);
Alternatively, if you want to move to a specific position, say 29
Code:
SendDlgItemMessage (hDlg, IDC_PROGRESS, PBM_SETPOS, 29, 0);
 
thanks again
i dont want to get annoying but i meant the location of the control in the window, i am using an .RC file for my controls but i couldnt find something about progress bars
 
You have to insert it as a control. Something like
Code:
CONTROL         "Progress1", IDC_PROGRESS,"msctls_progress32",
                PBS_SMOOTH | WS_BORDER,7,18,172,14
There is also a PBS_VERTICAL. If you do not specify PBS_SMOOTH, it gets chunky.

Check this link out if you want to know what they look like
 
hi,
actually i went through msdn, my problem was mainly that i couldnt find something related to my RC file, but of course your help was very valuable, and gave me insight about many things didnt corss my mind.
thanx again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top