Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Using FindWindow in vb.NET 05 (http://www.programmingforums.org/showthread.php?t=9371)

bigguy Apr 13th, 2006 11:50 PM

Using FindWindow in vb.NET 05
 
Hey yall, I decided to take my Download Blocker to vb.net from vb6. In vb6 I used a imer to look for the Download Windows every second, I tried that with .net and I couldnt get it to work. I dont know where a good place would be to put it in, It needs to look for the windows every second so everything is caught. I have tried Form1_Load,, Activate and Timer_Ticker, Disposed. I cant get any of them to work. Please give me a few ways I could do this or where I could put it. I once put it in Btnblock_Click and it found the window, So I know it is finding the window but I dont think the user wants to clikc that button everything something needs to be blocked. lol

But anyway I know its finding the window I juts need to put it in a place where it will be looking for it all the time. Thanks again yall

grumpy Apr 14th, 2006 12:25 AM

Why not place it in a separate thread? All the thread function needs to do is a continual loop that calls FindWindow(), closes the window if found, and sleeps for 1 second. Preferably, it would also check some flag so that, as your program exits, it could simply set that flag and the thread would terminate within 1 second.

As an aside, I'm not convinced that the best way to implement a "Download Blocker" is to simply close windows that are associated with a download. The workaround would be a little program that runs more frequently and sets the window label to something different --- or, even better, closing down your "Download Blocker". A better way would be to prevent programs from opening a network connection. Of course, that stops all email clients and browsers.

bigguy Apr 14th, 2006 12:36 AM

It's really not that big of deal as of now it's only used within my school. But thanks for the info and I'll look into it more.

Dameon Apr 14th, 2006 1:31 AM

Realize that a clientside download blocker could be easily disabled.

A filtering transparent proxy would be more effective.

bigguy Apr 14th, 2006 2:07 AM

Ok grumpy and I started what you said and here is the code I done for your idea and then the code for mine. Plus the outcome:

1. Your Idea
:

Public Class Form1

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

    Private IEDownload as Int32 = 0

    Private Sub IEDownloads()
        IEDownload = FindWindow("#32770", "File Download")
        MsgBox(IEDownload.ToString + "Download Detected")
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim thrblock As New System.Threading.Thread(AddressOf IEDownloads)
        thrblock.Start()
    End Sub
End Class


^^With that I get the message box as soon as I start the project, regardless if the download window is open or not.

2. My Code
:

Public Class Form1

    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

    Private IEDownload As Int32 = 0

    Private Sub IEDownloads()
        IEDownload = FindWindow("#32770", "File Download")
        MsgBox(IEDownload.ToString + "Download Detected")
    End Sub

    Private Sub Timer1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Disposed
        Dim thrblock As New System.Threading.Thread(AddressOf IEDownloads)
        thrblock.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim thrblock As New System.Threading.Thread(AddressOf IEDownloads)
        thrblock.Start()
    End Sub
End Class


^^^ With that the msgbox doesnt appear till AFTER I close the download windows, well actually when I close the running project and I go back to design mode. I think I'm geting close, but much more of this shit, I'll goi back to vb6. lol
No seriously thanks for yalls help thuis far, and hopefully I'm not that far off from fixing this problem.

Also daemon thanks.

bigguy Apr 14th, 2006 9:39 PM

Well I found my problem. It was my message box. So I made a loop and and put it in a timer and it worked fine when I done form2.show lol. I dont know why but when I done the message boxes it'd just as soon as I loaded the form or w/e it would give a bunch of msg boxes. But I got it fixed now. Thanks for all yalls help


All times are GMT -5. The time now is 9:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC