Click here to Skip to main content
15,918,108 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: UI design question ( presenting preferences ) Pin
Ravi Bhavnani11-Jun-04 12:54
professionalRavi Bhavnani11-Jun-04 12:54 
GeneralRe: UI design question ( presenting preferences ) Pin
Henry miller14-Jun-04 3:10
Henry miller14-Jun-04 3:10 
Questionhow to enable the "ok" button after 8 second in MFC Dialog box Pin
shiva shankar11-Jun-04 8:38
shiva shankar11-Jun-04 8:38 
AnswerRe: how to enable the "ok" button after 8 second in MFC Dialog box Pin
Ravi Bhavnani11-Jun-04 8:49
professionalRavi Bhavnani11-Jun-04 8:49 
AnswerRe: how to enable the "ok" button after 8 second in MFC Dialog box Pin
toxcct13-Jun-04 3:23
toxcct13-Jun-04 3:23 
Generalimage sequence in a window Pin
nyquisttt11-Jun-04 8:13
nyquisttt11-Jun-04 8:13 
GeneralRe: image sequence in a window Pin
David Crow11-Jun-04 9:40
David Crow11-Jun-04 9:40 
QuestionFindWindow is hanging.... help? Pin
Wes Jones11-Jun-04 6:55
Wes Jones11-Jun-04 6:55 
Hi all,

I have an app that uses FindWindow to find the window handle to another app's window, and it looks like it is hanging. It doesn't do it every time, but from my logging statements, I can tell that FindWindow is the last thing called when it's hung up.

I've seen the various articles/comments about the dangers of using FindWindow, ie: uses SendMessage internally & can hang if another app's thread is waiting/hung, etc.

I have written an alternative function for some other purpose that works similarly to FindWindow but checking all the top level windows, starting w/ the desktop window, but that too uses GetWindowText (ie: SendMessage()) & I think will have the same liability.

My question is: What's a good alternative to using FindWindow ?

I would alter my similar function to use SendMessageTimeout, but I am using Windows CE, and that function is not supported.

Please help, won't you?

What are the alternatives to using FindWindow?

here are some details about how I'm using FindWindow
LPCTSTR szPossibleNames[] = 
{  _T("name1"), _T("name2"),...,_T("nameN") };

for(int i=0; i < X; ++i)
{
    if( FindWindow(NULL, szPossibleNames[i]) )
      break;
}
//other stuff...


Is using FindWindow in a loop like this just asking for trouble? It's like I'm making it do risky things over & over again....


Just for fun, and in the case it can help somebody point out an alternative to me, here's the code for my 'alternative func':

HWND FindChildAmongManyChildDialogs(HWND hWndMain, 
                  LPCTSTR szClassName, 
                  LPCTSTR szWindowTitle)
//
//This function was written to 
//find a child window when there is a main 
//window, and then several dialogs that 
//are children, and the window we want 
//is on one of those dialogs.
//
//This is based on the AirCard 555 watcher program,
//and Spy++
//
//
//
{
	CString str, strTitle;
	TCHAR szClass[ 200 + 1 ] = {0};

	CWnd * pChild = CWnd::FromHandle(::GetWindow(hWndMain, GW_CHILD) );
	CWnd * pLast = NULL;
	if( pChild ) 
		pLast = pChild->GetWindow(GW_HWNDLAST);

	if( !pChild )
		return NULL;
	do{
		
		GetClassName(pChild->GetSafeHwnd(), szClass, 200);	
		pChild->GetWindowText(strTitle);

		if(_tcsicmp(szClass, _T("Dialog")) == 0 )
		{
			
			HWND hChild = FindChildWindow(pChild, szClassName, szWindowTitle);
			if( hChild ) 
				return hChild;
		}
		pChild = pChild->GetWindow(GW_HWNDNEXT);

	}while( pChild && (pChild != pLast) );
	
	return NULL;
}

HWND FindChildWindow(CWnd * pParent, LPCTSTR szClassName, LPCTSTR szWindowTitle)
{
	ASSERT( szClassName || szWindowTitle );
	ASSERT( pParent );
	
	CString strTitle;
	TCHAR szClass[ 200 + 1] = {NULL};

	CWnd * pChild = pParent->GetWindow(GW_CHILD);
	ASSERT( pChild );
	CWnd * pLast = NULL;
	if( pChild )
		pLast = pChild->GetWindow(GW_HWNDLAST);

	if( !pChild )
		return NULL;

	do
	{
		GetClassName(pChild->GetSafeHwnd(), szClass, 200);
		pChild->GetWindowText(strTitle);

		if( (!szClassName || _tcsicmp(szClass, szClassName) == 0) 
		&&  (!szWindowTitle || strTitle.CompareNoCase(szWindowTitle) == 0) )
		{
			return pChild->GetSafeHwnd();
		}
			
		pChild = pChild->GetWindow(GW_HWNDNEXT);

	}while( pChild && (pChild != pLast) );

	return NULL;
}



Last question:
Is using FindWindow(_T("dialog"), <window title="">)
better than using FindWindow(_T("dialog"), <window title="">) ?
Does specifying the class name prevent it from using the sendmessage call internally for those cases where the window is obviously not a dialog?



Thanks! Any help would be swell.
Wes
AnswerRe: FindWindow is hanging.... help? Pin
David Crow11-Jun-04 7:24
David Crow11-Jun-04 7:24 
GeneralRe: FindWindow is hanging.... help? Pin
Wes Jones11-Jun-04 7:52
Wes Jones11-Jun-04 7:52 
AnswerRe: FindWindow is hanging.... help? Pin
Navin11-Jun-04 7:48
Navin11-Jun-04 7:48 
GeneralRe: FindWindow is hanging.... help? Pin
Wes Jones11-Jun-04 8:00
Wes Jones11-Jun-04 8:00 
GeneralRe: FindWindow is hanging.... help? Pin
Navin11-Jun-04 8:04
Navin11-Jun-04 8:04 
AnswerRe: FindWindow is hanging.... help? Pin
Neville Franks11-Jun-04 11:40
Neville Franks11-Jun-04 11:40 
GeneralRe: FindWindow is hanging.... help? Pin
Wes Jones11-Jun-04 14:17
Wes Jones11-Jun-04 14:17 
GeneralRe: FindWindow is hanging.... help? Pin
Neville Franks11-Jun-04 15:17
Neville Franks11-Jun-04 15:17 
GeneralMicrosoft !!! Q's Pin
suiram4011-Jun-04 6:49
suiram4011-Jun-04 6:49 
GeneralRe: Microsoft !!! Q's Pin
Maximilien11-Jun-04 6:55
Maximilien11-Jun-04 6:55 
GeneralRe: Microsoft !!! Q's Pin
David Crow11-Jun-04 7:28
David Crow11-Jun-04 7:28 
GeneralRe: Microsoft !!! Q's Pin
Maximilien11-Jun-04 7:29
Maximilien11-Jun-04 7:29 
GeneralRe: Microsoft !!! Q's Pin
suiram4011-Jun-04 7:39
suiram4011-Jun-04 7:39 
GeneralRe: Microsoft !!! Q's Pin
David Crow11-Jun-04 8:06
David Crow11-Jun-04 8:06 
GeneralRe: Microsoft !!! Q's Pin
Henry miller11-Jun-04 8:03
Henry miller11-Jun-04 8:03 
GeneralRe: Microsoft !!! Q's Pin
jj3pa11-Jun-04 14:21
jj3pa11-Jun-04 14:21 
GeneralRe: Microsoft !!! Q's Pin
toxcct13-Jun-04 3:28
toxcct13-Jun-04 3:28 

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.