🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
9 messages
9 total messages Started by Malcolm Smith Wed, 10 May 2006 13:05
Using a window handle
#3637
Author: Malcolm Smith
Date: Wed, 10 May 2006 13:05
28 lines
1703 bytes
I have a COM DLL implementing the IEmptyVolumeCache interface.  One of the 
functions is :

  virtual HRESULT STDMETHODCALLTYPE ShowProperties(
      HWND hwnd);

This function is used to show a form that displays all files about to be 
purged.

I cannot work out how to make use of the hwnd parameter correctly.

For example, if a user minimizes my form (which is currently modal) I'm not 
sure how to make the calling (microsoft) window also minimize.  And, if a 
user restores either form to make sure they both restore.

Are there any other reasons for using the passed handle ?

Any tips ?

-- 
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com
 
Re: Using a window handle
#3641
Author: Remy Lebeau (TeamB)
Date: Wed, 10 May 2006 17:06
30 lines
1843 bytes
"Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
news:4461e528@newsgroups.borland.com...

> I cannot work out how to make use of the hwnd parameter correctly.

According to the documentation:

    IEmptyVolumeCache::ShowProperties Method

http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/ifaces/iemptyvolumecache/showproperties.asp

    hwnd
    [in] Parent window to be used when displaying the UI.


Did you try passing in the Handle of your form as the parent window?

> For example, if a user minimizes my form (which is currently modal) I'm
> not sure how to make the calling (microsoft) window also minimize.

It should minimize automatically if the window that ShowProperties()
displays is a child of your form's window.

> And, if a user restores either form to make sure they both restore.

Child windows are automatically shown when their parent window is shown.


Gambit
Re: Using a window handle
#3643
Author: Malcolm Smith
Date: Wed, 10 May 2006 21:19
65 lines
3032 bytes
Remy,

The HWND is coming into my DLL from the Cleanup Manager, not going out.

HRESULT STDMETHODCALLTYPE TDevCleanCtrlImpl::ShowProperties(HWND hwnd)
{
// we are caching the form in case the user shows it more than once
if( !frmFileDetails )
  frmFileDetails = new TfrmFileDetails( NULL, FVolume, FFileSearch, 
FFileStates );

if( frmFileDetails )
  frmFileDetails->ShowModal();

return S_OK;
}

So how do I use the HWND in my form to tell it that the Cleanup Manager is 
the parent form ?

I tried setting Application->Handle but that didn't make any difference.

-- 
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:44621e0c$1@newsgroups.borland.com...
>
> "Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
> news:4461e528@newsgroups.borland.com...
>
>> I cannot work out how to make use of the hwnd parameter correctly.
>
> According to the documentation:
>
>    IEmptyVolumeCache::ShowProperties Method
>
> http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/ifaces/iemptyvolumecache/showproperties.asp
>
>    hwnd
>    [in] Parent window to be used when displaying the UI.
>
>
> Did you try passing in the Handle of your form as the parent window?
>
>> For example, if a user minimizes my form (which is currently modal) I'm
>> not sure how to make the calling (microsoft) window also minimize.
>
> It should minimize automatically if the window that ShowProperties()
> displays is a child of your form's window.
>
>> And, if a user restores either form to make sure they both restore.
>
> Child windows are automatically shown when their parent window is shown.
>
>
> Gambit
>
> 
Re: Using a window handle
#3644
Author: Remy Lebeau (TeamB)
Date: Wed, 10 May 2006 21:50
46 lines
2160 bytes
"Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
news:446259de@newsgroups.borland.com...

> The HWND is coming into my DLL from the Cleanup Manager, not going out.

Exactly.  You have to use the HWND that is passed into ShowProperties() as
the parent window for any windows that ShowProperties() displays.

> we are caching the form in case the user shows it more than once

You need to change the form's ParentWindow property, ie:

    HRESULT STDMETHODCALLTYPE TDevCleanCtrlImpl::ShowProperties(HWND hwnd)
    {
        try
        {
            if( !frmFileDetails )
                frmFileDetails = new TfrmFileDetails( NULL, FVolume,
FFileSearch, FFileStates );
        }
        catch(const Exception &)
        {
            return E_OUTOFMEMORY;
        }

        try
        {
            frmFileDetails->ParentWindow = hwnd;
            try {
                frmFileDetails->ShowModal();
            }
            __finally {
                frmFileDetails->ParentWindow = NULL;
            }
        }
        catch(const Exception &)
        {
            return E_UNEXPECTED;
        }

        return S_OK;
    }


Gambit
Re: Using a window handle
#3649
Author: Malcolm Smith
Date: Thu, 11 May 2006 11:13
66 lines
2784 bytes
Oh, thanks.  I didn't even realize their was a ParentWindow property.

I've noted the additional exception handling as well.  I had a TODO on that 
(to look up common E_ return values).

