|
I would start looking at how the threaded procedure is communicating with the dialog
There are a number of good articles around on comms between a dialog and a worker thread - Im almost tempted to point you here http://www.flounder.com/workerthreads.htm[^]
'g'
|
|
|
|
|
I using PostMessage to send a user defined message on the main GUI thread which then calls SetWindowText on the static control that I am using for a counter. From what I have read this is the only safe way to update the GUI From a separate thread. I am still lost on why the dropping down of the combo box would interrupt the drawing of my counter control.
|
|
|
|
|
Greg Ellis wrote: I have created a new thread which should run as a separate process.
What does this mean? Is it a thread in the same process or a separate process?
How does the thread report its progress exactly?
Steve
|
|
|
|
|
R u trying to update the counter in dialog and viewing? if drow down box painter u can see some delay in the counter updation in dialog.
|
|
|
|
|
You say you have a worker thread posting messages to the UI thread.
Your worker thread is not being interrupted any differently than it was when the combobox is not being used. Windows runs multiple threads by time slicing. Higher priority threads get more slices more often.
It appears to you that the thread is interupted by the click but it is not. As your using post message, the UI thread updates the control content. This is the same thread that handles the users click on the combobox. While the UI thread is handling the click combo drop event, any messages posted by the worker thread are being added to the message queue for the UI thread to process once it returns from its current work.
The issue you have is that the drop event of the combo is animated and due to this appears to pause the UI while this happens. Apart from re-writing how a combo box works (or some how disabling the animation) I do not beleive there is anything you can do about this.
As a test to show its not affectig the worker thread. Time how long it takes for your on screen counter to increment to a set count. Then check that its takes the equivalent time (within a dop of the combobox time threadshold) it should still reach the same count.
If you vote me down, my score will only get lower
|
|
|
|
|
The visual studio c++ program compiles and build without errors. When i try to run it from the black screen, it says: Prgram.exe has encountered a problem and needs to close. We are sorry for the inconvenience. I believe I wrote this code before and it worked without problems. I don't understand why it will not work now. I could be wrong, it's been awhile. PLEASE KINDLY HELP?
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string fileName,line;
ifstream infile;
cout<<"Enter the file name and complete path: ";
cin>>fileName;
int Adder=0,count=0;
string *A;
infile.open(fileName.c_str());
while(!infile.eof())
{
getline(infile,line);
if(line[count]=='A'||line[count]=='a')
{
A=new string[Adder];
A[Adder]=strlen(line.c_str());//THIS LINE IS CAUSING ERROR
cout<<a[adder]<<endl;
adder++;
="" }
="" return="" 0;
}
<div="" class="signature">
modified on Thursday, May 20, 2010 9:48 PM
|
|
|
|
|
That is a bad post. Please read the "how to ask a question" sticky message, use PRE tags, and provide an accurate description of the things that happen against your expectation. Then people will be willing and able to help you.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
This use to be a cool place where individuals of all knowledge level came to share ideas, problems and solutions. With all due respect, this site is not the cool entity it used to be. Now it seems like asking a simple question is extremely very complicated. I tried reading the posting instructions and got totally lost in its comprehension. What Happen to Code Project?
|
|
|
|
|
without proper formatting, your code is hard to read. And it is strange:
- I see a "count" variable that starts at zero and remains zero;
- I see things getting stored in a string array for no good reason; maybe it is the beginning of something bigger?
- I see something that probably is sufficiently wrong to cause a crash:
new string[Adder] probably creates an array (a new one each time!), of which the elements are indexed from 0 to Adder-1, yet the very next line attempts to access the element with index=Adder which is beyond the array. Boom.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Can you please tell me if following instructions is correct: A[0]=strlen(line.c_str());
|
|
|
|
|
If new string[Adder] does what I expect, it creates an array with size zero since Adder is zero the first time around. So there is no way you can store anything in it.
You probably need new string[Adder+1] to fix that, and it would fix the illegal access too, since now you have room for elements 0, 1, ... up to Adder.
When you read from the array (in a cout statement IIRC), you should only read elements that have been written to earlier in that very same array; so changing one index to zero and keeping the other at Adder, will fail each time but the first.
However, as I said before, I see no point in creating an entire array each time around, while only filling one element of that array. I fail to understand what it all is going to do, and I find it hard to believe it used to work before.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
It is a string array and i am string load the array with a string such as a name. I am not trying to load a single character. I saw your point with and i did try:
A=new string[Adder+1];
A[Adder]=strlen(line.c_str());
cout<
|
|
|
|
|
Your compiler is probably screaming blue murder at you over the line you're interested in - see what it's saying and fix it. On one of my compilers it'll say something like: "conversion from 'size_t' to 'char', possible loss of data" which is a pretty big hint that it's not storing what you want in your array.
I know I've said it before in my previous post - using built in arrays and pointers is complete overkill for this sort of problem. std::vector and std::string are your friends here.
|
|
|
|
|
I have to say it was a bit of a trial reading your code, not just 'cause of the formatting! Before slagging people off for their attitude in helping you remember it pays to give them the respect they deserve by posting code that actually compiles - as you couldn't be bothered to stick you code in
tags we can't see your include files for example. Also some idea of what the program does is helpful when it's not obvious from the code (and in this case it aint obvious - are you trying to count the lines that start with A or a or just echo a file to the console?)
Look into these things:
- Don't use low level constructs (pointer, arrays, dynamic memory allocation) where a couple of local objects would have done (i.e. use <code>std::vector<std::string> lines( number_of_lines );</code> )
- use variable names that describe what you're doing - i.e. rename adder and A
- Learn how IOStreams work - <code>cin >> fileName;</code> won't work if you have spaces in the filename
- Grab a textbook and have a look at the difference between initialisation and assignment. For example there's no reason to not create your input file object and open it at the same time
- using strlen is completely pointless in a C++ program that's using std::string. Look up the interface to std::string in a decent reference and you'll find a member that does the right thing
Cheers,
Ash
|
|
|
|
|
Dear Sir, concerning your little search engine that finds A's in text files ..
Well, it works perfectly now, some minor alterations were made.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class FileSearcher
{
public:
string fileName,line;
char filename[256];
unsigned long fileSize, begin,end;
int Adder,count;
string *A;
public:
FileSearcher(char *file )
{
Adder=0;
count=0;
runMe(file);
}
~FileSearcher()
{
delete []A;
}
public:
void runMe(char *file)
{
cout<<"Enter the file name and complete path:> ";
cin>>filename;
fileName.assign( filename );
ifstream infile(filename);
infile.seekg (0, ios::end);
fileSize = infile.tellg();
infile.close();
cout << "size is: " << (fileSize) << " bytes.\n";
A=new string[fileSize+1];
infile.open(fileName.c_str());
Adder=0;
count=0;
while(!infile.eof())
{
getline(infile,line);
if(line[count]=='A'|| line[count]=='a')
{
cout<<"FOUND an A here ("<<line[count]<<") Line= "<<Adder<<": \n\n"<<line.c_str()<<"\n";
A[Adder]=strlen(line.c_str());
count++;
}
count=0;
Adder++;
}
infile.close();
cout<<"\n\n";
}
};
int main()
{
FileSearcher *myFileSearcher = new FileSearcher("c:\\t.txt");
return 0;
}
..
modified on Saturday, May 22, 2010 6:58 AM
|
|
|
|
|
It is perfect, for some strange version of perfection that I'm not sure that most experienced C++ programmers would recognise.
Faux pas the first: #pragma warning( disable : 4101 ) . Why are you disabling this warning? What defects does it hide in your code?
Faux pas the second: Using arrays when, in this example you just need std::string
Faux pas the third: Redundancy - reading stuff into a character array then assigning to a string when you could just read straight into the string
Faux pas the fourth: Closing the file, why not just rewind it to the beginning. Or stick getting the filesize in it's own function.
Faux pas the fifth: What are Adder and count for? Where I come from an Adder is a snake and the count is on Sesame Street. They're initialised, incremented and assigned and, er, pointless.
Faux pas the sixth: What's the point of an array of empty string, one per character in the input file?
Faux pas the seventh: Declaring variables miles away from using them
Faux pas the eighth: You can't see this one as you disabled the warning, bummer!
|
|
|
|
|
You are correct on all points.
Forgive my ignorance and lazyness , i stand corrected.
im used to passing the project down the development cycle
and letting someone better like for instance a senior software engineer do the cleaning up of code.
modified on Friday, May 21, 2010 6:01 AM
|
|
|
|
|
I'd like to step through the Microsoft code for dawing a CTabCtrl. In winctrl2.cpp, CTabCtrl::DrawItem consists only of ASSERT (FALSE); When I put a breakpoint here, it is not hit. If I put a break at CWnd::OnDrawItem it is hit, but stepping through doesn't land in the drawing code, and I don't know where to put a break to see the code that does the computations for the drawing.
Can you tell me how to set a breakpoint so I can step through this code? Thanks.
modified on Thursday, May 20, 2010 6:05 PM
|
|
|
|
|
Hi,
I am trying to add a combo box to provide a list of choice to the user. I add it to a dialogue box and entered Listbox items, but when I try to run to see the list, it is not there. I guess I need more work to make it work for me.
Please direct me
Thanks
|
|
|
|
|
mrby123 wrote: ...and entered Listbox items...
How?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
By right click the combo box image -> property->Data tab
to do Enter ListBox Items
Thanks
|
|
|
|
|
You need to size the control by clicking on its down-arrow and draging the control to the desired height.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I got the combo box working. I can select an item and retrieve the value.
However, the combo box is empty by default if the user does not select an item.
How to set an default value if the user does not or forget to select a value?
Thanks
|
|
|
|
|
Use SetWindowText() or SetCurSel() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thanks. That works.
In the simple application I have two dialogue box. One is for input and the other for display results.
I use Edit box to display results of calculated numbers (float or int). Then each edit box have a tittle
above it by Static Text.
Ideally I can change the static text according to the input since this static text should show the unit of the
displayed numbers. The unit depends on the input selection of the units.
How to change the static text on fly by the application according to the input selection from the input combo box.
Thanks a lot
|
|
|
|