Change owner of Help window

  • Thread starter Thread starter RvGrah
  • Start date Start date
R

RvGrah

I built a help system using Html Help Workshop (very unintuitive!).

Got it hooking up with my C# application OK. But I have one issue:

The application allows multiple child windows to be open, usually non-
modally. If the help window is launched from one window, and then the
user gives focus to another window and presses F1 again, the topic in
Help changes as it ought to, but whatever window opened it first comes
back to front as well (if it was still open in the background). I
assume this is because the first window to open Help still "owns" the
help window.

Is there a way to catch the F1 keystroke and take ownership of the
help window for the latest open form when the user presses F1?

Thanks, Bob Graham
 
I built a help system using Html Help Workshop (very unintuitive!).

Got it hooking up with my C# application OK. But I have one issue:

The application allows multiple child windows to be open, usually non-
modally. If the help window is launched from one window, and then the
user gives focus to another window and presses F1 again, the topic in
Help changes as it ought to, but whatever window opened it first comes
back to front as well (if it was still open in the background). I
assume this is because the first window to open Help still "owns" the
help window.

Is there a way to catch the F1 keystroke and take ownership of the
help window for the latest open form when the user presses F1?

I don't know how you're handling F1 now, but I'm sure there's a way to
detect when the key is pressed in your program.

As for changing the window parent, the Win32 function SetParent() will do
that. I mention the Win32 function, because the Help window is not a
managed window, AFAIK. So I think you'll have to use the unmanaged Win32
API to change the parent (see p/invoke interop).

Pete
 
I don't know how you're handling F1 now, but I'm sure there's a way to  
detect when the key is pressed in your program.

As for changing the window parent, the Win32 function SetParent() will do 
that.  I mention the Win32 function, because the Help window is not a  
managed window, AFAIK.  So I think you'll have to use the unmanaged Win32  
API to change the parent (see p/invoke interop).

Pete

I'm using the HelpProvider component from the standard toolbox and
setting Show help on HelpProvider1 to true. That makes it respond to
the F1 key with no further code writing as long as you set the
HelpProvider's properties and the HelpNavigator and HelpKeyword
properly on whatever form or control you're using.

I understand your answer, and can figure it out from there except for
one part... How do I attach to the help window's handle? Do I have to
iterate through the other windows that the os is handling to find it?
What if there are several help windows open from different programs?
Is there a way to know I'm getting the right one?

Thanks Peter, Bob Graham
 
[...]
I understand your answer, and can figure it out from there except for
one part... How do I attach to the help window's handle? Do I have to
iterate through the other windows that the os is handling to find it?
What if there are several help windows open from different programs?
Is there a way to know I'm getting the right one?

My understanding is that you already know the current parent of the help
window (or at least you can get and maintain that information trivially).
So my suggestion would be to enumerate the children of that parent, rather
than examining every open window on the system.

Pete
 
[...]
I understand your answer, and can figure it out from there except for
one part... How do I attach to the help window's handle? Do I have to
iterate through the other windows that the os is handling to find it?
What if there are several help windows open from different programs?
Is there a way to know I'm getting the right one?

My understanding is that you already know the current parent of the help  
window (or at least you can get and maintain that information trivially). 
So my suggestion would be to enumerate the children of that parent, rather  
than examining every open window on the system.

Pete

Hmm. I know the parent, but iterating through "this.OwnedForms" shows
0 as count, after launching help, so I'm a bit in the dark without a
better understanding of the win32 api it seems.
 
[...]
My understanding is that you already know the current parent of the
help  
window (or at least you can get and maintain that information
trivially).  
So my suggestion would be to enumerate the children of that parent,
rather  
than examining every open window on the system.

Hmm. I know the parent, but iterating through "this.OwnedForms" shows
0 as count, after launching help, so I'm a bit in the dark without a
better understanding of the win32 api it seems.

Since the help window isn't a managed form, I wouldn't be surprised at all
for it to not show up in the OwnedForms collection. You probably need to
use the unmanaged API for the enumeration as well; see the
EnumChildWindows() function.
http://pinvoke.net/default.aspx/user32/EnumChildWindows.html

If you know C++, you may find it simpler to write a helper class using
C++/CLI that handles the main grunt-work, so that you don't have to mess
around with all the p/invoke declarations (which aren't that hard,
especially if you consult the pinvoke.net web site, but do involve some
tedium).

Pete
 
Back
Top