Synchronization Issue.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
HI
I have a executable to creates a thread.
In this thread I create a process, which is another executable, using the following code.

<div style="color:Black;background-color:White; <pre>
SECURITY_ATTRIBUTES sa;
sa.nLength = <span style="color:Blue; sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = FALSE;
CreateMyDACL(&sa);

CreateProcess(szPath.c_str()
, (_TCHAR*)Parameters.c_str()
, &sa
, &sa
, <span style="color:Blue; false
, CREATE_DEFAULT_ERROR_MODE
, NULL
, NULL
, &siStartupInfo
, &piProcessInfo)
[/code]

Now after this process is created it pops up a dialog with a yes and no button.
I use the following code to simulate a pause until this dialog appears. However this does not seem to wait properly. Can anyone give me any suggestions to make this work.

<div style="color:Black;background-color:White; <pre>
string m_szWindowName = TEXT(<span style="color:#A31515; "Dialog Window");<br/>HWND m_hWnd = NULL;<br/><br/><span style="color:Blue; bool CEnumerateWindows::MyFunc()
{
<span style="color:Blue; int iCounter = 0;
bRc = <span style="color:Blue; false;
<span style="color:Blue; while ((bRc == <span style="color:Blue; false) && (iCounter <= 480))
{
<span style="color:Green; //iterate all windows, if found simulate a user click
::EnumWindows(EnumWindowsProc,(LPARAM)<span style="color:Blue; this);
<span style="color:Blue; if (<span style="color:Blue; this->m_hWnd != NULL)
{
<span style="color:Blue; long style =GetWindowLong(<span style="color:Blue; this->m_hWnd, GWL_STYLE);
<span style="color:Blue; if ((style & WS_VISIBLE) != 0)
{
bRc = <span style="color:Blue; true;
}
}
Sleep(500);
iCounter++;
}
<span style="color:Blue; return bRc;
}


BOOL CALLBACK CEnumerateWindows::EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
<span style="color:Blue; char szBuffer[256] = {0};
CEnumerateWindows *pEW = <span style="color:Blue; reinterpret_cast<CEnumerateWindows*>(lParam);
BOOL bTextFound = FALSE;
<span style="color:Blue; char szOut[ 256 ] = { 0 };
<span style="color:Blue; if( !lParam )
{
<span style="color:Blue; return TRUE;
}
<span style="color:Blue; if( GetWindowText( hWnd, szBuffer, <span style="color:Blue; sizeof( szBuffer ) ) )
{
<span style="color:Blue; if( *szBuffer != )
{
<span style="color:Green; //test window text against our variable
<span style="color:Blue; if (!_tcscmp (szBuffer,pEW->m_szWindowName.c_str()))
{<br/> pEW->m_hWnd = hWnd;<br/>  <span style="color:Blue; return FALSE;
}
}
}
<span style="color:Blue; return TRUE;
}
[/code]
<br/>
<br/>


View the full article
 
Back
Top