Re: CFileDialog in Threads



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
> 


.



Relevant Pages

  • Re: CFileDialog in Threads
    ... I would abandon the whole design. ... assumes that the Thread1 has actually created the window, ... >UINT Thread1(LPVOID pParam) ...
    (microsoft.public.vc.mfc)
  • Re: CFileDialog in Threads
    ... file save dialog box window invoked by activex control method... ... GetForegroundWindow is wrong approach how should I get handle to File ... >> UINT Thread1(LPVOID pParam) ...
    (microsoft.public.vc.mfc)
  • Re: CFileDialog in Threads
    ... You can set a local hook for window creation and watch for "Dialog" class ... > GetForegroundWindow is wrong approach how should I get handle to File ... >>> UINT Thread1(LPVOID pParam) ...
    (microsoft.public.vc.mfc)
  • Re: PostMessage/PeekMessage and interop
    ... and trying to notify the main window when some unit of work is done. ... UInt32 Msg, // message ... public IntPtr handle; ... public uint time; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Control.FromHandle for Compact Framework
    ... They probably are doing this by reparenting their window to the window which ... uint style = GetWindowLong; ... private static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint ... private static extern IntPtr SetParent(IntPtr hWndChild, ...
    (microsoft.public.dotnet.framework.compactframework)

Loading