Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 13th, 2006, 11:50 PM   #1
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
Exclamation 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
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain

Destruction leads to a very rough road, but it also breeds creation.
bigguy is offline   Reply With Quote
Old Apr 14th, 2006, 12:25 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
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.
grumpy is offline   Reply With Quote
Old Apr 14th, 2006, 12:36 AM   #3
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
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.
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain

Destruction leads to a very rough road, but it also breeds creation.
bigguy is offline   Reply With Quote
Old Apr 14th, 2006, 1:31 AM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Realize that a clientside download blocker could be easily disabled.

A filtering transparent proxy would be more effective.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Apr 14th, 2006, 2:07 AM   #5
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
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.
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain

Destruction leads to a very rough road, but it also breeds creation.
bigguy is offline   Reply With Quote
Old Apr 14th, 2006, 9:39 PM   #6
bigguy
Professional Programmer
 
bigguy's Avatar
 
Join Date: Sep 2005
Location: Arkansas
Posts: 298
Rep Power: 0 bigguy is an unknown quantity at this point
Send a message via AIM to bigguy Send a message via MSN to bigguy Send a message via Yahoo to bigguy
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
__________________
Forgiveness is the fragrance that the violet sheds on the heal that has crushed it. - Mark Twain

Destruction leads to a very rough road, but it also breeds creation.
bigguy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:26 PM.

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