joele23
asked on
Creating a progress bar help needed
I am not used to windows style programming so I may not be offbase with this but anyways.....
I want to add a progress bar to my program. Im used to starting all my programs with main() but this one starts with WINAPI WinMain(). I wanted to add a progress bar to my program while it is doing some work. More specifically I like the style of this progress bar http://www.codeproject.com/miscctrl/kcbusyprogress.asp
Now I downloaded that code and tried to figure out how it works but Im completly lost. I cannot find any main() in the program and I am assuming it defaults to some class where things are intialized and started. I included the source code in my program and tried to make a progress bar like this:
DWORD dwStyle ;
dwStyle |= PBS_TITLEBAR;
dwStyle |= PBS_TITLETEXT;
RECT rect = {20,30,180,230};
CKCBusyProgressCtrl kfc(100,0);
CWnd *pWnd = AfxGetMainWnd();
kfc.Create(dwStyle,rect,pW nd,20,NULL );
kfc.SetNumSteps(10);
kfc.SetCurPos(0);
kfc.Start();
Sleep(2000);
kfc.StepIt();
Sleep(2000);
kfc.StepIt();
But the only thing that happens is the screen goes gray.
Heres the initial code when I create my window:
bool create()
{
RECT screen_cord;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = NULL;
WndClass.lpfnWndProc = MainWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndCl ass))
{
return false;
}
SystemParametersInfo(SPI_G ETWORKAREA ,0,&screen _cord,0);
hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"MyWindow",
WS_POPUP,
CW_USEDEFAULT, CW_USEDEFAULT,
screen_cord.right,
screen_cord.bottom,
NULL, NULL, g_hInst, NULL);
if(hWnd == NULL)
{
return false;
}
return true;
}
Im really no sure where I am going wrong or where do start. If I cant implement this bar then I would like to make a standard progress bar and I would need help with that as well.
I want to add a progress bar to my program. Im used to starting all my programs with main() but this one starts with WINAPI WinMain(). I wanted to add a progress bar to my program while it is doing some work. More specifically I like the style of this progress bar http://www.codeproject.com/miscctrl/kcbusyprogress.asp
Now I downloaded that code and tried to figure out how it works but Im completly lost. I cannot find any main() in the program and I am assuming it defaults to some class where things are intialized and started. I included the source code in my program and tried to make a progress bar like this:
DWORD dwStyle ;
dwStyle |= PBS_TITLEBAR;
dwStyle |= PBS_TITLETEXT;
RECT rect = {20,30,180,230};
CKCBusyProgressCtrl kfc(100,0);
CWnd *pWnd = AfxGetMainWnd();
kfc.Create(dwStyle,rect,pW
kfc.SetNumSteps(10);
kfc.SetCurPos(0);
kfc.Start();
Sleep(2000);
kfc.StepIt();
Sleep(2000);
kfc.StepIt();
But the only thing that happens is the screen goes gray.
Heres the initial code when I create my window:
bool create()
{
RECT screen_cord;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = NULL;
WndClass.lpfnWndProc = MainWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndCl
{
return false;
}
SystemParametersInfo(SPI_G
hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"MyWindow",
WS_POPUP,
CW_USEDEFAULT, CW_USEDEFAULT,
screen_cord.right,
screen_cord.bottom,
NULL, NULL, g_hInst, NULL);
if(hWnd == NULL)
{
return false;
}
return true;
}
Im really no sure where I am going wrong or where do start. If I cant implement this bar then I would like to make a standard progress bar and I would need help with that as well.
The codeproject's control is an MFC control, so you have to create an MFC project in Visual C++. If you have not VC++, you won't be able to use it as is.
ASKER
Actually I got it to work. I made added this code then instead of passing pwnd to Create() I passed wndcls that I made here and it works perfect! I guess I got to give myself the points
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS)); // start with NULL defaults
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndcls.lpszClassName = _T("MyNewClass");
AfxRegisterClass(&wndcls);
SystemParametersInfo(SPI_G ETWORKAREA ,0,&screen _cord,0);
wnd.CreateEx(0, "MyNewClass", "MyWindow", WS_VISIBLE | WS_BORDER, (screen_cord.right/2 - 100),(screen_cord.bottom/2 - 25), 205, 50, NULL, 0, 0);
CRect rect(0,0,200, 25);
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS)); // start with NULL defaults
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndcls.lpszClassName = _T("MyNewClass");
AfxRegisterClass(&wndcls);
SystemParametersInfo(SPI_G
wnd.CreateEx(0, "MyNewClass", "MyWindow", WS_VISIBLE | WS_BORDER, (screen_cord.right/2 - 100),(screen_cord.bottom/2
CRect rect(0,0,200, 25);
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.