Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2010 [RESOLVED] Question on Loosing Focus

$
0
0
I've read a bit on both of these, but I'm not sure how to test Loosing Focus to see if it work. Basically my program runs just fine, however when something else takes focus, such as a Windows Update in the Nav bar, my program looses focus and abruptly stops. I want to make sure it does not loose focus so I did some research and found this to be the most effective code to stop it:

LOOSING FOCUS:
Code:

Imports System.Runtime.InteropServices

Public Class progHelper

    'STOPS APPLICATION FROM LOOSING FOCUS!!!!!
    <DllImport("user32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
    Public Shared Function SetForegroundWindow(ByVal hwnd As IntPtr) As <Runtime.InteropServices.MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

 Private Sub WebWindow_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
        SetForegroundWindow(Me.Handle)

    End Sub
End Class

Trouble is, I'm not sure how to test it. From everything I've read, this API call only affects loosing focus, not mouse clicks causing focus to be lost, so if I click on another app while my program is running, I believe it will still loose focus and not complete it's task. Is there anyway I can test this to see if it's working?

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>