Re: CFileDialog in Threads

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Use the handle you already obtained to get the handle of the parent.

The relationship is not qute what you might expect. Your CFileDialog 
derivative is actually a child of the dialog you see. Don't believe me? Use 
Spy to check out the hierarchy.

<akshay4friend@xxxxxxxxx> wrote in message 
news:1138794696.615421.270490@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Vipin,
> Thanx for your comments.. I was expecting comment about subclassing
> BUT....
> Above is just sample code...In my original code I am having third party
> ActiveX control which is having method to invoke modal
> CFileDialog.....So I just want to get handle of this file dialog for
> further manipulation.. So I want to put that in thread......Can you
> please tell me how  to get that work with given code ?
>
> Thanx
> Akshay
>
> Vipin [MVP] wrote:
>> 1) subclass CFileDialog and create a class called CMyFileDialog
>> 2) provide a OnInitDialog handler.
>> In that you can use the GetSafeHwnd(...) to get the window handle.
>>
>> No use like this
>> CMyFileDialog dlg;
>> dlg.DoModal();
>>
>> --
>> Vipin Aravind
>> <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

  • CFileDialog in Threads
    ... I need to get handle of modal file dialog box. ... CFileDialog in thread. ... UINT Thread1(LPVOID pParam) ...
    (microsoft.public.vc.mfc)
  • Re: CFileDialog in Threads
    ... subclass CFileDialog and create a class called CMyFileDialog ... In that you can use the GetSafeHwndto get the window handle. ... > UINT Thread1(LPVOID pParam) ...
    (microsoft.public.vc.mfc)