CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2003
    Location
    India
    Posts
    232

    Modal Dialog loosing focus

    I have got a SDI application. On selecting a menu option, a modal dialog is shown using dlg.DoModal().

    In the InitDialog, 6 comboboxes (5 visible and 1 invisible) are populated with values read from files. But as soon as the dialog is painted on the screen, it looses focus. (The title bar appears gray instead of blue). On clicking on the dialog, focus returns.

    I want u to suggest probable reasons of this kind of behaviour. Could it be bcoz of the invisible combo.

    Moreover, OnPaint has not been overridden, neither has been PreCreateWindow.
    Sarve Bhavantu Sukheenah,
    Sarve Santu Niramayah,
    Sarve Bhadrani Pashyantu,
    Ma Kashchit dukh bhag bhavet.

  2. #2
    Join Date
    Aug 2004
    Location
    Earth, Solar System, Milky Way
    Posts
    80

    Re: Modal Dialog loosing focus

    Try in the resource editor to change the tab order of the dialog controls and make it first one visible.
    Hokutata Yakubotu

  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Modal Dialog loosing focus

    Is your dialog style set to child by any chance?
    Also are you performing any lengthy operation in a while loop?
    Last edited by JohnCz; October 19th, 2004 at 08:01 AM.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Join Date
    Feb 2003
    Location
    India
    Posts
    232

    Re: Modal Dialog loosing focus

    I have tried setting the tab order. Tab order 1 is a visible control. My dialog style is Popup.
    The operations I perform to populate the combo cant be categorized as lengthy. 10 values for each of 6 combos read either from memory or from local disk.
    Sarve Bhavantu Sukheenah,
    Sarve Santu Niramayah,
    Sarve Bhadrani Pashyantu,
    Ma Kashchit dukh bhag bhavet.

  5. #5
    Join Date
    Aug 2004
    Location
    INDIA
    Posts
    260

    Re: Modal Dialog loosing focus

    Return Value of OnInitDialog

    Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box.

    Have a look at OnInitDialog function description in MSDN.
    http://msdn.microsoft.com/library/de...initdialog.asp
    If you feel this post is useful,
    Rate this Post by clicking right top corner (Rate this Post)
    Santhosh

    ***Add strength to your country - Interesting Poll
    ***

  6. #6
    Join Date
    Feb 2003
    Location
    India
    Posts
    232

    Re: Modal Dialog loosing focus

    OnInitDialog is returning non-zero. The dialog has focus for abt a fraction of second and I can notice that the focus was actually on the first control before the focus goes away.
    Sarve Bhavantu Sukheenah,
    Sarve Santu Niramayah,
    Sarve Bhadrani Pashyantu,
    Ma Kashchit dukh bhag bhavet.

  7. #7
    Join Date
    Aug 2004
    Location
    INDIA
    Posts
    260

    Re: Modal Dialog loosing focus

    Better post your sample source.. Not clear what you are doing in OnInitDialog
    If you feel this post is useful,
    Rate this Post by clicking right top corner (Rate this Post)
    Santhosh

    ***Add strength to your country - Interesting Poll
    ***

  8. #8
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Modal Dialog loosing focus

    What kind of comboboxes are those ? Are they CComboBox / or some other class ?

    Did you try stripping out the initialization of those comboboxes and see if that made a difference ?

  9. #9
    Join Date
    Feb 2003
    Location
    India
    Posts
    232

    Re: Modal Dialog loosing focus

    Hi Gurus.

    Actualy there was a timer active, the handler of which performed SetWindowPos on the mainframe. That was forcing the focus away from the dialog. Now the dialog works fine.
    Sarve Bhavantu Sukheenah,
    Sarve Santu Niramayah,
    Sarve Bhadrani Pashyantu,
    Ma Kashchit dukh bhag bhavet.

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