Repost: How to regain focus when an HtmlHelp window is closed?

G

Guest

Hopefully my subscription issues are now resolved. Here is my previous
posting:

I am developing a Windows Forms application using Visual Studio 2003 and C#.
The application uses the MDI style.

The main application provides context sensitive help upon user request The
help information is displayed in a help viewer window ( HHCtrl.ocx,
HtmlHelp() ). The help viewer shows up as a separate application in the task
manager, but it is associated with the same process as the main application.

We have found that if the user closes the help viewer window, focus does not
always return to the main application window. Is there a way for the main
application to detect when the help viewer is closed and give itself focus?

We launch the HtmlViewer as follows:

public class HelpControlBase
{
protected const int HH_HELP_CONTEXT = 0x000F;

[DllImport( "HHCtrl.ocx" )]
public extern static int HtmlHelp( int hwnd, string pszFile, int cmd, int
data );

virtual protected int DisplayHelp( int helpID, string fileName )
{
int results = HelpControlBase.HtmlHelp( 0, fileName, HH_HELP_CONTEXT,
helpID );
return results;
}
}

Thanks,
Dave
 
L

Linda Liu [MSFT]

Hi Dave,

Thank you for posting.

This is a quick note to let you know that I am performing research on this
issue and will get back to you as soon as possible. I appreciate your
patience.



Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
L

Linda Liu [MSFT]

Hi Dave,

Thank you for posting. From your post, my understanding on this issue is:
how to regain focus to the main Windows Form after an HtmlHelp Window is
closed. If I'm off base, please feel free to let me know.

HTML Help API syntax is: HWND HtmlHelp(
HWND hwndCaller,
LPCSTR pszFile,
UINT uCommand,
DWORD dwData) ;
hwndCaller Specifies the handle (hwnd) of the window calling HtmlHelp().
The help window is owned by this window. When the help window is closed,
HtmlHelp() will return focus to the owner unless the owner is the desktop.
If hwndCaller is the desktop, then the operating system determines where
focus is returned.

The following is a sample.
public class HelpControlBase
{
protected const int HH_HELP_CONTEXT = 0x000F;

[DllImport( "HHCtrl.ocx" )]
public extern static int HtmlHelp( IntPtr hwnd, string pszFile, int cmd,
int data );

virtual public int DisplayHelp( IntPtr hwnd, int helpID, string fileName
)
{
int results = HelpControlBase.HtmlHelp( hwnd, fileName,
HH_HELP_CONTEXT, helpID);
return results;
}
}
// this is a button click event handling method defined in the Main
Windows Form
private void button1_Click(object sender, System.EventArgs e)
{
HelpControlBase helpbase = new HelpControlBase();
helpbase.DisplayHelp(this.Handle,0,@"C:\xdict.chm");
}

When the help form is closed, the focus will return to the Main Windows
Form.

Hope this is helpful to you.
If you have any other concerns, or need anything else, please don¡¯t
hesitate to let me know.



Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
G

Guest

Linda,

I now pass in the IntPtr hwnd Handle of the main form (the MDI Parent) of
the application as described in your reply. Focus still does not return to
the application. I am not sure where focus is going. However, if I press
the windows key on a standard keyboard the Start menu opens.

Anyway, what I need to happen is that focus is returned to my application's
main form. This is still not occurring.

When I launch the help viewer using the code below, I note that the results
value being returned is non-zero, being a value of 2495970 (0x2615e2). What
does this value indicate? Where can I find what values to expect and their
meaning?

int results = HelpControlBase.HtmlHelp( hwnd, file, HH_HELP_CONTEXT, helpID );

In summary:
I still need a solution for returning focus to the main application form.
Is the non-zero return value an indication of a problem?

Awaiting your reply,
Dave

--
Dave Leach
Agilent Technologies, Inc.


Linda Liu said:
Hi Dave,

Thank you for posting. From your post, my understanding on this issue is:
how to regain focus to the main Windows Form after an HtmlHelp Window is
closed. If I'm off base, please feel free to let me know.

HTML Help API syntax is: HWND HtmlHelp(
HWND hwndCaller,
LPCSTR pszFile,
UINT uCommand,
DWORD dwData) ;
hwndCaller Specifies the handle (hwnd) of the window calling HtmlHelp().
The help window is owned by this window. When the help window is closed,
HtmlHelp() will return focus to the owner unless the owner is the desktop.
If hwndCaller is the desktop, then the operating system determines where
focus is returned.

The following is a sample.
public class HelpControlBase
{
protected const int HH_HELP_CONTEXT = 0x000F;

[DllImport( "HHCtrl.ocx" )]
public extern static int HtmlHelp( IntPtr hwnd, string pszFile, int cmd,
int data );

virtual public int DisplayHelp( IntPtr hwnd, int helpID, string fileName
)
{
int results = HelpControlBase.HtmlHelp( hwnd, fileName,
HH_HELP_CONTEXT, helpID);
return results;
}
}
// this is a button click event handling method defined in the Main
Windows Form
private void button1_Click(object sender, System.EventArgs e)
{
HelpControlBase helpbase = new HelpControlBase();
helpbase.DisplayHelp(this.Handle,0,@"C:\xdict.chm");
}

When the help form is closed, the focus will return to the Main Windows
Form.

Hope this is helpful to you.
If you have any other concerns, or need anything else, please don¡¯t
hesitate to let me know.



Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
L

Linda Liu [MSFT]

Hi Dave,

Thank you for your reply.

The return value of HtmlHelp function indicates the handle (hwnd) of the
help window created. If the return value is zero, it indicates that the
help window has not yet been created. The fact that you got a non-zero
result value means that help file has been created properly.

If you pass the main form handle to the HtmlHelp function , the focus
should be returned to the main form when the help form is closed. I think
the problem may be relative to your actual code in your project. If your
project is not complex, you can send it to me to have a look. If the
project is too large to send by email, you may create a simple winform
project and copy your related code into it, so that the new project can
also reproduce the problem.

To get my actual email, please remove the "online" from my displayed email.
Thanks.


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
G

Guest

Linda,

I have sent to you an email with two files to aid in replicating the
problem. The first file is a zipped VS 2003 solution. The second is a help
file (CHM).

Thanks,
Dave
 
L

Linda Liu [MSFT]

Hi Dave,

Thank you for your reply.
I have received your project and help file. After runing your program, I
found the problem existed. The main form can't regain focus after the
help window is closed. But after I modify the filename in your program to
open another help file on my machine , the main form can regain focus when
the help window is closed.
It seems that the problem that the main form can't regain focus may be
caused by the help file "map_ID_test_chm.chm".

I noticed that help file "map_ID_test_chm" behaves a little different from
my help file in the below test.

Double-click my help file in Windows Explorer, and then close it. The focus
returns to the Windows Explorer(the title bar of the Windows Explorer is
activated). The same test on the help file "map_ID_test_chm" gives a
different result. After I close the help file "map_ID_test_chm", the focus
doesn't return to the Windows Explorer and I don't know where it goes.

Hope this is helpful to you.

Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
G

Guest

Linda,

I have confirmed that our CHM file does not return focus to the Windows
Explorer window as you describe, but the CHM files included with Windows XP
do. We will be looking into how we create the CHM files for our application
and try to identify what might be causing the different behavior between out
CHM file and those created for Microsoft applications.

Thanks for your assistance in identifying this behavior. Please consider
this posting closed. I will start a new post if we have more questions
related to the HtmlViewer.

Thanks,
Dave
 
L

Linda Liu [MSFT]

Hi Dave,

You're welcome! And good luck to you!


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top