Results 1 to 17 of 17

Thread: Another window doesnt popup though it should

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Another window doesnt popup though it should

    Hi,
    I am facing strange issue - when another app is not running and folder exists, it does not shown another form. However, if folder does not exists and app is running, it works fine. I prior thought that timers restarting policy is the issue, but its not since it works when folder does not exists.

    2nd app only creates folder and removes it every 5 seconds.
    another form is a form with close button that closes it.

    Code:
    Imports System.Net
    Public Class my_program
        Public Declare Auto Function FindWindowNullClassName Lib "user32.dll" Alias "FindWindow" (ByVal lpClassName As Integer, ByVal lpWindownName As String) As Integer
        Dim Counter As Integer = 0
    
        Private Sub mainwindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If My.Computer.FileSystem.DirectoryExists("C:\directory.desc\") Then
            Else
                My.Computer.FileSystem.CreateDirectory("C:\directory.desc\")
            End If
            timer1.Interval = 15000 '15 sek
            timer1.Start()
        End Sub
    
        Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
            Dim hWnd As Integer = FindWindowNullClassName(0, "nazov.okna.este.nie.je")
    
            If hWnd = 0 And Not My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
                AnotherForm.Show()
            Else
                
            End If
        End Sub
    I dont see the problem since theres AND in my code i.e. both conditions are handled.
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Another window doesnt popup though it should

    If you want AnotherForm to show when the folder exists, why are you checking if it does
    Code:
    Not
    exist in your If statement?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    That does not matter how its written. if file exists or if not file exists
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Another window doesnt popup though it should

    Quote Originally Posted by VB.NET Developer View Post
    That does not matter how its written. if file exists or if not file exists
    Good luck then.

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Another window doesnt popup though it should

    No... both conditions are not handled...
    Code:
        Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
            Dim hWnd As Integer = FindWindowNullClassName(0, "nazov.okna.este.nie.je")
    
            If hWnd = 0 And Not My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
                AnotherForm.Show()
            Else
                
            End If
        End Sub
    That handles one case... where the hWnd is 0 (ie the app is NOT running) and where the Directory does NOT exist ... BUT ... in your start up here:
    Code:
        Private Sub mainwindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If My.Computer.FileSystem.DirectoryExists("C:\directory.desc\") Then
            Else
                My.Computer.FileSystem.CreateDirectory("C:\directory.desc\")
            End If
    you forced the directory to be created... so it will always exist....
    You never handled the Else case in the Timer1_Tick event .... you have 4 possible outcomes:
    hWnd = 0 and directory exists
    hWnd = 0 and directory does not exist
    hWnd <> 0 and directory exists
    hWnd <> 0 and directory does not exist

    You've only handled that second one... you haven't done anything to handle any of those other cases. But since you force the directory creation, you really only care about two outcomes:
    hWnd = 0 and directory exists
    hWnd <> 0 and directory exists
    But you've still only handled the one possibility... and it isn't one of those two...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    Beware,
    Code:
    C:\directory.desc\
    its not the correct directory. The correct directory is C:\directory.desc\initial-check
    No, the directory is periodically created and removed every 3 seconds - via another app with this code:

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer1.Interval = 3000
            Timer1.Start
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
                My.Computer.FileSystem.DeleteDirectory("C:\directory.desc\initial-check", FileIO.DeleteDirectoryOption.DeleteAllContents)
            Else
                My.Computer.FileSystem.CreateDirectory("C:\directory.desc\initial-check\")
            End If
        End Sub
    The problem is, after a few seconds when folder is created and removed, AnotherForm is opened.

    My current code:
    Code:
    Private Sub mainwindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Timer1.Interval = 15000 '15 sek
            Timer1.Start()
    End Sub
    
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim hWnd As Integer = FindWindowNullClassName(0, "nazov.okna.este.nie.je")
    
            If hWnd = 1 And My.Computer.FileSystem.DirectoryExists("C:\directory.desc\initial-check\") Then
    
            Else
                AnotherForm.Show()
            End If
    You can try these codes yourself and you will see the behavior.
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    Can you help me??
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Another window doesnt popup though it should

    The whole thing seems convoluted. You have a separate application that, every 3 seconds will either create this folder if it doesn't exist, or will delete the folder if it does. So every 3 seconds it goes from existing, to non-existing, to existing, to non-existing, ...

    Then, every 15 seconds, this other application displays AnotherForm if hWnd != 1 Or the directory in question doesn't exist. Because the directory in question doesn't exist half of the time, I would expect AnotherForm to be displayed every other time that 15 second timer is ran, so every 30 seconds or so (with some variance as far as how closely the two timers are aligned).

    I think the help you need is only going to happen if you explain, in detail what, exactly, you are trying to accomplish with this convoluted timer and folder stuff.

    As it stands, I doubt anyone has a clue what your end goal is and therefore no specific coding help can be offered.

    Good luck.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    Sure. I want to detect presence of my second app both via window name AND presence of folder REPEATEDLY.
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Another window doesnt popup though it should

    Quote Originally Posted by VB.NET Developer View Post
    Sure. I want to detect presence of my second app both via window name AND presence of folder REPEATEDLY.
    Why? Is this a "because I can" sort of thing or are you actually trying to achieve something useful? If the latter, you should explain what that is because it's hard to imagine that there isn't a better way than what you describe.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    I already explained what it is - I want to detect presence of my second app when both conditions are true. Enough explanation?
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Another window doesnt popup though it should

    Quote Originally Posted by VB.NET Developer View Post
    Sure. I want to detect presence of my second app both via window name AND presence of folder REPEATEDLY.
    Right. And yet, your second app keeps deleting and recreating that folder REPEATEDLY. So there will continuously be times that your first app finds the second app via window name, but the folder is missing.

    And there's been no logical reason given for WHY you are doing any of this with timers, window handles, and folder recreation. And because I doubt that reason is forthcoming, I'm officially done with this thread.

    Good luck.

  13. #13
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Another window doesnt popup though it should

    You can check for a running process like this:-
    Code:
    '
            If Process.GetProcessesByName("Notepad").Length > 0 Then
                MessageBox.Show("Notepad is running!!")
            End If
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    Sure, I know, but I solved this via window name instead of process name.
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Another window doesnt popup though it should

    Quote Originally Posted by VB.NET Developer View Post
    I already explained what it is
    Yes you did, but I didn't ask you "what". I asked you "why". You don't have to answer my question if you don't want to but I'm not interested in helping people to do the wrong thing so if you can't help me establish that what you want to do is the right thing, I won't be spending my time helping you to do it.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    I want to build some kind of advanced process detector.
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2018
    Posts
    276

    Re: Another window doesnt popup though it should

    @jmcilhinney
    Hope that is enough explanation what I want to do. Or am I wrong?
    Please dont forget to add good reputation if my advices were useful for you.
    How? Under this post there is "RATE THIS POST" button. Click on it.

Tags for this Thread

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