Click here to Skip to main content
15,914,608 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF Browser Application With Ajax Pin
Abhijit Jana18-Apr-08 21:29
professionalAbhijit Jana18-Apr-08 21:29 
AnswerRe: WPF Browser Application With Ajax Pin
charlymoon23-Apr-08 12:21
charlymoon23-Apr-08 12:21 
QuestionWebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
OscarOrtega18-Apr-08 6:28
OscarOrtega18-Apr-08 6:28 
GeneralRe: WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
RNEELY21-Apr-08 17:24
RNEELY21-Apr-08 17:24 
GeneralRe: WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
OscarOrtega22-Apr-08 23:07
OscarOrtega22-Apr-08 23:07 
GeneralRe: WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
OscarOrtega23-Apr-08 0:14
OscarOrtega23-Apr-08 0:14 
GeneralRe: WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
RNEELY23-Apr-08 3:35
RNEELY23-Apr-08 3:35 
GeneralRe: WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
OscarOrtega22-Apr-08 23:01
OscarOrtega22-Apr-08 23:01 
Hello again,

I've reproduced the problem in a small program. First, I've built a WPF Control Library with a WebBrowser embedded. Then, I've built a simple MFC application that calls this control. The result is the same: Whenever I press the TAB key inside the WebBrowser the application hangs and stops responding.

Next, I'm posting the code of this simple project. Please, could someone give me any clue about could be happening?

The WPF control library contains the following code:

In the XAML file:
<code>
<UserControl x:Class="WpfControlLibrary1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wfh="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Loaded="UserControl_Loaded"
Height="300" Width="300">
<Grid>
<wfh:WindowsFormsHost x:Name="myFormHost">
<wf:WebBrowser x:Name="webBrowser1" x:FieldModifier="public" />
<wfh:WindowsFormsHost>
<!-- Uncomment for WPF frame test
<Frame Name="myFrame" Source="http://www.google.es" LoadCompleted="Frame_LoadCompleted" />
-->
<Grid>
</UserControl>
</code>

Then in the .cs file:
<code>
namespace WpfControlLibrary1
{
/// &lt;summary&gt;
/// Interaction logic for UserControl1.xaml
/// &lt;/summary&gt;
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
string destUrl = "http://www.google.es";
webBrowser1.Url = new Uri(destUrl);
}

/* Uncomment for WPF frame test
private void Frame_LoadCompleted(object sender, NavigationEventArgs e)
{
}
*/
}
}
</code>

For the application holding the WPF control, I've built a simple MFC application in which I added a class compiled with the /clr option to manage the transition between MFC (unmanaged) and WPF (managed). Following these lines is the code of this class:
<code>
{...}

#include &lt;vcclr.h&gt;

using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Interop;
using namespace WpfControlLibrary1;

ref class Globals
{
public:
static System::Windows::Interop::HwndSource^ gHwndSource;
static UserControl1^ gwcContainer;
};

HWND hwndWPF; //The hwnd associated with the hosted WPF page

HWND GetHwnd(HWND parent, int x, int y, int width, int height)
{
System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew System::Windows::Interop::HwndSourceParameters ("MFCWPFApp");
sourceParams-&gt;PositionX = x;
sourceParams-&gt;PositionY = y;
sourceParams-&gt;Height = height;
sourceParams-&gt;Width = width;
sourceParams-&gt;ParentWindow = IntPtr(parent);
sourceParams-&gt;WindowStyle = WS_VISIBLE | WS_CHILD;
Globals::gHwndSource = gcnew System::Windows::Interop::HwndSource(*sourceParams);
Globals::gwcContainer = gcnew UserControl1();
FrameworkElement^ myPage = Globals::gwcContainer;

Globals::gHwndSource-&gt;RootVisual = myPage;
return (HWND) Globals::gHwndSource-&gt;Handle.ToPointer();
}

