|
I take it back, it's WM_SHOWWINDOW. That's a windows message, which is what your command handlers like OnInitDialog handle. So, look for an OnShowWindow handler, or something like that. In VC6, it actually says the message, WM_SHOWWINDOW.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
well what i get from query all you need to do is use the Create method in the dialog class
something like this...
<br />
void OnInitDialog()<br />
{<br />
pPopUp = new CDialog;<br />
pPopUp->Create(IDD_DIALOG1,this);<br />
pPopUp->ShowWindow(SW_SHOW);<br />
}<br />
cheers
Sky is the limit
|
|
|
|
|
This ShowWindow function works well, however is there any way to make the second dlg be the focus and nothing can be done on the first dialog unless a choice is made on the second dialog?
|
|
|
|
|
LCI wrote: This ShowWindow function works well, however is there any way to make the second dlg be the focus and nothing can be done on the first dialog unless a choice is made on the second dialog?
Modeless window, so call .DoModal() instead of ShowWindow().
if(IDOK == dlg.DoModal())
{
// OK was returned from child modal window
}
else
{
// Cancel was clicked (IDCANCEL)
}
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
http://functionx.com/visualc/howto/calldlgfromdlg.htm
plz search this link it will help u and u understand how we call one dialog to another
|
|
|
|
|
LCI wrote: ...at this point that i would like to pop up another dialog. I can't seem to find where the program control will go next.
That all depends on whether the second dialog is modal or modeless.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Then control will naturally go to the second dialog's OnInitDialog() method. Control will not return to the first dialog until the second dialog has been dismissed.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Every program has the potential to run out of stack space. The following does so on purpose. I'm using Borland C++ Builder 5.5 and it doesn't throw an exception for stack overflows. I think Visual C++ does but it's using SEH, (not C++ exception handling), which is also not available in Borland C++ Builder. The program below just terminates after the stack overflows. The error message ("An exception was thrown. Probably out of stack space.") never prints. Is there anyway to handle stack over flow without using windows exceptions? Is it even possible to recover from a stack overflow? Any help would be appreciated.
<br />
#include <iostream.h><br />
<br />
void StackOverflow(int depth)<br />
{<br />
try<br />
{<br />
char blockdata[10000];<br />
cout << "Overflow: " << depth;<br />
StackOverflow(depth+1);<br />
}<br />
catch (...)<br />
{<br />
cout << "An exception was thrown. Probably out of stack space." << endl;<br />
}<br />
}<br />
<br />
<br />
int main(<br />
{<br />
StackOverflow(0);<br />
return 0;<br />
}<br />
-- modified at 16:59 Wednesday 27th September, 2006
|
|
|
|
|
risingtechie wrote: Is it even possible to recover from a stack overflow?
Not really. When you think about it, using exceptions would require placing more items on the stack, calling a function to clean up the stack would also require putting items on the stack first. Basically, once the stack overruns the heap, you are screwed.
However, this should rarely happen with the amount of memory applications are afforded in systems these days. Generally, when it does, it is a sign of a bug (like the code you posted shows).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks Zac,
What if this error happens during an operation that must be completed in it’s entirety or else something catastrophic happens. For example, maybe some massive amount of invaluable, irreplaceable data on secondary storage (like the U.S. Treasury's database mapping bond holder names to bond serial numbers) was being manipulated and becomes corrupted rendering it practically indecipherable. So, even though the risk of a stack overflow is minimal, let's say it's still too likely for comfort. I guess your only option is to keep regular backups and simply design your code in such a way that a stack over flow and any other unpredictable event that may occur doesn't cause any catastrophic loss. Am I correct in thinking this? I may sound like I'm being petty but I'm really just trying to live up to the highest standards of professional, robust, and secure software development. I guess I just don't know for sure what the limits are to how robust an application is expected to be. This issue is a constant thorn in my side.
|
|
|
|
|
Any recursive function will have a maximum depth possible. I would tend to ask design questions like 'what's the maximum value I could be passed here', then engineer it using values that will go twice as deep. That seems to me a reasonable margin for error.
The other thing is, don't use recursion unless it really makes sense to do so.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
If the stack goes to crap, the rest of your application is screwed. It wouldn't matter what data you were trying to store, it would be junk.
Generally, stack overruns are a sign of buggy code and poor implementations (or that you are forcing the stack size to be too small). There are rare occassions (mostly on embedded systems) that have issues with stack overruns, but even that is fairly rare these days. For guidelines on writing robust code, check out "Effective C++" (3rd ed) and "Effective STL" by Scott Meyers, and "Exceptional C++" by Herb Sutter. Those 3 books are invaluable.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
It's technically possible to recover from a stack overflow but extremely low level. It would involve more machine code then C/C++.
Steve
|
|
|
|
|
risingtechie wrote: Is there anyway to handle stack over flow without using windows exceptions?
When you run out of stack space, you'll end up trying to write to the guard page that's set up just beyond the end of the stack. This is what triggers the Stack Overflow exception, and any chance you have of handling it is going to have to work with SEH in some way, because that's how Windows does it. (yeah, you could probably write your own stack code, and compiler to go with it... but that's getting a bit excessive)
Handling the Stack Overflow exception is tricky - there's little or no stack left, so calling any methods will likely fail (the sort of failure where it's impossible for the OS to do anything but terminate the app and move on). If you really, really need it to work, you can use SEH or XP's Vectored Exception Handler support to catch the exception, and then immediately switch to another stack.
This is... decidedly non-trivial. And as Zac mentioned, if you're overflowing the stack, you probably have other problems with your program. There will be very little you can do to salvage the situation.
If you have the need for a system tolerant of such errors, you'll probably be better off using a separate watchdog program to monitor the main app, and restart it when things go wrong.
|
|
|
|
|
It is a wrong practice to implement stack with the help of array .u use linklist than ur problem will be solved
|
|
|
|
|
Hi There,
I have a virtual listview that I load up anywhere from 20,000 to 200,000 records into. The virtual listview handles this no problem at all. I am using the CSortedArray by PJ Naughter class to store a array of custom objects. I can sort the array very fast no problems.
My issue occurs when I have to do a keyword search. I have to be able to allow the user to search as they type into a text box. So the user starts off with a FULL list of ALL the items appearing in the virtual listview, as the type keys into the textbox the virtual listview starts drilling down and only showing items that have the letters being typed in the name. so simple example:
List
====
Greg
John
Steve
George
If the user types G in the text box the list will now look like below
List
====
Greg
George
I have this working using a simple for loop to loop through all the items at each keystroke and remove any items from the list that do not match the keys typed. However, when my list gets to 30,000 or higher the search begins to take up WAY too much CPU. Is there some faster way I can do search like this using the CSortedArry?
Thanks
Greg
|
|
|
|
|
Hi
You can use a Thread to process a binary search. The when search finish you can select or show the item(s)
David
|
|
|
|
|
ah ok thank you!
Do you know if there is any examples of where I can find how to do this?
Thanks,
Greg
|
|
|
|
|
If I understand correctly, you have a list of ordered elements, and a partial match. Binary search will help, but won't be exactly what you want.
To do something similar, I use a binary search which does a length restricted string comparison to find an element which matches, and then backs up to find the first match. For my application this approach is fine, since I only have a few items in each such grouping. Your mileage may vary.
However, a better approach, which someone has already suggested, might be to have a small array of indices into the array, keyed by first letter. Essentially something like this:
typedef struct index
{
TCHAR chr;
int start;
} INDEX;
CArray<INDEX, INDEX&>> ix;
INDEX in;
ix.RemoveAll();
in.chr = _T('\0');
in.start = -1;
for(i = 0; i < nElements; i++)
{
// get first char of this item...
chr = ....;
if (in.chr!=chr)
{
// make a new index entry
in.chr = chr;
in.start = i;
ix.Add(in);
}
}
in.chr = _T('\0');
in.start = nElements;
ix.Add(in);
To do your search, look in the ix array for a matching first character, get the start index from the matching entry, and the stop index from the next entry
This gives you a smaller space to do additional matching if necessary.
Steve S
Developer for hire
|
|
|
|
|
Greg Ellis wrote: I have this working using a simple for loop to loop through all the items at each keystroke and remove any items from the list that do not match the keys typed. However, when my list gets to 30,000 or higher the search begins to take up WAY too much CPU.
With that many items, you are going to eat up a lot of CPU time anyway. A map or hash table would allow for more efficient searching, but with an array (even a sorted one), you are still going to be stuck with an O(n) operation. Additionally, if you have 30,000 items in the list, and your search will only find 1 entry, the list control has to do a LOT of work to remove 29,999 items. So don't be surprised to see a CPU/Memory spike for a second or two.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Instead of using a single array to hold all the data, why not break it up into say 27 arrays (one for each letter of the alphabet and numbers). You would have to create an algorithm for adding items to the correct array and choosing the correct array depending on the first character entered.
|
|
|
|
|
Try something like this. It uses binary searches so it will be many, many times faster then using linear searches. It’s a simple console app which reads in words from a file (each word in the file separated by any white space). It is not limited to only matching a single charcter; you can match all words which start with "act" for example.
------------------------
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
struct PrefixMatchLess : std::binary_function<std::string, std::string, bool>
{
bool operator()(const std::string &s, const std::string &prefix) const
{
const std::string sub = s.substr(0, prefix.length());
return sub<prefix;
}
};
struct PrefixMatchGreater : std::binary_function<std::string, std::string, bool>
{
bool operator()(const std::string &prefix, const std::string &s) const
{
const std::string sub = s.substr(0, prefix.length());
return sub>prefix;
}
};
int main()
{
// For notational convenience.
using namespace std;
typedef vector<string> StringList_t;
typedef istream_iterator<string> StringInIt_t;
typedef ostream_iterator<string> StringOutIt_t;
// Open the word list.
ifstream ifs("C:\\Words.txt");
if (!ifs)
{
cerr << "Failed to open word list!" << endl;
return 1;
}
// List for words.
StringList_t words;
// Read in the word list.
copy(StringInIt_t(ifs), StringInIt_t(), back_inserter(words));
// Sort the list and remove duplicates.
sort(words.begin(), words.end());
words.erase(unique(words.begin(), words.end()), words.end());
// Output the word list (diagnostic).
cout << "Word list:" << endl;
copy(words.begin(), words.end(), StringOutIt_t(cout, "\n"));
cout << endl;
for(;;)
{
// Get the prefix to search for.
string word;
cout << "Enter search prefix (! quit): ";
cin >> word;
// Check if the user wants to quit.
if (word=="!")
{
break; // Quit.
}
cout << endl;
// Calculate range.
StringList_t::iterator b = lower_bound(words.begin(), words.end(), word, PrefixMatchLess());
StringList_t::iterator e = upper_bound(b, words.end(), word, PrefixMatchGreater());
// Output results.
cout << "Matching words:" << endl;
copy(b, e, StringOutIt_t(cout, "\n"));
cout << endl;
}
return 0;
}
Steve
|
|
|
|
|
I am a beginner trying to clear the edit box of a combobox in drop list mode after making a selection from the list.
after selecting a list box entry, the control places a copy of it in the edit box by default, apparently using the SelectString member and the message WM_SETTEXT as part of the controls windows procedure.
when the dropdown type is used, ->SetEditSel and ->Clear etc will empty the edit box, (though not very elegantly). but the dropdown type still allows users enter text in the edit box (which is confusing and non-functional)
the drop list type prevents user edits of the edit box, but ->SetEditSel and ->Clear etc no longer appears to clear the edit box to pretty things up after selection.
I have tired many things already, and am considering trying to trap WM_SETTEXT or paint over the edit box somehow
I wonder if I am not missing some ridiculously minor thing (as I was before I realized the drop list type prevented user edits to the edit box)
Any suggestions about what I can do with/to my combobox control to prevent, clear or overwrite unwanted edit box text matching my selection in the list box?
Thanks to all...
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
I'm not exactly sure what the issue here is. For a combobox having the CBS_DROPDOWNLIST style, once a selection is made, the dropdown part of the control goes away and the edit part of the control reflects whatever was selected. What's to clear?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|