Re: CFileDialog in Threads
- From: "Alexander Grigoriev" <alegr@xxxxxxxxxxxxx>
- Date: Wed, 1 Feb 2006 08:32:15 -0800
GetForegroundWindow returns top level (unowned) window. The file dialog is owned by previous dialog. And GetForegroundWindow is most likely wrong approach to your problem. What you want to do, anyway? GFW might return a window from different process. <akshay4friend@xxxxxxxxx> wrote in message news:1138790055.413553.259400@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx >I need to get handle of modal file dialog box. for that I am putting > CFileDialog in thread. I am creating 2 threads . In one thread i am > invoking CFileDialog and in another thread I am trying to get handle of > that dialog box using GetForegroundWindow().....but with code given > below I am not getting handle of file dialog box but getting my > CTestDlg dialog box handle..... > > > void CTestDlg::OnOK() > { > // TODO: Add extra validation here > CWinThread* pWThread1 = AfxBeginThread(Thread1, this); > > CWinThread* pWThread2 = AfxBeginThread(Thread2, this); > ....... > ....... > } > > UINT Thread1(LPVOID pParam) > { > static char szFilter[] = "COFF files (*.txt)|*.out|All Files > (*.*)|*.*||"; > CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | > OFN_OVERWRITEPROMPT, szFilter); > fileDlg.DoModal(); > return 1; > } > > UINT Thread2(LPVOID pParam) > { > ::SetWindowText(::GetForegroundWindow(),"Save Text File"); > return 1; > } > > **BUT... WHEN I CHANGE Thread2() FUNCTION LIKE BELOW I AM GETTING > HANDLE OF FILE DIALOG BOX AND ITS PROPERLY SETTING WINDOW TEXT...LIKE > THIS.. > > UINT Thread2(LPVOID pParam) > { > Sleep(100); > ::SetWindowText(::GetForegroundWindow(),"Save Text File"); > return 1; > } > > but I think using Sleep() is not perfect way for doing this...because > 100 factor for Sleep function is not fixed for every time...I am new to > thread programming. .. so I want to know which is other way to getting > handle of file dialog box... how can i know that my modal file dialog > box is become foreground window..... > > Thanx in Advance > Akshay > .
- Follow-Ups:
- Re: CFileDialog in Threads
- From: akshay4friend
- Re: CFileDialog in Threads
- References:
- CFileDialog in Threads
- From: akshay4friend
- CFileDialog in Threads
- Prev by Date: Re: Crash in CAfxStringMgr::Free
- Next by Date: MFC and c++ problems
- Previous by thread: Re: CFileDialog in Threads
- Next by thread: Re: CFileDialog in Threads
- Index(es):
Relevant Pages
|
Loading