|
Search the MSDN for
"Spawn Console Processes with Redirected Standard Handles"
Q190351
Also I seem to remember there is an example on CP using the above method.
"There is no monument dedicated to the memory of a committee." - Lester J. Pourciau
|
|
|
|
|
One solution is pipe as the other member has mentioned. Check out MSDN.
http://support.microsoft.com/default.aspx?scid=kb;en-us;190351
Kuphryn
|
|
|
|
|
I wrote email program which works fine, but the problem I have is resolving domain name server. For example if I want to send email to somebody@yahoo.com, the server is not really yahoo.com but rather mx2.mail.yahoo.com. My question: are there any API functions to querry DNS to get me the real server name, after which I can use gethostbyname() and send the email.
Thanx,
|
|
|
|
|
One solution is via getaddrinfo() and getnameinfo().
Kuphryn
|
|
|
|
|
Hi,
How do i disable a popup menu item in runtime (or change it's property to grayed) ?
For a regular menu item i would use the ON_UPDATE_COMMAND_UI macro, with the menu item's ID and the handler function. the problem is that a a popup menu item has no ID!
Does antone have an idea?
Regards,
Oren.
|
|
|
|
|
oren frenkel wrote:
the problem is that a a popup menu item has no ID!
Actually, you are wrong...
You have to give each item an ID when you are creating it. Either in resource editor,
or when you add each line.
BOOL AppendMenu( UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );
Off the top of my head, to get the ON_UPDATE_COMMAND_UI stuff working, just give
TrackPopupMenu your main window.
int nResult = mPopup.TrackPopupMenu (
TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
pt.x, pt.y, AfxGetMainWnd () );
Iain.
|
|
|
|
|
Hi every one...
I need to calculate the time in millisecondes to find an element in this array
in another way i want to calculate this time to compare between the binary search and the sequential search..
Pleae help me
|
|
|
|
|
Naif620 wrote:
...i want to calculate this time to compare between the binary search and the sequential search
Why bother? For three items and greater, a binary search will always take less time than a sequential search. The search time for for a binary tree is O(lg N) in the worst case. For sequential lists, the search time is O(N) in the worst case.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Brother I need to prove this by time,this is my taecher want.
|
|
|
|
|
If you are not interested in accuracy, try something like:
DWORD dwStart = GetTickCount();
DWORD dwStop = GetTickCount();
cout << (dwStop - dwStart) / 1000.0 << " seconds\n";
Another way that involves a bit more could would be:
unsigned __int64 nFreq;
QueryPerformanceFrequency((LARGE_INTEGER *) &nFreq);
unsigned __int64 nStart;
QueryPerformanceCounter((LARGE_INTEGER *) &nCtrStart);
unsigned __int64 nStop;
QueryPerformanceCounter((LARGE_INTEGER *) &nCtrStop);
cout << (nCtrStop - nCtrStart) / nFreq << " seconds\n";
But given that Windows is not a RTOS, you'll always be at the mercy of the hardware in terms of resolution.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hello everyone,
I have been working on an MFC SDI program whose Document actually has lists of lists (and possibly a list of a list of a list). I would like to get into a good habit and be consistent with the way I maintain collections (mostly lists, occasionally arrays and maps). Almost all my objects are derived from CObject (for serializing, etc.).
I guess it comes down to picking between CList<type, type>, CList<type, type&>, CList<type*, type*> and whatever other combinations. To keep sane, I think I always want to use CList<type*, type*>. That way, I just use the new operator at the point where an object needs to be instantiated and call delete on it (while traversing the list or sublist) at the 'outer' list's destructor.
I would like comments about this. Is it safe? Is it a decent practice to keep? How can I prevent double deleting the same objects (if that could even happen)? Does this choice affect how I code the required copy constructor and assignment operator (which always seem to involve references)?
Thanks in advance for any advice and comments!
Eric
|
|
|
|
|
Cloaca wrote:
To keep sane, I think I always want to use CList.
MFC containers are utter crap. Use std::list instead and you'll find a lot of the ancillary code you need to write will already be there for you.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Thanks for your tip Christian.
I will look around to learn how to make std::list (part of the STL, right?) work with MFC (including topics like Serialization, etc.).
If you could suggest any resources in particular, that would be great.
Thanks again!
Eric
|
|
|
|
|
It depends whether you want homogeneous (containing one type of object only) or heterogeneous (containing multiple types of object) containers.
If I want a homogeneous container, I typically have the container manage the storage of the contained objects. If the objects are small (perhaps int s), I use a CList< int, int >. If the objects are larger than about 8 bytes, I use CList< T, const T& > so that any functions which need an object (to store it, or compare it) take their argument by constant reference. You don't need to do any extra clean-up when you destroy the container; it destroys all the elements for you.
For a concrete definition of a heterogeneous container, consider a class hierarchy modelling shapes. We have an abstract base class CShape with derived classes CRectangle , CEllipse and CPolygon (for example). We want the container to be able to hold any combination of rectangles, ellipses, polygons and whatever else we might define in future.
To get polymorphic behaviour, we must store base class pointers. So I would normally declare the container as storing pointers of the type of the most-derived base class common to the elements to be contained. In this case I would use a CList< CShape*, CShape* > . The ARGTYPE is a CShape* because pointers are trivial to copy.
Lists of lists are tricky in MFC because CList doesn't define a copy constructor or assignment operator. You can't contain a CList inside a CList (although you can store CList pointers). If the top-level list is heterogeneous, you probably do need to use a list of CObject pointers, and MFC has a special class for that: CObList.
|
|
|
|
|
Hi Mike,
I appreciate your response. From what you wrote it looks like if I need to maintain a collection of different objects (but all derived from a common base), then a CList< baseclass*, basclass*> is the way to go (which is what I had been thinking for 'my sanity's sake').
For trivially small things (e.g. ints), a CList<int, int> is good. This sounds good to me.
You wrote: "If the objects are larger than about 8 bytes, I use CList< T, const T& > so that any functions which need an object (to store it, or compare it) take their argument by constant reference."
What is the advantage of doing CList<T, const T&> over CList<T*, T*> ? Or, alternatively, is there a reason not to do CList<T*, T*> all the time?
Thanks again!
Eric
|
|
|
|
|
I prefer the version without the pointers for three reasons:- I don't have to clean up the list myself (CList doesn't delete objects pointed to in the destructor).
- I don't have to handle indirections.
- The list has less memory-management overhead.
I'll deviate from this if I have to store references to the same object in multiple places in a list, but this is less common.
|
|
|
|
|
Hi Mike,
Thanks again.
About reason 1.: Most times, the objects that are in a list are made using a call to 'new' at some point in the code. If this is the case, then the contents of the list (the newed objects) need to get deleted at some point anyway. And this must be done by walking through the list in a loop to call delete for each item before doing a RemoveAll() on the list.
Or, do you have a methodology in coding that 'recycles' objects. That is, a variable of type CMyObject is declared and reused (has its data changed) whenever an item needs to be added to the list. Then, due to storing actual T's (not T*'s or T&'s), they are passed by reference into the CList by value (so that the declared variable can be changed for reuse to create the next item in the list). Is this what you mean? Does this mean that the destructor for each item in the list is called when the CList is destroyed?
Thanks very much,
Eric
|
|
|
|
|
Hello,
I have a question. I have a dialog style window. Is it possible to add text display box to it? I plan to display some text at run time. Thanks.
|
|
|
|
|
|
I need to write a program to run a few hundred executables, and read in their results into an array.
i've posted here, before and got help. using SHELLEXECUTEINFO i can specify the .exe and a paramater. which is really cool
but the upon executing, i get a HANDLE back
i was told to monitor the handle, but how?
i need to see the values that the .exe printf() 'ed onto the command line...
this is only a small part of the project and i dont have time to go learning all the details of handle programming...
so if anyone can help me out here it'd be soo cool
thanks
PS: i need to get this done soon, so any awnser would be great
|
|
|
|
|
|
One solution is pipe as the other member has mentioned. Check out MSDN.
http://support.microsoft.com/default.aspx?scid=kb;en-us;190351
Kuphryn
|
|
|
|
|
Dear all,
How could I calculate the execution time of a function?
I used CTime, CTimeSpan, GetTickCount but the result is always zero.
Islam Hegazy
islam
|
|
|
|
|
you could SetTimer() berfore calling the proc and KillTimer() after the proc returns. in the timer proc you can then increment a variable counting the amount of ms or secs depending on what interval you've specified.
hope this helps...
|
|
|
|
|
Hi,
This is the way to do it through the Windows API function:
SYSTEMTIME sStart, sEnd;
float fEllapsedSec, ffEllapsedSecModulu;
long lEllapsedDays, lEllapsedHours, lEllapsedMin, lEllapsedSec, lEllapsedMilliSec;
CString strFuncTime;
::GetSystemTime(&sStart);
// call your function:
func();
::GetSystemTime(&_sEnd);
lEllapsedDays = sEnd.wDay - sStart.wDay;
lEllapsedHours = sEnd.wHour- sStart.wHour;
lEllapsedMin = sEnd.wMinute - sStart.wMinute;
lEllapsedSec = sEnd.wSecond - sStart.wSecond;
lEllapsedMilliSec = sEnd.wMilliseconds - sStart.wMilliseconds;
lEllapsedHours += lEllapsedDays*24;
lEllapsedMin += lEllapsedHours*60;
lEllapsedSec += lEllapsedMin*60 ;
// the total number of seconds:
fEllapsedSec = (float)lEllapsedSec + (float)lEllapsedMilliSec / 1000;
// for gui presentation:
lEllapsedHours = ((long)(fEllapsedSec / 3600));
lEllapsedMin = ((long)(fEllapsedSec / 60)) % 60;
ffEllapsedSecModulu = fEllapsedSec - ((int)(fEllapsedSec / 60) * 60); // cant use modulu on float
strFuncTime.Format("%d:%d:%.3f",lEllapsedHours,(lEllapsedMin % 60),ffEllapsedSecModulu);
|
|
|
|