|
Incredible as it may seem, there's no such built-in function for std::string s. This is one of the most frequently asked questions in comp.lang.c++ and comp.lang.c++.moderated.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am working on a model reading and displaying procedure, the larger the model is, the longer the reading time will be, so I want to display a progress bar to indicate the reading progress, they should keep at the same step, how could i do better? thanks
victorswan
|
|
|
|
|
Calculate the size of the model and in your reading/writting procedure calculate the amount of the model currently read into buffer.
Also inside the loop do:
float nPercent = nTotal / nCurrent;
Hope I understood correctly.
Have a day!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
your suggestion sounds very easy, and I can understand, but the reading and displaying procedures are seprated, the percentage is not easy to be calculated, so i want to creat a UI thread,just display a continous runing progress, but when the thread begin, It keep waiting for the main thread running, the UI thread doesn't run until the main thread finishes, I want to keep them at the same step.how can i do? thanks
|
|
|
|
|
I'm not sure I fully understand.
You have a read/write function and both are in a seperate thread and you want to use a UI thread for updating the progress control. Is there two progress controls, one for reading and another for writting...?
Or is it just the one progress control to show the status of the current read or current write, but not both...?
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
sorry for my poor explain ability,I am a beginner,my problem is:
I use one progress to show the status of the current read and current write,but I cant calculate the percent exactly, because all the time expenses is a sum of the reading time and the writting time,the reading procedure locates in "Tremesh" class, but the writting procedure locates in "CView" class, since I can't claculate the percent exactly, I creat a UI thread, the main job of this UI thread is changing a progress continously, It doesn't care about the percent associated with the reading and writting procedure.I hope behind this progress changing, my reading and writting are still working,
but I found, after I use a AfxBeginThread(RUNTIME_CLASS(CProgressThread))to begin the UI thread in the main reading and writting thread , It doesn't start until reading and writting thread ends, my intention is the UI thread should start accompanying with the reading and writting thread, not start after that.
how can i do, thanks.
|
|
|
|
|
So your trying to get the UI thread to run at the same time as your two working threads (read/write) and basically get the UI thread to increment the progress each call or iteration...?
What happens if and when your progress gets beyond 100%, it'll indicate a completion before it actually completes..?
I'm missing something here...if your total is the sum of the time (in seconds) expended for both functions (read/write) your going to have to calculate the number of iterations or calls the threads will receive or someother means of totals. I can't see how your gonna update your progressbar otherwise...?
For just updating a control I don't know if a worker thread is nessecary. It's to my understanding that UI threads are for responding to messages and require a message loop. I would think you could probably do the following:
UINT ProgressThread(LPVOID pParam)
{
CProgressCtrl* pControl = (CProgressCtrl*)pParam;
pControl->StepIt();
}
And start the thread like:
CProgressCtrl* pWnd = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS);
CWinThread* pThread = AfxBeginThread(ProgressThread, (LPVOID)pWnd);
Your thread (i think) should start executing immediately after invocation. Why it's exectuing after your read/write functions go, I have no idea???
Perhaps you thread is being suspended somehow...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Another option is to post a windows message from your thread to the main UI thread. This prevents very bad things.
something like:
::PostMessage(MainWindowHWND, YOURMESS_INCREMENTPROGRESS, CURRENT, MAX);
// Rock
|
|
|
|
|
thank HockeyDude
thank CLaW
victorswan
|
|
|
|
|
I want to move picture by mouse, not just drag scrollbar.
Thanks in advance.
|
|
|
|
|
I'm not sure I fully understand you, but i think you want to
handle the picture boxes OnLButtonDown/OnLButtonUp and OnMouseMove.
Your probably going to want to handle the MouseMove in the parent window also/only.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hello,
I have a problem with the icons in my program. I changed the default MFC icon to my own in VC++ 7. Now my own icon shows up in the top left corner when I run the program but in windows explorer and if I drag a link onto my desktop another icon appears next to the program name. The icon that appears is an icon I'm using for something else in my app... Can someone help me with this?
Regards,
Tobias
|
|
|
|
|
Hmmm. Maybe the system imagelist still has your icon cached or something? If you have TweakUI, it has a function to do this. Otherwise you can delete the ShellIconCache file under the \Winnt or \Windows folder.
___________
Klaus
[www.vbbox.com]
|
|
|
|
|
Thanks for the tip! Too bad it didn't work... Got any other tips?
|
|
|
|
|
Did you change both (large and small) icons?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I think the problem is that you only changed the "large" icon and not the "small" one. Open the resource editor and chose the lower resolution setting, and see if you get the original MFC IDR_MAINFRAME icon.
srs
|
|
|
|
|
Thanks for the tips! I didn't really understand where the choose a lower resolution function is in the resource manager. However, when I removed all the icons from my projekt, rebuilt it, added them again and rebuilt my projekt once more it worked. Very strange indeed...
Thanks again!
Regards,
Tobias
|
|
|
|
|
I am looking for a VU Meter (Realtime volume meter) for use in my C++ project. So far I have been able to find many components that use the windows built in mixer controls to read the peak meter value. This is not sufficient because not all sound card mixers support this. I need something more low level that can obtain the volume level from ANY soundcard
|
|
|
|
|
Hey,
How do I access a bitmap file to read pixels or write pixels? All I need to do is to get pixel color at (x,y) coordinates, then be able to write pixels in a similar way.
Thanks,
Gr3g
|
|
|
|
|
You can select it into a DC and use GetPixel/SetPixel, but unless you're not doing much of this and speed is not an issue, I'd recommend creating a DIBSection ( there are some good wrappers on this site ), which gives you a pointer to the underlying pixel data.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
How do you flush/clear out the message queue in MFC?
|
|
|
|
|
You can loop calling PeekMessage with PM_REMOVE flag till there are no more messages pending.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I want to use A CFile Object so I can use the following GDI+ object call.
static Bitmap* FromStream(
IStream* stream,
BOOL useEmbeddedColorManagement
);
Am I right in thinking I have to create a derrived object, to do this. Could anyone point me in the right direction.
Thanks Again
Rich
|
|
|
|
|
Say I have an array Stuff[100] how would I make that into a collection class I'm having trouble understanding this. I need to derive it from the CObList in MFC. Thanks for your time guys.
-CDudd
|
|
|
|
|
Why do you need to write your own collection ? What are you making a container of ? I guess pointers to some MFC type ?
There seem to be some examples in MSDN for this, go to msdn.microsoft.com if you don't have MSDN on your PC. Personally, I'd use std::vector, but anyone know knows me remotely knew I'd say that. I'm not familiar with any benefits of CObList, but if it's a container specialised for MFC types, there may well be some, in which case I can't help too much except recommending you check the MSDN.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|