|
I just did.
|
|
|
|
|
Me too; fascinating, you learn something new every day.
The best things in life are not things.
|
|
|
|
|
yu-jian wrote: I use "(CMainFrame*)AfxGetMainWnd;" to get CMainFrame pointer
Isn't this just getting the address of the AfxGetMainWnd() function rather than actually calling it?
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Exactly and so typecasting it to a CMainFrame* is like taking a roller coaster ride standing up.
|
|
|
|
|
Thanks for every one's replies.
I know that AfxGetMainWnd is the pointer of function AfxGetMainWnd,
the statement, (CMainFrame*)AfxGetMainWnd converts a wrong pointer to CWnd*.
|
|
|
|
|
I would like to create a service or background running program (something that minimizes to system tray).
It would have a path list of external applications, eg.
- C:\App1\Task1.exe
- C:\App2\Task2.exe
- C:\App3\Task3.exe
It would start the first one and monitor the process details (CPU Usage, Mem Usage, and maybe I/O Writes). Each application will do their jobs for a couple of minutes then go idle - hence completed the task. At this point the CPU Usage = 0, Mem Usage, etc. will be idle.
Then I need to close/kill that process and start the next application in the list. And this repeats as above and so on.
Does anyone know how to execute an external program, monitor the process details, then kill it?
|
|
|
|
|
Why can't the program exit by itself once it's done?
When you create a process, you can wait on the process handle, and it will signal when the process closes.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
andwan0 wrote: Does anyone know how to execute an external program
CreateProcess[^]
|
|
|
|
|
That isn't ideal of course.
The reason is that it isn't deterministic. You don't know it is done but rather you are guessing it.
As an example where there could be real problems if one process is relying on an external server and there are network problems it could take a minute for the server to send a response. During which time the process is blocked - and thus not doing anything.
At a minimum you are going to need to wait a significant amount of time to be sure it isn't doing anything.
|
|
|
|
|
You can start an application using CreateProcess .
If you plan to run the process from a service, you may need to use CreateProcessAsUser or CreateProcessWithLogonW or CreateProcessWithTokenW instead.
To monitor a process there are several functions available like GetProcessMemoryInfo , InitializeProcessForWsWatch , GetProcessIoCounters , QueryProcessCycleTime etc.
To kill a process, you can use the TerminateProcess function, but this is not recommended as this is an unconditional termination. Instead you must have some sort of built in mechanism in the process for it to terminate itself. This could be by sending a message or by setting an event if you want to control it from a service.
|
|
|
|
|
INT* pInt = new int ;
LPVOID pVoid = pInt ;
delete pVoid ;
will pVoid(object) be deleted cleanly as "delete pInt" does? I am a little worried since there's no way to indicate the object size.
|
|
|
|
|
With "basic" types it might work.
With doing this with a "real" classes it will not call the class destructor and will lead to memory leaks
Watched code never compiles.
|
|
|
|
|
I'm pretty sure it'll work with standard types, and for classes, it's undefined behavior. So it should be avoided anyway.
|
|
|
|
|
delete will try to call the destructor of the object that the pointer is pointing to, and then deallocate the memory associated (by calling operator delete for that object). If you cast the type away to void, then there's no destructor associated, and as a result, all the memory will not be de-allocated properly.
I also do not understand why would you need to do such a thing.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
I use lParam of LVITEM to hold some struct address like CREATESTRUCT, PAINTSTRUCT, I new/malloc blocks of memory for them. When the listview control is about to destroy. I want to delete/free the lParam which points to a struct object. Because the object is dynamically allocated, I cannot determine its exact type. so I wish I could do the lazy job, simply delete/free the pVoid expecting that wouldn't cause too much trouble.All of windows structures don't have constructors.
|
|
|
|
|
this seems like a good place for an abstract base class with a virtual destructor and a derived class for each of the types you want to pass around.
or, you could do it with a simple struct:
struct cMyStruct
{
typedef enum {eInt=0, eDouble, eCreateStruct, ePaintStruct} eTypeID;
void *pData;
eTypeID typeID;
cleanUp()
{
switch (typeID)
{
case eInt:
{
int *p = (int *)pData;
delete p;
pData = NULL;
}
break;
etc...
}
}
};
just pass that around, initialized properly, of course.
|
|
|
|
|
Cold_Fearing_Bird wrote: Because the object is dynamically allocated, I cannot determine its exact type.
So the items in the listview "point to" different types of data? If that's the case, wrap the data and the type in a struct like:
struct data_and_type
{
int type;
PVOID data;
};
data_and_type *dt = new data_and_type;
dt->type = 0;
dt->data = (CREATESTRUCT *) new CREATESTRUCT;
SetItemData(..., (DWORD) dt); Now when you are ready to delete:
dt = (data_and_type *) GetItemData();
if (dt->type == 0)
{
CREATESTRUCT *cs = (CREATESTRUCT *) dt->data;
delete cs;
}
else if (dt->type == 1)
... Clear as mud?
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
DavidCrow wrote: dt->data = (CREATESTRUCT *) new CREATESTRUCT;
Any particular reason for the explicit cast?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: Any particular reason for the explicit cast?
Yes. I had not typed enough this morning and was simply trying to meet my quota.
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Cold_Fearing_Bird wrote: I new/malloc blocks
Are you sayiny you can't even tell what method you used to allocate memory? In that case you must make sure that you are calling the proper destruction method, i. e. either free() or delete (or, maybe delete [] ?). I fyou don't take care of that and use the wrong method, your program will crash at runtime.
Wherever you get the pointer from, you must add a release() method there that takes care of the proper destruction and deallocation. This most probably will involve virtual destructors in case of classes, or some other method of indirection.
|
|
|
|
|
no
does that even compile?
|
|
|
|
|
it does compiles on VS2008.
Watched code never compiles.
|
|
|
|
|
Hi all,
I have one parent dialog where in OnPaint Function i am drawing some rectangles.
On that dialog i am opening one more child dialog,
I am making that child dialog as modeless,so that i can move that dialog
I want to keep the modless dialog active even when i click on the parent dialog,so that i can move rectangles.
OnLButtonDown i need to redraw the rectangles and even keep the dialog visible.
But when i click the Mouse LButtonDown,my child dialog is getting dissappeared
void Test::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rcClient(170,414,170,415);
LeafDialog::GetClientRect(&rcClient);
if((xp<415 && xp >140) && (yp>100))
{
InvalidateRect(rcClient,false);
LeafB[0]=100;
LaefA[0] = 100;
}
}
On Test View i am creating dialog
void CTestView::OnLoadImage()
{
CBitmapimage* dlgbmp;
dlgbmp = new CBitmapimage;
dlgbmp->Create(IDD_DIALOG1,this);
dlgbmp->ShowWindow(SW_SHOW);
}
Can anyone tell me what can i do so that even i can move the image and redraw on the parent dialog when clicked on the rectangle
Thanks
Sharan
|
|
|
|
|
It sounds like the modless child dialog needs to have the HWND_TOPMOST position in the tab order so it never gets to go behind its parent window.
See the SetWindowPos function for details. You may have to be careful in its use as the modless window should not sit in top most mode when you application does not have focus.
If you vote me down, my score will only get lower
|
|
|
|
|
"UnitTest" is on the VC's main menu,I want to use itto test my C++ code, but I am not familiar with its mechanism.
I wrote a little code expecting to learn how it works.But seems not work.
here's my code
class myClass
{
private:
int m_i ;
public:
myClass( int i ):m_i(i){ }
BOOL EQ( int i )
{
if( m_i == i )
return TRUE ;
else
return FALSE ;
}
} ;
int main()
{
myClass mc( 10 ) ;
}
I click "new UnitTest", go through a few steps,when trying click the checkbox besides my project name, there's always a msg reporting unsuccessful "Unknown virtual address 0".
Waiting for help...
modified on Thursday, July 21, 2011 5:09 AM
|
|
|
|