Hosting Winforms UserControl in CDialog focus problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Hosting Winforms UserControl in CDialog focus problem

  1. #1
    Join Date
    Apr 2005
    Posts
    78

    Question Hosting Winforms UserControl in CDialog focus problem

    Hi,

    Im having a problem with focus hosting a winforms usercontrol within an MFC App via a CDialog.
    As described in this article
    http://msdn.microsoft.com/en-us/library/b1kyh79x.aspx

    The usercontrol displays correctly. When I first attempted to select an UI item within the usercontrol, the program hanged.

    Within the OnInitDialog of the CDialog I changed it to return false, then it was OK.
    I could interact with the controls inside the UserControl correctly.

    BOOL CDialogCaseCLR::OnInitDialog()
    {
    CDialog::OnInitDialog();

    return FALSE; // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
    }

    There are some context menus that bring up dialogs within the user-control when these menuitems are selected, the dialogs never display and it just hangs again like the initial problem?

    Cant get my head round what is the problem and what I have to do to solve it?

    Thanks in advance

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: Hosting Winforms UserControl in CDialog focus problem

    Your debugger should give you some clue.

  3. #3
    Join Date
    Apr 2005
    Posts
    78

    Question Re: Hosting Winforms UserControl in CDialog focus problem

    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x93 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.DefWndProc(ref System.Windows.Forms.Message m) + 0xc bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x10e bytes
    System.Windows.Forms.dll!System.Windows.Forms.TabControl.WndProc(ref System.Windows.Forms.Message m) + 0x1b6 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 135, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes
    [Native to Managed Transition]

    breaking while it hangs produces above?

    So I guess its it some sort of infinite loop, unable to display the child dialog within the usercontrol?

  4. #4
    Join Date
    Apr 1999
    Posts
    27,446

    Re: Hosting Winforms UserControl in CDialog focus problem

    Quote Originally Posted by PRMARJORAM View Post
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x93 bytes
    You do know that this forum does not deal in .NET or managed applications, right?

    You should be posting in the Managed C++ forum.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Apr 2005
    Posts
    78

    Question Re: Hosting Winforms UserControl in CDialog focus problem

    Quote Originally Posted by Paul McKenzie View Post
    You do know that this forum does not deal in .NET or managed applications, right?

    You should be posting in the Managed C++ forum.

    Regards,

    Paul McKenzie
    Well apart from im calling it from a native C++ MFC App?
    So really needs to be in both threads?
    Can it be copied into the other as well?

    Im assuming the problem is to do with the native client host rather than the managed user control.
    When the user control is run from within a managed host app, no problem.

  6. #6
    Join Date
    Apr 1999
    Posts
    27,446

    Re: Hosting Winforms UserControl in CDialog focus problem

    Quote Originally Posted by PRMARJORAM View Post
    Well apart from im calling it from a native C++ MFC App?
    That makes no difference. MFC works fine when used with Native C++.

    What you are asking for is to fix or diagnose a NET issue. All of those functions in the call stack are .NET functions. Not only that, any Forms related questions also go in the Managed C++ forum.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Apr 2005
    Posts
    78

    Re: Hosting Winforms UserControl in CDialog focus problem

    Quote Originally Posted by Paul McKenzie View Post
    That makes no difference. MFC works fine when used with Native C++.

    What you are asking for is to fix or diagnose a NET issue. All of those functions in the call stack are .NET functions. Not only that, any Forms related questions also go in the Managed C++ forum.

    Regards,

    Paul McKenzie
    Ok, Well Iv posted it there too.
    But I feel the solution will be via setting some extended styles or something from with the native parent client app. Thats why I posted it there.

    Note:
    #include <afxwinforms.h>

    Has been a part of MFC since vs 2005. I just got a legacy MFC app, want to do new stuff using more current windows technology. MFC is so old now!

  8. #8
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: Hosting Winforms UserControl in CDialog focus problem

    You have to choose one of two: MFC or .NET.
    Although mixing them is possible (at last everything is possible), that can give you more headache than satisfaction.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  9. #9
    Join Date
    Apr 2005
    Posts
    78

    Re: Hosting Winforms UserControl in CDialog focus problem

    Quote Originally Posted by ovidiucucu View Post
    You have to choose one of two: MFC or .NET.
    Although mixing them is possible (at last everything is possible), that can give you more headache than satisfaction.
    Lol, thats the conclusion I am coming too. Mixing different technologies in practice is full of problems not documented.

    I still feel its something small but its like the needle in the haystack solution. Like changing return TRUE to return FALSE and it all suddenly started working at least at the top level, I was just about to give up at that point.

    Yes am now considering doing a new subsystem in C++ at least got the feature pack from 2008

    But having done a recent .NET project you kind of reluctant to going back and using MFC, tedious!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center