Board index » cppbuilder » Using a window handle

Using a window handle


2006-05-10 09:05:41 PM
cppbuilder86
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
www.mjfreelancing.com
Associate Editor
C++Builder Developers Journal
www.bcbjournal.com
 
 

Re:Using a window handle

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
Quote
I cannot work out how to make use of the hwnd parameter correctly.
According to the documentation:
IEmptyVolumeCache::ShowProperties Method
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?
Quote
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.
Quote
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

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
www.mjfreelancing.com
Associate Editor
C++Builder Developers Journal
www.bcbjournal.com
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

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

According to the documentation:

IEmptyVolumeCache::ShowProperties Method

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


 

{smallsort}

Re:Using a window handle

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
Quote
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.
Quote
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

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
www.mjfreelancing.com
Associate Editor
C++Builder Developers Journal
www.bcbjournal.com
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.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

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
www.mjfreelancing.com
Associate Editor
C++Builder Developers Journal
www.bcbjournal.com
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.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

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
Quote
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

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
Quote
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.
Quote
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

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
www.mjfreelancing.com
Associate Editor
C++Builder Developers Journal
www.bcbjournal.com
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Malcolm Smith" < XXXX@XXXXX.COM >wrote in message
news:44631fb8$ XXXX@XXXXX.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