Click here to Skip to main content
15,897,032 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCreate Windows Service with C++ Pin
andysmurfen21-Apr-04 4:04
andysmurfen21-Apr-04 4:04 
GeneralRe: Create Windows Service with C++ Pin
Antony M Kancidrowski21-Apr-04 5:06
Antony M Kancidrowski21-Apr-04 5:06 
GeneralRe: Create Windows Service with C++ Pin
tareqsiraj21-Apr-04 5:27
tareqsiraj21-Apr-04 5:27 
GeneralRe: Create Windows Service with C++ Pin
Mike Dimmick21-Apr-04 6:00
Mike Dimmick21-Apr-04 6:00 
QuestionHow do I type a System._ComObject? Pin
mhuslig21-Apr-04 4:03
mhuslig21-Apr-04 4:03 
QuestionHow do I close a running program? Pin
IronMaiden42021-Apr-04 3:53
IronMaiden42021-Apr-04 3:53 
AnswerRe: How do I close a running program? Pin
jmkhael21-Apr-04 3:54
jmkhael21-Apr-04 3:54 
GeneralRe: How do I close a running program? Pin
Shail_Srivastav21-Apr-04 5:14
Shail_Srivastav21-Apr-04 5:14 
you can close program by two method
1. by sending WM_CLOSE, you have to find the window using FindWindow function.
2. using TerminateProcess(hProcess, 0), you need to find the process id (pid)

I find the other method better, if the application have many threads, for example when you exit the visual studio, its running many threads in background. Its hide the window but takes time to clear all the threads. you can see it from task manager.

// Shail [11/11/2002]
const CString ConfigPage::ProcessTerminate(int nApp, bool &bSuccess) const
{
CString msg;
DWORD pid = 0;
HANDLE hProcess;
CCSITimer oTimer;
bSuccess = true;

SetCursor(LoadCursor(NULL, IDC_WAIT));
pid = GetPIDfromAppName(m_strProcessApps[nApp]);
if (pid)
{
// open the process with all access
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

// bye-bye
if (hProcess)
{
TerminateProcess(hProcess, 0);
oTimer.Start();
while ( ( pid )
&& !oTimer.IsElapsed( PROCESS_TERMINATE_TIMEOUT ) )
{
Pump();
oTimer.Delay(500);
pid = GetPIDfromAppName(m_strProcessApps[nApp]);
}

if ( pid == 0 )
msg.Format("%s Terminated.", m_strApps[nApp]);
else
bSuccess = false;
}
}
return msg;
}

const CString ConfigPage::ProcessDistroy(int nApp, bool &bSuccess) const
{
CString msg;
CWnd * pWnd = NULL;
CCSITimer oTimer;

SetCursor(LoadCursor(NULL, IDC_WAIT));

if (m_strApps[nApp].IsEmpty())
return msg;
pWnd = FindWindow(NULL, m_strApps[nApp]);
if (pWnd )
{
pWnd->PostMessage(WM_CLOSE);

if ( C7StartupConfigPage::nDS == nApp )
{
msg.Format("Close %s Manually.", m_strApps[nApp]);
}
else
{
oTimer.Start();
while ( (NULL != pWnd)
&& !oTimer.IsElapsed( PROCESS_TERMINATE_TIMEOUT ) )
{
Pump();
oTimer.Delay(500);
pWnd = FindWindow(NULL, m_strApps[nApp]);
}

if ( NULL == pWnd )
msg.Format("%s Terminated.", m_strApps[nApp]);
else
bSuccess = false;
}

}
else
{
// Shail [11/11/2002]
// if app window doesn't exists, then just terminate the app. [ most prob. its a crashed app.]
ProcessTerminate(nApp, bSuccess);
}

return msg;
}


Shail Srivastav
shailsrivastav@hotmail.com
QuestionConnectionPoint Interface? Pin
ndalal21-Apr-04 3:42
ndalal21-Apr-04 3:42 
GeneralPorting Mac to Win, WaitMouseMoved Pin
Maarten Kools21-Apr-04 3:27
professionalMaarten Kools21-Apr-04 3:27 
GeneralRe: Porting Mac to Win, WaitMouseMoved Pin
Anonymous21-Apr-04 3:47
Anonymous21-Apr-04 3:47 
GeneralRe: Porting Mac to Win, WaitMouseMoved Pin
Maarten Kools21-Apr-04 4:58
professionalMaarten Kools21-Apr-04 4:58 
GeneralIf anyone from Microsoft is reading this (VC++ 7.1) Pin
Giles21-Apr-04 3:25
Giles21-Apr-04 3:25 
GeneralRe: If anyone from Microsoft is reading this (VC++ 7.1) Pin
David Crow21-Apr-04 5:18
David Crow21-Apr-04 5:18 
GeneralGetting the battery Status Pin
rallister21-Apr-04 3:19
rallister21-Apr-04 3:19 
GeneralRe: Getting the battery Status Pin
Anonymous21-Apr-04 3:45
Anonymous21-Apr-04 3:45 
GeneralListCtrl Scroll Messages Pin
Greg Ellis21-Apr-04 3:10
Greg Ellis21-Apr-04 3:10 
GeneralRe: ListCtrl Scroll Messages Pin
jmkhael21-Apr-04 3:13
jmkhael21-Apr-04 3:13 
GeneralRe: ListCtrl Scroll Messages Pin
Greg Ellis21-Apr-04 3:17
Greg Ellis21-Apr-04 3:17 
GeneralUpload file without file-selection field Pin
intelligent21-Apr-04 2:44
intelligent21-Apr-04 2:44 
GeneralIntellisense Pin
Roger H. Art21-Apr-04 2:42
sussRoger H. Art21-Apr-04 2:42 
GeneralRe: Intellisense Pin
David Crow21-Apr-04 2:47
David Crow21-Apr-04 2:47 
GeneralRe: Intellisense Pin
Roger H Art21-Apr-04 2:52
sussRoger H Art21-Apr-04 2:52 
GeneralReading code from file Pin
Ni@m21-Apr-04 2:01
Ni@m21-Apr-04 2:01 
GeneralRe: Reading code from file Pin
David Crow21-Apr-04 2:32
David Crow21-Apr-04 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.