|
That is the problem with the ... catch all operator, there is no way to get the error information. This should be used as a just in case mechanism.
Hopefully you know what type of error will be thrown and you can look for that particular type of exception.
try
{
}
catch (CException &err)
{
}
catch (DWORD &err)
{
}
catch (...)
{
}
You can catch class objects, native data types or do the catch all. The most important thing to remember is to place the exception catch code that is the most detailed or most important to you first in the chain. Because if it is possible for the exception to be casted or converted into one of the other forms in order for the handler to work, it will.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
To add to Paul's excellent comments:
It's best to derive all your exception classes from one base class, such that you can simply catch any of them in one clause. Then you can leave the catch(...) clause for things that would not otherwise happen if your code were bug-free, such as access violations.
try
{
...
}
catch (BaseExceptionClass& e)
{
}
catch (...)
{
}
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
I have two sets set1, set2. They have some elements in commmon. I want to make a set3 which is the unique elements from both set1 and set3.
What i mean is if set1 has a,b,c,d,e
set2 has b,c,e,f,g,
Then I want set3 to have in it: a,b,c,d,e,f,g. I'm using a set because it wont have duplicate elements. But I dont know if you can do:
set3 = set1+set2?
Do I have to use iterators and do something like copy both set1, set2, into set3?
Appreciate your help,
ns
|
|
|
|
|
|
Daniel Turini wrote:
You can use STL's set_union available in #include <algorithm>
You can still run into duplication with set_union, here is an example I found showing this:
inline bool lt_nocase(char c1, char c2) { return tolower(c1) < tolower(c2); }
int main()
{
int A1[] = {1, 3, 5, 7, 9, 11};
int A2[] = {1, 1, 2, 3, 5, 8, 13};
char A3[] = {'a', 'b', 'B', 'B', 'f', 'H'};
char A4[] = {'A', 'B', 'b', 'C', 'D', 'F', 'F', 'h', 'h'};
const int N1 = sizeof(A1) / sizeof(int);
const int N2 = sizeof(A2) / sizeof(int);
const int N3 = sizeof(A3);
const int N4 = sizeof(A4);
cout << "Union of A1 and A2: ";
set_union(A1, A1 + N1, A2, A2 + N2,
ostream_iterator<int>(cout, " "));
cout << endl
<< "Union of A3 and A4: ";
set_union(A3, A3 + N3, A4, A4 + N4,
ostream_iterator<char>(cout, " "),
lt_nocase);
cout << endl;
}
The output is
Union of A1 and A2: <font color="red">1 1 2 3 5 7 8 9 11 13</font>
Union of A3 and A4: <font color="red">a b B B C D f F H h</font>
I suppose you could sort your two maps and create a third where you use an interator and the find function to make sure that you have only added the value from either maps when it is not in map number 3 based on the iterator. A simple for loop should do the trick, however maybe someone else has a more efficient method to do this.
HTH
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
|
Daniel Turini wrote:
Isn't the purpose of the set class being a container of unique items?
I haven't been playing around with STL very much, I was reading this[^] when I saw the message come up. You could be correct.
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
The following example shows using set_union to do a union of sets:
<br />
using namespace std;<br />
<br />
<br />
class PrintInt<br />
{<br />
public:<br />
void operator() ( int value )<br />
{<br />
cout << value << endl;<br />
}<br />
};<br />
<br />
<br />
int main()<br />
{<br />
set<int> setA;<br />
set<int> setB;<br />
set<int> setC;<br />
<br />
setA.insert( 1 );<br />
setA.insert( 3 );<br />
setA.insert( 5 );<br />
setA.insert( 7 );<br />
setA.insert( 9 );<br />
<br />
<br />
setB.insert( 2 );<br />
setB.insert( 3 );<br />
setB.insert( 4 );<br />
setB.insert( 5 );<br />
<br />
set_union( setA.begin(), setA.end(), setB.begin(), setB.end(), inserter(setC,setC.begin()) );<br />
<br />
cout << "setC Contents:" << endl;<br />
for_each( setC.begin(), setC.end(), PrintInt() );<br />
<br />
return 0;<br />
}<br />
Best regards,
John
|
|
|
|
|
Thanks so much for the detail. I hadnt figured this out yet...so I'm gladyou showed me how!
Appreciate your help,
ns
|
|
|
|
|
Hi.
I am using WH_CBT hook to trap WM_CREATE message. I want to get the handle,className …………. form CRETESTRUCT pointer which is in the lParam
I cant retrieve this information I tried every thing I know. Can some body please
Help me
Regards
Gau.
;);P
Gaurika Wijeratne. // www.gaurika.com
|
|
|
|
|
What have you tried, and what are you experiencing that is preventing from letting you get this information?
I just want to be clear on one other thing, are you using the CREATESTRUCT structure?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Yes I am using CREATESTRUCT structure.
it doesn't give any errors. I casted the lParam to CREATESTRCT and trying to
get the class name from it. but nothing is coming.
but when I put a catch with "..." ,it is catching a error.
I just want to check the class name with a string and destroy the window if it is a match....
Gaurika Wijeratne. // www.gaurika.com
|
|
|
|
|
It looks to me that the CREATESTRUCT structure is not used directly.
I beleive that it sends a CBT_CREATEWND structure instead, and embedded in that structure is the CREATESTRUCT structure.
[msdn]
CBT_CREATEWND
The CBT_CREATEWND structure contains information passed to a WH_CBT hook procedure, CBTProc, before a window is created.
typedef struct tagCBT_CREATEWND {
LPCREATESTRUCT lpcs;
HWND hwndInsertAfter;
} CBT_CREATEWND, *LPCBT_CREATEWND;
[/msdn]
Try that and see if it helps
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
The name may also be stored in an ATOM. Then you can use GetAtomName or GlobalGetAtomName to get the string involved. I don't remember the exact sequence, but FindAtom or GlobalFindAtom might be involved.
Joel Lucsy (jjlucsy@concentric.net)
|
|
|
|
|
Hey, can anyone give me any ideas on where I can look for some info/examples of how to do FTP. I am looking for a way to get an FTP address, password, and username, establish an FTP session, send file(s), close the session, then periodically open the FTP session and see if any files are being FTP'd to me. This functionality is new to me. I am not sure where to look for articles, I am using MFC/C++, no C# or anything like that.
|
|
|
|
|
Yes, search CodeProject!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I hate answers like these because I usually do look through the articles first and post questions when I cannot find an answer. So, just to let everyone know, I DID SEARCH CODEPROJECT? I found 2 articles, basically. And neither were that good. I would like information on how to create this not how to download source code someone else has put together. Any other ideas?
|
|
|
|
|
I'm sorry, but you didn't tell!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
This should get you going. CFtpConnection. Not sure how many people use the wininet stuff, but this seems to do the job.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Please HELP!
I have a CPropertyPage class...
I have changed the constructor from
CMeasureItemsPage();
to
CMeasureItemsPage(CRoom* pRoom);
I need this, because the page of the property sheet must working with this member!
After this change Visual C++ says:
error C2512: 'CMeasureItemsPage' : no appropriate default construc
The error is at the following line:
IMPLEMENT_DYNCREATE(CMeasureItemsPage, CPropertyPage)
What's wrong? Why does the IMPLEMENT_DYNCREATE macro needs a default constructor?
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Try changing your constructor to:
CMeasureItemsPage(CRoom* pRoom = NULL);
IMPLEMENT_DYNCREATE is used for MFC objects that are "dynamically created" by the framework (for example, when they are serialized to/from a file). Adding the = NULL default argument satisfies the requirement for a default constructor. It sounds like you're not going to doing anything that requires it, but you could add a check in your constructor:
if (pRoom == NULL) {
}
in order to handle that case.
Gary R. Wheeler
|
|
|
|
|
Thanks!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I have recently taken over development of an application that uses modal dialogs for everything and they are designed to overlap each other (full screen windows ce device). This scenario worked fine until a request came in to 'skin' the app for use on the local machine while demoing the program.
I can get the first dialog converted over to be a child view and run in my 'skin' container dialog but soon as I try showing the other screens, they go modal which takes a way any control of the skin. Plus the dialogs begin competing with each other and begin overdrawing each other (raw painting to the screen, and now child controls).
Finally it seems that the message pump for key presses stays with the first child even if set focus is sent to the new child dialog that is sitting on top.
My question is this: How would I make modal modelesss dialogs - ie I want to behave as if they were modal but not be modal to the skin dialog so it can still receive mouse clicks and key presses. I feel this would also help with the competition of the drawing code so the screen doesn't swap between dialogs.
Please Help.
Sincerly,
Clint Singer
|
|
|
|
|
You can look at how MFC implements DoModal, and do something similar to that.
Basically a modal dialog is just a modeless dialog, where a second message pump has been placed on the stack in order to process the messages, and the parent window of the modal dialog has been disabled to prevent focus from going back to the parent window.
When you create your own message loop, one other thing to be aware of is that you will need to be sure to call IsDialogMessage to dispatch your dialog messages. THis is how the tab control and other special dialog functionality is performed.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi, all
I created a Dropdown ComboBox. now I want to handle the CBN_EDITCHANGE message. At that time, how can I get the text in the editbox of the combobox box? I know one way is to use UpdateData, but it will update all the data include other controls, how can I just get the text of the combobox?
Thanks in advance
|
|
|
|
|