Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,
I have a dialog box with two without argument and without return type functions, a check box and has two push buttons

recycler();//---------Will empty the recycle bin
Emptier();//----------Will empty my old VS projects which I have used for learning

When the check box (Which specifically asks the user to empty the recycle bin) is checked recycler + Emptier function gets executed if the check box is unchecked Emptier function gets executed.
C++
int checked;
case WM_COMMAND:
		if (LOWORD(wParam) == IDOK)
		{
			checked = IsDlgButtonChecked(hDlg, IDC_CHECK1);
			if (checked) {
				recycler();
				Emptier();
				}
			else
			{
				Emptier();
				
			}
break;
			
		}
		else if (LOWORD(wParam) == IDCANCEL)
			EndDialog(hDlg, LOWORD(wParam));
		return (INT_PTR)TRUE;
break;


Since I cant confirm that my code has done the job I used a progress bar to do the job
here is the code for it!
C++
case WM_INITDIALOG:
		progressbar = GetDlgItem(hDlg, IDC_PROGRESS1);
		SendMessage(progressbar, PBM_SETRANGE, 0, MAKELPARAM(0, 10));
		SendMessage(progressbar, PBM_SETSTEP, (WPARAM)10, 0);
		return (INT_PTR)TRUE;


and I have sent the message successfully to the progress bar and progress bar shows some progress.

My problem is:
Since Visual studio projects are quiet huge and consumes a lot of memory I could not guess several things.

For example, My old, useless projects which I did created for learning consumes more than a GB which I consider use less and usually my recycle bin always has more than a GB of waste files.

When I run my program the progress is shown by by my Operating system (Windows 10) like this
http://tncdn.vikitech.netdna-cdn.com/assets/6-deleting.png[^]
in addition to my progress bar.

On experimenting with this I found my progress bar just simply shows the progress but not actually doing work.
Since my English is bad I'll try to explain this clear:
when I click on the OK button within a fraction of second my progress bars beeps a sound(I used Beep(x,y) function to know my progress has been completed)

Every time I get comments that my code is insufficient for the experts to solve to avoid my mistakes I have provided the complete code below for the convenient view!
C++
int checked;
HWND progressbar;
INT_PTR CALLBACK Optimizer(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
		
	case WM_INITDIALOG:
		progressbar = GetDlgItem(hDlg, IDC_PROGRESS1);
		SendMessage(progressbar, PBM_SETRANGE, 0, MAKELPARAM(0, 10));
		SendMessage(progressbar, PBM_SETSTEP, (WPARAM)10, 0);
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK)
		{
			checked = IsDlgButtonChecked(hDlg, IDC_CHECK1);
			if (checked) {
				recycler();
				Emptier();
				SendMessage(progressbar, PBM_STEPIT, 0, 0);
				Beep(750, 100);
				}
			else
			{
				Emptier();
				SendMessage(progressbar, PBM_STEPIT, 0, 0);
				Beep(750,100);
			}
			
		}
		else if (LOWORD(wParam) == IDCANCEL)
			EndDialog(hDlg, LOWORD(wParam));
		return (INT_PTR)TRUE;
	
		break;
	case WM_CTLCOLORDLG:
	{
		return(LONG)DlgBackground;
	}
	case WM_CTLCOLORSTATIC:
	{
		//------
	}
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(hDlg, &ps);
		// TODO: Add any drawing code that uses hdc here...
		HBITMAP logo;
		logo = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
		HDC logoB;
		logoB = CreateCompatibleDC(hdc);
		SelectObject(logoB, logo);
		BitBlt(hdc, 0, 0, 4100, 4100, logoB, 10, 10, SRCCOPY);
	}
	
	}
	return (INT_PTR)FALSE;
}


What I have tried:

I have referred to some experts answer and came to know that it is not the purpose of progress bar.
This is what I learnt,
One can use the progress bar only if he knows how long will the task takes place

I also referred Goggle through various key words like progress bar for unknown time and found various solutions in C# which is quiet difficult to figure out my solution

So I don't know here what should I do?

Thank you
Posted
Updated 6-Feb-16 6:56am
v2
Comments
Philippe Mori 7-Feb-16 22:20pm    
If you display Windows delete dialog, then why would you need a progress bar?
[no name] 7-Feb-16 23:54pm    
Thank you sir for your comment.
But my problem is also there I want to show the progress in my progress bar and should prevent my windows to do that task.
Windows usually display progress bar when the files occupy greater storage.
If I have not implemented a progress bar in my program both windows and my program will maintain silence if files occupy lesser space so I can't find the task has been completed or not so why I have created a progress bar in my program.
Thank you

1 solution

I see two major ways of solving that problem:

1. use indeterminate progressbar with TBPF_INDETERMINATE style. Take a look at theExample.
2. use some kind of "spinning wheel". Example picture. It is a picture which is spinned.

But anyway: make the GUI of the progress bar in an own thread. Use PostThreadMessage.

tip: Dont load the bmp in every WM_PAINT. Load it as global on start up.
 
Share this answer
 
Comments
[no name] 8-Feb-16 0:14am    
Sir, Thank you for your kind solution.
I have several doubts since I am a beginner in Win32 API so could you explain more briefly please.
Spinners will do my job but I wish to have a progress bar

"tip: Dont load the bmp in every WM_PAINT. Load it as global on start up."
This was a long time confusion I have which I have not asked in this forum because I fear that it would become a non-technical question. I see various commercial products showing their logo in their software for example
http://cache.filehippo.com/img/ex/3049__ccleaner1.png shows a cleaner logo(Alphabet C with a brush) in its software do they use bitmaps or something else? I found that they have not used any bitmaps using resource editor then what do they do to display such a beautiful logos on their software.

Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900