CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Modal dialog doesnt get focus

    I have a mfc sdi application without a doc/view architecture. The "view" is derived from CWnd. When the user right-clicks on the view a popup menu is created. Some commands of the popup menu might result in creating a modal dialog.

    Unfortunately somehow the "view" rerains it's focus and unless I explicitly click on the modal dialog once it still gets commands.

    There are two problems with that. The first is that to close the dialog, you must click it two times (which isn't horrible but it still is a pain in the donkey). The second is that mousemove messages sent to the view are still sent due to it having focus, and it's bad for the application behaviour.

    I tried calling SetFocus in OnInitDialog of the dialogs and it didn't help. Even if it did though this isn't a solution since some of the dialogs are not mine and I don't have a control of their behaviour.

    So can someone please help?
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Modal dialog doesnt get focus

    How do you create/pop up this modal dialog? What peculiar do you do in its OnInitDialog handler?
    Post some code.

  3. #3
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661

    Re: Modal dialog doesnt get focus

    Quote Originally Posted by VictorN
    How do you create/pop up this modal dialog? What peculiar do you do in its OnInitDialog handler?
    Post some code.
    It's truly simple It hapens to every dialog. Even to an example dialog that doesn't even have it's own class. Here is how i create it:

    Code:
    void CTheView::OnSomeCommand()
    {
        CDialog dlg(IDD_SAMPLE /*, this*/);
        dlg.DoModal();
    }
    The parent parameter of the constructor doesn't change a thing. No mater if it's the view or the main frame.

    Oh and another thing. The dialog does get focus if the command is sent from the application menu (IDR_MAINFRAME) but if the same command is sent through the popup menu that appears on right-clicking the view the dialog doesn't get focus.
    Last edited by SeventhStar; May 5th, 2007 at 03:28 AM.
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Modal dialog doesnt get focus

    Still not clear...
    If you are using VC6.0 then try to create a small test project representating your problem and post it to the forum (.zip without Releasa, Debug subfolders and without .ncb file)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured