|
Hi,
I am executing an exe file using CreateProcess. Is there any mechanisam to check wheather the .exe file is already running or not .
Thanks and Regards,
Venkat
|
|
|
|
|
Do a search for "single instance" - you'll find a few articles on the subject.
|
|
|
|
|
use PROCESSENTRY32
never say die
|
|
|
|
|
Use PROCESSENTRY32 as mentioned earlier.
See this[^] article about its usage.
|
|
|
|
|
Example For You:
HANDLE hWatchDog;
CProcessMonitor mProcessMonitor;
hWatchDog = mProcessMonitor.GetHandleToProcess("WatchDog.exe");
if(hWatchDog != NULL)
{
TerminateProcess(hWatchDog,0);
}
CProcess Monitor is the class, which is implemented using PSAPI.
HANDLE CProcessMonitor::GetHandleToProcess(CString ProcessName)
{
HANDLE hProcess;
hProcess = NULL;
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];
strcpy(szTargetProcessName,ProcessName.GetBuffer(50));
ProcessName.ReleaseBuffer();
ULONG lCpuusage = 0;
UINT index;
//Find Total Number of Processes;
if (!EnumProcesses( mAvailableProcesses, sizeof(mAvailableProcesses), &cbNeeded ) )
return hProcess;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
if(cProcesses > 1000)
{
AfxMessageBox("There are Too Many applications Running on PC.");
}
for ( index = 0; index < cProcesses; index++ )
{
hProcess= GetProcessHandle(mAvailableProcesses[index],szTargetProcessName);
if(hProcess != NULL)
{
return hProcess;
}
}
return hProcess;
}
I think this should be enough for you....
haribabu
(Impossible to understand )
|
|
|
|
|
Use a separate thread to call CreateProcess and then a WaitXXX call.
DWORD WINAPI
_thWaitProcess(LPVOID pvParam)
{
HANDLE hProcess = ::CreateProcess( parameters_from_pvParam);
HANDLE hLeaveEvent = get_leave_event();
HANDLE Handles[2] = {0};
Handles[0] = hProcess;
Handles[1] = hLeaveEvent;
WaitForMultipleObjects(2, Handles, FALSE, INFINITE);
return 0;
}
|
|
|
|
|
I want to draw an open line which smoothly passes several (or any number of) points.
those points are set by user with mouse clicking.
do you know any formula suitable for c++ code to draw the smooth line passing all of those points?
|
|
|
|
|
includeh10 wrote: want to draw an open line which smoothly passes several (or any number of) points.
A line, or straight line, can be described as an infinitely thin, infinitely long, perfectly straight curve.
Three or more points that lie on the same line are called collinear.
So for you, if the user clicks on different points that are not collinear than it won't be possible for you to connect this points using one single line. You would need to store the points in an array (or whatever you prefer) and then draw a line betweent the consecutive points.
You could prefer a curve if you want to connect these points but a single line won't do it, unless and until the points are collinear.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
Use a spline!
You can implement it with polynomial expression joining 3 or 4 points each time and then join the splines obtained to get a continuos line.
Cheers,
Russell
|
|
|
|
|
I is what I am thinking.
Any existing code or formula to get related params for >=3 (4 or more is prefered) points?
|
|
|
|
|
Here you can fine some interesting formula
http://www.codeproject.com/useritems/SplineInterpolation.asp
Cheers,
Russell
|
|
|
|
|
|
A modelless dialog with child property is created on a main dialog,just like notepad with find dialog been opened,except the modeless dialog has a List Control.
now do it like this:
set focus(click the left mouse button) to the List Control(if the List Control's tab order is not 1) firstly,secondly, minimize the main dialog, then restore it.
now you will find the problem: the List Control remains not refreshing!
|
|
|
|
|
eat_union wrote: the List Control remains not refreshing!
What does this mean ?
|
|
|
|
|
the List Control remains not refreshing
means that the List Control does not be displayed.
I'm a chinese.
I'm so sorry to my poor english.
|
|
|
|
|
eat_union wrote: the List Control remains not refreshing
means that the List Control does not be displayed.
How you are creating list box ? One place its creation could be in in WM_INITDIALOG handler.
eat_union wrote: I'm so sorry to my poor english.
Never mind. You can count me one with you.
|
|
|
|
|
You need to show , how you have created list box ?
|
|
|
|
|
|
Oh ! I'm not able to reproduce said behaviour. May be you can try it with other application. And see the difference.
|
|
|
|
|
thanks for your help!
I do the same operation in another simple project, and the problem cant not be reproduced too,
I will try to find my fault.
thanks.
|
|
|
|
|
That's cool. All the best. Do post, when you find ,what you was doing wrong.
|
|
|
|
|
Yes it can be refreshed correctly.
Probably you mean redraw, not refresh. Anyway, it's the programmer's job to handle WM_ACTIVATE, WM_SETFOCUS etc.
Could be a SetRedraw with FALSE without a SetRedraw with TRUE?
|
|
|
|
|
yes, i mean that the List Control disappeared.
when the main dialog being restored, i add some code:
<br />
CDialog::OnSysCommand(nID, lParam);<br />
if (SC_RESTORE == (nID & 0xFFF0) && hRefresh)
::RedrawWindow(hRefresh, 0, 0, RDW_FRAME | RDW_INVALIDATE);<br />
now, program is solved, but i want to know why.
|
|
|
|
|
Check with spy++ the list size and visibility while the main dialog is minimized.
|
|
|
|