Thanks again.
-- 
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:446260ad$1@newsgroups.borland.com...
>
> "Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
> news:446259de@newsgroups.borland.com...
>
>> The HWND is coming into my DLL from the Cleanup Manager, not going out.
>
> Exactly.  You have to use the HWND that is passed into ShowProperties() as
> the parent window for any windows that ShowProperties() displays.
>
>> we are caching the form in case the user shows it more than once
>
> You need to change the form's ParentWindow property, ie:
>
>    HRESULT STDMETHODCALLTYPE TDevCleanCtrlImpl::ShowProperties(HWND hwnd)
>    {
>        try
>        {
>            if( !frmFileDetails )
>                frmFileDetails = new TfrmFileDetails( NULL, FVolume,
> FFileSearch, FFileStates );
>        }
>        catch(const Exception &)
>        {
>            return E_OUTOFMEMORY;
>        }
>
>        try
>        {
>            frmFileDetails->ParentWindow = hwnd;
>            try {
>                frmFileDetails->ShowModal();
>            }
>            __finally {
>                frmFileDetails->ParentWindow = NULL;
>            }
>        }
>        catch(const Exception &)
>        {
>            return E_UNEXPECTED;
>        }
>
>        return S_OK;
>    }
>
>
> Gambit
>
> 
Re: Using a window handle
#3650
Author: Malcolm Smith
Date: Thu, 11 May 2006 11:27
69 lines
2961 bytes
Remy,

It turned out to be incorrect behaviour - my form become embedded in the 
cleanup manager (as described in the help file).

Is there any way I can make the cleanup manager auto minimize/restore if a 
user minimizes my form ?

If not, I'll just have to remove the minimize button and be done with it.

-- 
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:446260ad$1@newsgroups.borland.com...
>
> "Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
> news:446259de@newsgroups.borland.com...
>
>> The HWND is coming into my DLL from the Cleanup Manager, not going out.
>
> Exactly.  You have to use the HWND that is passed into ShowProperties() as
> the parent window for any windows that ShowProperties() displays.
>
>> we are caching the form in case the user shows it more than once
>
> You need to change the form's ParentWindow property, ie:
>
>    HRESULT STDMETHODCALLTYPE TDevCleanCtrlImpl::ShowProperties(HWND hwnd)
>    {
>        try
>        {
>            if( !frmFileDetails )
>                frmFileDetails = new TfrmFileDetails( NULL, FVolume,
> FFileSearch, FFileStates );
>        }
>        catch(const Exception &)
>        {
>            return E_OUTOFMEMORY;
>        }
>
>        try
>        {
>            frmFileDetails->ParentWindow = hwnd;
>            try {
>                frmFileDetails->ShowModal();
>            }
>            __finally {
>                frmFileDetails->ParentWindow = NULL;
>            }
>        }
>        catch(const Exception &)
>        {
>            return E_UNEXPECTED;
>        }
>
>        return S_OK;
>    }
>
>
> Gambit
>
> 
Re: Using a window handle
#3651
Author: Remy Lebeau (TeamB)
Date: Thu, 11 May 2006 16:39
10 lines
1256 bytes
"Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
news:44631c4f$1@newsgroups.borland.com...

> Oh, thanks.  I didn't even realize their was a ParentWindow property.

It is listed in the VCL documentation ;-)


Gambit
Re: Using a window handle
#3652
Author: Remy Lebeau (TeamB)
Date: Thu, 11 May 2006 16:47
30 lines
2426 bytes
"Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
news:44631fb8$1@newsgroups.borland.com...

> It turned out to be incorrect behaviour - my form become embedded
> in the cleanup manager (as described in the help file).

That is what it is supposed to do.  A window can't have a parent window and
still be its own top-level window.  If you need your dialog window to remain
its own popup window, then you have to use a NULL parent window.  But then
your popup window won't have any ties to the Cleanup Manager's window.

> Is there any way I can make the cleanup manager auto
> minimize/restore if a user minimizes my form ?

If your DLL is passed in an HWND parent window, you need to use it as a
parent window.  That is the contract that the DLL needs to follow, since
that is the way the interface is spec'ed out to operate.

With that said, one thing you can consider doing is to have ShowProperties()
call EnumWindows() and GetWindowThreadProcessId() to build up a list of all
the HWND handles that belong to the calling process.  When your popup form
is minimized/restored, you can run through the list minimizing/restoring
those windows as needed.  In order to detect when the user
minimizes/restores those windows directly, you would have to subclass them
via SetWindowLong(GWL_WNDPROC) to catch all messages that are issued to
them.


Gambit
Re: Using a window handle
#3653
Author: Malcolm Smith
Date: Thu, 11 May 2006 20:09
54 lines
3088 bytes
Yes, Remy.  I understand.

It's a strange contract since the Cleanup Manager window is quite small.

Thanks for your input.

-- 
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:44636b16@newsgroups.borland.com...
>
> "Malcolm Smith" <mjfreelancing@optusnet.com.au> wrote in message
> news:44631fb8$1@newsgroups.borland.com...
>
>> It turned out to be incorrect behaviour - my form become embedded
>> in the cleanup manager (as described in the help file).
>
> That is what it is supposed to do.  A window can't have a parent window 
> and
> still be its own top-level window.  If you need your dialog window to 
> remain
> its own popup window, then you have to use a NULL parent window.  But then
> your popup window won't have any ties to the Cleanup Manager's window.
>
>> Is there any way I can make the cleanup manager auto
>> minimize/restore if a user minimizes my form ?
>
> If your DLL is passed in an HWND parent window, you need to use it as a
> parent window.  That is the contract that the DLL needs to follow, since
> that is the way the interface is spec'ed out to operate.
>
> With that said, one thing you can consider doing is to have 
> ShowProperties()
> call EnumWindows() and GetWindowThreadProcessId() to build up a list of 
> all
> the HWND handles that belong to the calling process.  When your popup form
> is minimized/restored, you can run through the list minimizing/restoring
> those windows as needed.  In order to detect when the user
> minimizes/restores those windows directly, you would have to subclass them
> via SetWindowLong(GWL_WNDPROC) to catch all messages that are issued to
> them.
>
>
> Gambit
>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads