|
I have a dialog with a button and a progressbar. When the user clicks the button a lengthy process is initiated. During this process I want to increment the progressbar on a regular interval. I did this by setting a timer when the button is clicked, but the OnTimer function is never called. However it is called when I set the timer in the OnInitDialog function.
It seems that the lengthy process that is initiated in the 'OnMyButtonClicked' function blocks the timer. Anyone knows a sollution for this problem?
|
|
|
|
|
you need to have event pumped into your lenghty process.
I thing there are samples here on code project, have a look around.
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|
|
Brian van der Beek wrote:
When the user clicks the button a lengthy process is initiated.
Do this lengthy progress in a worker thread. Have this worker thread send PostMessages to its parent(View), which in turn sets the Progress bar.
For threads, I recommend this article.[^]
[edit] You can also use a message pump as suggested (code is in the Prosise-book), but that tends to get complicated.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
I now use a worker thread and everything works fine. Thanks for your reply.
|
|
|
|
|
Brian van der Beek wrote:
I now use a worker thread
You did this within 20 minutes?
Wow - you code pretty fast!
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
In Win32 you should use a worker thread to handle lengthy processes in the background so that normal message passing can continue.
If you do not want to use a worker thread then you will need to to use one of the old tricks used before mult-threading.
1) Use some thing like this
if( PeekMessage(...) ) // in lengthy process loop
{
DispatchMessage(...)
}
to allow other messages to be processed.
OR
2) Use a user defined message that you keeping posting to your self until the job is fininish. There by allowing other messages to flow. This works as follows:
PostMessage(MY_MESSAGE); // Get processing started
...
Proc(MY_MESSAGE)
{
swicth(message)
{
case MY_MESSAGE:
// do part of processing
if( !done )
PostMessage(MY_MESSAGE);
break.
}
Both of the above method will increase the amount of time it take to do the lengthy process, but they both work to solve your problem.
I hope this give you some ideas as to how to solve your problem.
INTP
|
|
|
|
|
I have a dialog with a button and a progressbar. When the user clicks the button a lengthy process is initiated. During this process I want increment the progressbar on a regular interval. I did this by setting a timer when the button is clicked, but the OnTimer function is never called. However it is called when I set the timer in the OnInitDialog function.
It seems that the lengthy process that is initiated in the 'OnMyButtonClicked' function blocks the timer. Anyone knows a sollution for this problem?
|
|
|
|
|
I am not sure if this will help, but does this "lengthy process" have a DO/FOR/WHILE loop? If so the task is fairly straight forward. Here is an example of a ProgressBar function:
void CMyDialog::ProgressBar()
{
int percentage=0; //variable initialisation
char temp[100]; //
//The following line will calculate the Progress bar percentage
//The "Records" is a global UINT which increments each time through the loop
//The "TotalRecords" is the total number of Records in the loop
percentage=(int)(((float)Records/(float)TotalRecords)*100.0);
//"m_Progress" is the variable attached to your dialog
//This will set the position of the progress bar depending on the percentage
m_Progress.SetPos(percentage);
//This will update the "m_Progress" variable with the new position
UpdateData(FALSE);
}
Call this function every time you wish to update the progress bar.
Dont forget to update the "Records" variable before calling this function.
Hope this helps.
|
|
|
|
|
Have tried a lot of logging techniques (log to .txt and so on)
Anyone got a easy and good way?
APe
|
|
|
|
|
|
Hi,
How do I append a text in a edit box. I tried various methods, but they could just overwrite the previous line ,but couldnt append..
Any suggestions?
Thanks
Deepak Samuel.
|
|
|
|
|
CString str;
editvar.GetWindowText(str);
str+="appended text";
editvar.SetWindowText(str);
Thats it!!
Cheers
Muhammad Shoaib Khan
http://geocities.com/lansolution
|
|
|
|
|
I think what you want is something like:
SendMessage(hWnd, EM_SETSEL, -1, -1);
SendMessage(hWnd, EM_REPLACESEL, Undo, Text);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I am not so familiar with VC++ and I am facing a problem that seems too easy to professionals.
I have created a dialog based application with VC++ wizard but on the taskbar only the button for the first dialog is displayed. If I try to add more dialogs and their related dialog classes into the project, they do not have their own taskbar button so I do have to use alt+tab to swap among the dialogs. Any ideas?
|
|
|
|
|
|
That's the normal behaviour...
maybe create the other dialogs modeless with a NULL parent (or desktop window as parent ).
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|
|
Items only appears on the taskbar if they children of the desktop window (like the standard modal-dialog-based app is). If you want your other dialogs to be on the taskbar, you'll need to either make them modeless with the parent as the desktop window, or to write a separate modal-dialog-based app for either dialog you want to be separated.
The kindest thing you can do for a stupid person, and for the gene pool, is to let him expire of his own dumb choices.
[Roger Wright on stupid people]
We're like private member functions
[John Theal on R&D]
We're figuring out the parent thing as we go though. Kinda like setting up Linux for the first time ya' know...
[Nitron]
|
|
|
|
|
hy,
i have a console application and i need the path where the exe is located, is there a function which can get me the path ?
Thanks in advance!
|
|
|
|
|
Another solution is GetModuleFileName().
Kuphryn
|
|
|
|
|
I'm beginning to program OpenGL animation, there are two ways to select.
The first is to set PFD_DOUBLEBUFFER flag, in CMyView::OnDraw(CDC *pDC), use SwapBuffer() to show the image, as almost all tutoral said.
The second is to create a DIB using CreateDIBSection(), select it to MemDC, then using wglMakeCurrent() to connect the existed RC with MemDC, thus all the OpenGL commands will draw to the DIB. in OnDraw(), only BitBlt() the DIB to pDC.
In my old machine, which is PII / 128M memory / Savage3D display card, method 2 seems more smooth than method 1.
But I'm afraid, if using the display card with OpenGL supporting and optimizing, method 2 will not be able to take the advantage of the computing ability of the hardware, then method 1 will be quicker and smoother than method 2?
Another puzzle is DOUBLEBUFFER also first draw to main memory (not relate to display chips?), only after drawing finished, the result is shown (copy to display memory).
Is it means that it doesn't / cannot use the calculating ability of the display chips?
|
|
|
|
|
|
in a Document-View application, a modeless dialog is created and shown, the
dialog is very big, so when the user click the frame window or the view, he
wants the dialog not to stay on top. i tried SetWindowPos, but it seems not
work.
|
|
|
|
|
I don't believe there's a way around this. It's the nature of modeless dialogs (they're always on top of the parent window). You might want to consider making the dialog smaller or at least resizable.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
making Desktop parent of child dialog might help
No Worries!
|
|
|
|
|
Why not to use CFormView instead of dialog?
So, you can have your windows managed like cascadely, tile horizontally and tile vertically.
Sonork 100.41263:Anthony_Yio
|
|
|
|