Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key.

WebBrowser hosted in a WPF user control called from MFC dialog hangs when pressing the TAB key.

Scheduled Pinned Locked Moved WPF
csharpwpfcomhelpc++
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OscarOrtega
    wrote on last edited by
    #1

    Hi colleagues, I'm dealing with a weird scenario that I will try to explain here. I don't know what more can I do to find a solution, so I'm posting here with the expectation that someone can help me. I created a user control using WPF & C# in .NET 3.5 with VS2008. This control is placed in a dll. The control has a toolbar, a tree view on the right side and a browser on the left. Inside the XAML code, I'm inserting the WebBrowser control hosted in a WindowsFormsHost. If I use this control from a Container that uses WPF as well everything works fine. The problems arise when I try to call the mentioned control from an MFC application. I created a modeless dialog and call my WPF control. The first problem was that WM_CHARS messages were eaten up by someone, and I didn't receive any keystroke in my WPF control. Hopefully, I found this useful link that helped me to solve the problem: http://devonethatdevelops.wordpress.com/2007/10/30/wpf-win32-interop-with-hwndsource/ But the main problem is that when I put the focus in the web browser and press the TAB key, both the modeless dialog and the application hang. The only thing I can do is go to the task manager and end the process. I've been searching similar problems but found nothing. I've tried to put breakpoints on every KeyDown event both in the containing dialog and in the user control but nothing happens. It seems as though the TAB key absolutely swollen by don't-know-who. I've executed the WPF control from a WPF container and the KeyDown events reach my control on every key I press, but when I call it from the MFC dialog the program don't stop in the breakpoints. The only thing I know is that pressing the TAB key inside the web browser control frozens the application. Please, do you have any idea of what could be happening? Any clue? Well, thanks anyway for having had the patience of reading this. Oscar Ortega

    R O 2 Replies Last reply
    0
    • O OscarOrtega

      Hi colleagues, I'm dealing with a weird scenario that I will try to explain here. I don't know what more can I do to find a solution, so I'm posting here with the expectation that someone can help me. I created a user control using WPF & C# in .NET 3.5 with VS2008. This control is placed in a dll. The control has a toolbar, a tree view on the right side and a browser on the left. Inside the XAML code, I'm inserting the WebBrowser control hosted in a WindowsFormsHost. If I use this control from a Container that uses WPF as well everything works fine. The problems arise when I try to call the mentioned control from an MFC application. I created a modeless dialog and call my WPF control. The first problem was that WM_CHARS messages were eaten up by someone, and I didn't receive any keystroke in my WPF control. Hopefully, I found this useful link that helped me to solve the problem: http://devonethatdevelops.wordpress.com/2007/10/30/wpf-win32-interop-with-hwndsource/ But the main problem is that when I put the focus in the web browser and press the TAB key, both the modeless dialog and the application hang. The only thing I can do is go to the task manager and end the process. I've been searching similar problems but found nothing. I've tried to put breakpoints on every KeyDown event both in the containing dialog and in the user control but nothing happens. It seems as though the TAB key absolutely swollen by don't-know-who. I've executed the WPF control from a WPF container and the KeyDown events reach my control on every key I press, but when I call it from the MFC dialog the program don't stop in the breakpoints. The only thing I know is that pressing the TAB key inside the web browser control frozens the application. Please, do you have any idea of what could be happening? Any clue? Well, thanks anyway for having had the patience of reading this. Oscar Ortega

      R Offline
      R Offline
      RNEELY
      wrote on last edited by
      #2

      Have you tried KeyboardNavigation.TabNavigation="None" for your user control ?

      Sincerely, -Ron

      O 2 Replies Last reply
      0
      • O OscarOrtega

        Hi colleagues, I'm dealing with a weird scenario that I will try to explain here. I don't know what more can I do to find a solution, so I'm posting here with the expectation that someone can help me. I created a user control using WPF & C# in .NET 3.5 with VS2008. This control is placed in a dll. The control has a toolbar, a tree view on the right side and a browser on the left. Inside the XAML code, I'm inserting the WebBrowser control hosted in a WindowsFormsHost. If I use this control from a Container that uses WPF as well everything works fine. The problems arise when I try to call the mentioned control from an MFC application. I created a modeless dialog and call my WPF control. The first problem was that WM_CHARS messages were eaten up by someone, and I didn't receive any keystroke in my WPF control. Hopefully, I found this useful link that helped me to solve the problem: http://devonethatdevelops.wordpress.com/2007/10/30/wpf-win32-interop-with-hwndsource/ But the main problem is that when I put the focus in the web browser and press the TAB key, both the modeless dialog and the application hang. The only thing I can do is go to the task manager and end the process. I've been searching similar problems but found nothing. I've tried to put breakpoints on every KeyDown event both in the containing dialog and in the user control but nothing happens. It seems as though the TAB key absolutely swollen by don't-know-who. I've executed the WPF control from a WPF container and the KeyDown events reach my control on every key I press, but when I call it from the MFC dialog the program don't stop in the breakpoints. The only thing I know is that pressing the TAB key inside the web browser control frozens the application. Please, do you have any idea of what could be happening? Any clue? Well, thanks anyway for having had the patience of reading this. Oscar Ortega

        O Offline
        O Offline
        OscarOrtega
        wrote on last edited by
        #3

        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: Then in the .cs file: namespace WpfControlLibrary1 { /// <summary> /// Interaction logic for UserControl1.xaml /// </summary> 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) { } */ } } 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: {...} #include <vcclr.h> 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::I

        N 1 Reply Last reply
        0
        • R RNEELY

          Have you tried KeyboardNavigation.TabNavigation="None" for your user control ?

          Sincerely, -Ron

          O Offline
          O Offline
          OscarOrtega
          wrote on last edited by
          #4

          Thank you for your answer Ron. The problem is that I'm using the browser to display an InfoPath form, so the user will expect the TAB to be working "as usual" in order to change focus from control to control. So if I tell the user that he's going to lose the TAB key... well, maybe he's not going to be very happy. But thanks, it's a good a idea if everything else fails to work. Oscar

          1 Reply Last reply
          0
          • R RNEELY

            Have you tried KeyboardNavigation.TabNavigation="None" for your user control ?

            Sincerely, -Ron

            O Offline
            O Offline
            OscarOrtega
            wrote on last edited by
            #5

            Anyway, Ron, I've just tested the solution you were proposing but no luck: it still happens the same. Application hangs. It seems as though the problem is more on the MFC side than on the WPF side, but it's only a guess... Thanks, Oscar

            R 1 Reply Last reply
            0
            • O OscarOrtega

              Anyway, Ron, I've just tested the solution you were proposing but no luck: it still happens the same. Application hangs. It seems as though the problem is more on the MFC side than on the WPF side, but it's only a guess... Thanks, Oscar

              R Offline
              R Offline
              RNEELY
              wrote on last edited by
              #6

              It was just a guess. There are quite a few options for that setting and it is not really clear how each one behaves. Probably experimenting with them is the only way to find out for sure. I can see your problem is complex. You might try an MFC forum as well. I'm fresh out of ideas. Good luck.

              Sincerely, -Ron

              1 Reply Last reply
              0
              • O OscarOrtega

                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: Then in the .cs file: namespace WpfControlLibrary1 { /// <summary> /// Interaction logic for UserControl1.xaml /// </summary> 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) { } */ } } 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: {...} #include <vcclr.h> 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::I

                N Offline
                N Offline
                NickB
                wrote on last edited by
                #7

                I feel for you.... MFC and WPF don't play well when it comes to the keyboard. The best solution is to not mix controls! That said, other things you'll need to do to get tabbing kinda working: 1. Override pretranslate message in you App: BOOL CMyApp::PreTranslateMessage(MSG* pMsg) { if (System::Windows::Interop::ComponentDispatcher::RaiseThreadMessage(*reinterpret_castSystem::Windows::Interop::MSG\*(pMsg))) return true; else return CWinApp::PreTranslateMessage(pMsg); } 2. Implement IKeyboardInfoSite and handle OnNoMoreTabStops. Call the MFC dialogs NextDlgCtrl method and return true: In OnCreate: ((IKeyboardInputSink^) hwndWPF)->KeyboardInputSite = gcnew MyKeyboardInputSite(source); bool GKeyboardInputSite::OnNoMoreTabStops(TraversalRequest^ request) { if (request->FocusNavigationDirection == FocusNavigationDirection::Next) wpfDialog->NextDlgCtrl(); else wpfDialog->PrevDlgCtrl(); return true; } The only problem with this is that tabbing back into the WPF user control puts the focus on the last control (not the first). Yet to figure out the best way to overcome that one. Hope this helps

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups