dcsimg
Results 1 to 8 of 8

Thread: Losing Focus in a DirectX Project

Hybrid View

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Losing Focus in a DirectX Project

    I bet most people in this forum have came across this one before, when say you press Alt + Tab and your DirectX App loses focus it doesn't like it, yeah? Well I know you can Restore Surfaces then reload the images but does anyone know if theres a way just to stop it from losing the surfaces in the first place?
    Thanx,

    Paul
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    you mean like how DOS is made exclusively?

    Not sure, but im sure theres some API for it, did you look at PSC?

  3. #3

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Originally posted by Madboy
    you mean like how DOS is made exclusively?

    Not sure, but im sure theres some API for it, did you look at PSC?
    Well even if you set DirectX to Exclusive its still happens, I don't know if theres some kind of setting in Dx or something. PSC??


    Originally posted by Madboy
    Not sure, but im sure
    .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Originally posted by Electroman
    PSC??
    Planet-Source-Code

    link in signature

  5. #5

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    doh!
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,191
    Yeah you can disable the Alt+Tab buttons, but it is not recomended at all. It is really anoying, and all real DX books are trying to make you understand how irritating it is. And an other thing is that some IMs and other stuff might pop up in the window on some machines too, and that will make you loos the focus too, so the best thing to do is to always check if you have the focus and if not, restore it...

  7. #7

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    As soon as you lose focus tho you need to retsore all the surfaces right, and how exactly do you check for focus and get focus back?
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  8. #8
    New Member Son of Makuta's Avatar
    Join Date
    Sep 2007
    Posts
    14

    Re: Losing Focus in a DirectX Project

    You can check for focus by using GetActiveWindow, a minor API call:
    Code:
    Public Declare Function GetActiveWindow Lib "user32" () As Long
    
    If GetActiveWindow = Form1.hWnd Then
        'You've got the focus
    Else
        'You've not
    End If
    Dunno about restoring surfaces though...? My program throws automation errors when it restores, but this method might work for you though, 'cos I'm not using many surfaces, mostly textures and sprites and stuff. (And because I'm hideously error-prone at times.) I presume your Form_Load sub holds all the surface-loading code, yeah? You can cheat: whenever the form reactivates, bomb it out and load it again.

    The best way to go about that is just to use a little sub called Form_Activate and a variable saying when the program's tabbed out.
    Code:
    Private Sub Form_Load
        'The lot
        TabOut = False
    End Sub
    
    Private Sub Form_Activate
        If TabOut = True Then
            Unload Me   'Not sure if this is necessary
            Form_Load
        End If
    End Sub
    
    'Later on, in the main loop...
    Private Sub RenderAll         'Called by the main loop
        If GetActiveWindow = Me.hWnd Then
            'Do the funky rendering gibbon
        Else
            TabOut = True
        End If
    End Sub
    That any good for you?

    Edit: You do know that [VBCode] thing [/VBCode] in your sig doesn't work, don't you?
    Last edited by Son of Makuta; Feb 16th, 2008 at 01:42 PM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width