Start a process and obtain its main window handle

Source: Internet
Author: User

The following two functions can be used to start a process and obtain the main window handle.

Bool callback cdsupdate: enumdsumwindowsproc (hwnd, lparam)

{

DWORD dwid;

Enumparam * Pep = (enumparam *) lparam;

Getwindowthreadprocessid (hwnd, & dwid );

If (dwid = pep-> m_dwprocessid)

{

Pep-> m_hmainwnd = hwnd;

Return false;

}

Return true;

}

Hwnd cdsupdate: rundsum (cstring sdsumfile)

{

Enumparam EP;

Startupinfo Si;

Process_information PI;

Cstring sfolder;

Zeromemory (& Si, sizeof (startupinfo ));

Si. cb = sizeof (startupinfo );

Si. wshowwindow = sw_show;

Zeromemory (& Pi, sizeof (process_information ));

Updatelog (: Message, l "(rundsum): Start dsum .");

If (! CreateProcess (null, (lptstr) (lpctstr) sdsumfile, null, null, false, 0, null, sdsumfile. left (sdsumfile. reversefind ('//'), & Si, & PI ))

{

Updatelog (: error, l "(rundsum): Start dsum fail (% d).", getlasterror ());

Return NULL;

}

// Close process and thread handles.

Closehandle (PI. hprocess );

Closehandle (PI. hthread );

 

Ep. m_dwprocessid = pi. dwprocessid;

Ep. m_hmainwnd = NULL;

For (INT I = 0; I <50; I ++) // retry about 10 s.

{

Sleep (200 );

Enumwindows (enumdsumwindowsproc, (lparam) & EP );

If (Ep. m_hmainwnd)

Break;

}

If (! Ep. m_hmainwnd)

{

Updatelog (: error, l "(rundsum): couldn't find the hwnd of dsum .");

Return NULL;

}

Return ep. m_hmainwnd;

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.