/// &lt;summary&gt;
/// Hooks to the HwndSource window procedure. This is required to handle a bug in the WPF interop
/// in case the HwndSource is used in a modal dialog. If the hook is not used, WM_CHAR messages
/// are lost because the standard dialog message loop includes a call to IsDialogMessage().
/// &lt;/summary&gt;
static IntPtr ChildHwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, bool% handled)
{
if (msg == WM_GETDLGCODE)
{
handled = true;

//DLGC_WANTARROWS|DLGC_WANTTAB|DLGC_WANTALLKEYS|DLGC_RADIOBUTTON|DLGC_WANTCHARS
return IntPtr(DLGC_WANTCHARS);
}

return IntPtr(0);
}

// CWPFModelessContainerDlg dialog

IMPLEMENT_DYNAMIC(CWPFModelessContainerDlg, CDialog)

CWPFModelessContainerDlg::CWPFModelessContainerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWPFModelessContainerDlg::IDD, pParent)
{
}

{...}

int CWPFModelessContainerDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;

hwndWPF = GetHwnd(this-&gt;GetSafeHwnd(), lpCreateStruct-&gt;x, lpCreateStruct-&gt;y, lpCreateStruct-&gt;cx, lpCreateStruct-&gt;cy);

// Message hook that ensures WM_CHAR messages are dispatched
// to the managed side. Try removing this line and then writing
// to the WPF TextBox
Globals::gHwndSource-&gt;AddHook(gcnew HwndSourceHook(ChildHwndSourceHook));

return 0;
}

{...}

void CWPFModelessContainerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);

FrameworkElement^ page;
page = Globals::gwcContainer;

page-&gt;MinHeight = cy;
page-&gt;MaxHeight = cy;
page-&gt;MinWidth = cx;
page-&gt;MaxWidth = cx;
::MoveWindow(hwndWPF,0,0,cx,cy,TRUE);
}
</code>

I would appreciate your comments.

Thanks,
Oscar Ortega
GeneralRe: WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key. Pin
NickB25-Jun-08 4:14
NickB25-Jun-08 4:14 
GeneralWPF animation and performance Pin
koleraba17-Apr-08 12:14
koleraba17-Apr-08 12:14 
GeneralRe: WPF animation and performance Pin
User 27100917-Apr-08 18:26
User 27100917-Apr-08 18:26 
Generalfloat Dependency Property Exception Pin
RNEELY17-Apr-08 9:33
RNEELY17-Apr-08 9:33 
GeneralRe: float Dependency Property Exception Pin
Pete O'Hanlon17-Apr-08 9:55
mvePete O'Hanlon17-Apr-08 9:55 
GeneralRe: float Dependency Property Exception Pin
RNEELY17-Apr-08 10:00
RNEELY17-Apr-08 10:00 
Generalwpf xbap listbox problem Pin
pat3d216-Apr-08 9:03
pat3d216-Apr-08 9:03 
GeneralRe: wpf xbap listbox problem Pin
RNEELY18-Apr-08 4:48
RNEELY18-Apr-08 4:48 
GeneralRe: wpf xbap listbox problem Pin
pat3d223-Apr-08 7:27
pat3d223-Apr-08 7:27 
GeneralProblem with UserControl [modified] Pin
koleraba14-Apr-08 15:23
koleraba14-Apr-08 15:23 
GeneralRe: Problem with UserControl Pin
Insincere Dave14-Apr-08 16:33
Insincere Dave14-Apr-08 16:33 
GeneralRe: Problem with UserControl Pin
koleraba15-Apr-08 0:11
koleraba15-Apr-08 0:11 
GeneralPhoto Gallery using Silver light Pin
r aa j14-Apr-08 3:43
r aa j14-Apr-08 3:43 
GeneralRe: Photo Gallery using Silver light Pin
Michael Sync14-Apr-08 17:53
Michael Sync14-Apr-08 17:53 
GeneralRe: Photo Gallery using Silver light Pin
r aa j15-Apr-08 18:16
r aa j15-Apr-08 18:16 
QuestionHow can i use DataGridView in WPF Application? Pin
bankey101011-Apr-08 1:24
bankey101011-Apr-08 1:24 
AnswerRe: How can i use DataGridView in WPF Application? Pin
User 27100911-Apr-08 2:02
User 27100911-Apr-08 2:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.