Results 1 to 15 of 15

Thread: [RESOLVED] [VB6] - how detect if 1 window is open?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,960

    Resolved [RESOLVED] [VB6] - how detect if 1 window is open?

    i have these code for:
    1 - call the compiler;
    2 - testing if the compiler continues open;
    3 - if the compiler is closed, then open the exe.
    Code:
    Private Sub mnuCompileCompleAndRun_Click()
        Call mnuCompileCompile_Click 'open the compiler
        Do
            If FindWindow(App.Path & "\MinGW32\bin\gcc.exe", vbNullString) <> 0 Then
                'is open
            Else
                Exit Do
            End If
            DoEvents
        Loop
        Call mnuCompileRun_Click 'open the exe
    End Sub
    can anyone tell me where i did wrong?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,263

    Re: [VB6] - how detect if 1 window is open?

    Is it just me, or is he running into an endless loop the moment the If-clause returns true?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,960

    Re: [VB6] - how detect if 1 window is open?

    Quote Originally Posted by Zvoni View Post
    Is it just me, or is he running into an endless loop the moment the If-clause returns true?
    if i understand your question: yes. the loop is for test if the window is open. that string it's the caption
    but seems not working
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: [VB6] - how detect if 1 window is open?

    The first param of the FindWindow is the class name not the exe name, use the tool Spy++ (comes with VB6) to know the class name of the compiler window.



  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,263

    Re: [VB6] - how detect if 1 window is open?

    Or he could just enumrate all processes and look for gcc.exe
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,960

    Re: [VB6] - how detect if 1 window is open?

    Quote Originally Posted by 4x2y View Post
    The first param of the FindWindow is the class name not the exe name, use the tool Spy++ (comes with VB6) to know the class name of the compiler window.
    sorry.. the window caption is the exe name
    (i have seen that)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: [VB6] - how detect if 1 window is open?

    Quote Originally Posted by joaquim View Post
    sorry.. the window caption is the exe name
    (i have seen that)

    Try to swap param, e.g.
    Code:
    FindWindow(vbNullString, App.Path & "\MinGW32\bin\gcc.exe")
    but i doubt that will success according to a review in http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    *Don't try to use FindWindow if you want to get a window that's in another process!!!*
    As i said, use the Spy++ to get the class name, it will save you a lot of headache



  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,960

    Re: [VB6] - how detect if 1 window is open?

    Quote Originally Posted by 4x2y View Post
    Try to swap param, e.g.
    Code:
    FindWindow(vbNullString, App.Path & "\MinGW32\bin\gcc.exe")
    but i doubt that will success according to a review in http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx


    As i said, use the Spy++ to get the class name, it will save you a lot of headache
    thanks works
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] [VB6] - how detect if 1 window is open?

    Quote Originally Posted by joaquim View Post
    i have these code for:
    1 - call the compiler;
    2 - testing if the compiler continues open;
    3 - if the compiler is closed, then open the exe.
    You might find that a Shell and Wait method (such as this) is more reliable than FindWindow.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,960

    Re: [RESOLVED] [VB6] - how detect if 1 window is open?

    Quote Originally Posted by Bonnie West View Post
    You might find that a Shell and Wait method (such as this) is more reliable than FindWindow.
    thanks
    1 thing: why i can't use " "(sepace) in parameters?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] [VB6] - how detect if 1 window is open?

    Quote Originally Posted by joaquim View Post
    1 thing: why i can't use " "(sepace) in parameters?
    Can you show your code? You're probably not doing something right.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  12. #12

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,960

    Re: [RESOLVED] [VB6] - how detect if 1 window is open?

    Quote Originally Posted by Bonnie West View Post
    Can you show your code? You're probably not doing something right.
    see these sub:
    Code:
    Private Sub mnuCompileCompile_Click()
        Dim strCompilerName As String
        Dim strCPPFonteName As String
        Dim strEXEFileName As String
        Call ConvertCode(rtbConvertedCode, rtbTextCode)
       
        rtbConvertedCode.SaveFile App.Path & "\test.cpp", rtfCFText
        strCompilerName = App.Path & "\MinGW32\bin\gcc.exe"
        strEXEFileName = App.Path & "\test "
        strCPPFonteName = App.Path & "\test.cpp"
        
        ShellExecute Form1.hwnd, "open", strCompilerName, "-o " & strEXEFileName & strCPPFonteName, App.Path & "\MinGW32\bin", 10
    End Sub
    see these: App.Path. if i change the folder name from "C:\ConvertLanguage" to "C:\Convert Language"(see the sepace) the gcc.exe isn't open
    why these situation? why i can't use sepace?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,263

    Re: [RESOLVED] [VB6] - how detect if 1 window is open?

    Not familiar with gcc.exe, but isn't there a space missing between strEXEFilename and strCPPFontename?

    strEXEFilename & strCPPFontename

    something else: i'm pretty sure that shellexecute is the wrong function. Since when do you have an "open"-command for an EXE? Try Shell

    EDIT: i just saw the trailing space in strEXEFilename. Discard my comment
    Last edited by Zvoni; Jun 6th, 2013 at 11:31 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  14. #14
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] [VB6] - how detect if 1 window is open?

    Command line arguments are usually delimited by spaces. If a path contains space(s), you must surround it with quotation marks (") so that the path is treated as a single parameter. Try the following modifications:

    Code:
    Private Sub mnuCompileCompile_Click()
        Const SW_SHOWDEFAULT = 10&
    
        Dim App_Path        As String
        Dim strCompilerName As String
        Dim strCPPFonteName As String
        Dim strEXEFileName  As String
        Dim strWorkingDir   As String
    
        Call ConvertCode(rtbConvertedCode, rtbTextCode)
    
        App_Path = App.Path 'Properties are slow to access. Retrieve them only once.
    
        strCompilerName = App_Path & "\MinGW32\bin\gcc.exe"
        strWorkingDir = App_Path & "\MinGW32\bin"
        strEXEFileName = App_Path & "\test"
        strCPPFonteName = App_Path & "\test.cpp"
    
        rtbConvertedCode.SaveFile strCPPFonteName, rtfCFText
    
        ShellExecute Form1.hWnd, "open", strCompilerName, "-o """ & strEXEFileName & """ """ & strCPPFonteName & """", strWorkingDir, SW_SHOWDEFAULT
    End Sub


    @ Zvoni

    According to the ShellExecute doc:

    Quote Originally Posted by MSDN
    open
    Opens the item specified by the lpFile parameter. The item can be a file or folder.
    Shell can't specify the working directory, although it can be set prior to shelling via ChDrive and ChDir.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  15. #15

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,960

    Re: [RESOLVED] [VB6] - how detect if 1 window is open?

    Quote Originally Posted by Bonnie West View Post
    Command line arguments are usually delimited by spaces. If a path contains space(s), you must surround it with quotation marks (") so that the path is treated as a single parameter. Try the following modifications:

    Code:
    Private Sub mnuCompileCompile_Click()
        Const SW_SHOWDEFAULT = 10&
    
        Dim App_Path        As String
        Dim strCompilerName As String
        Dim strCPPFonteName As String
        Dim strEXEFileName  As String
        Dim strWorkingDir   As String
    
        Call ConvertCode(rtbConvertedCode, rtbTextCode)
    
        App_Path = App.Path 'Properties are slow to access. Retrieve them only once.
    
        strCompilerName = App_Path & "\MinGW32\bin\gcc.exe"
        strWorkingDir = App_Path & "\MinGW32\bin"
        strEXEFileName = App_Path & "\test"
        strCPPFonteName = App_Path & "\test.cpp"
    
        rtbConvertedCode.SaveFile strCPPFonteName, rtfCFText
    
        ShellExecute Form1.hWnd, "open", strCompilerName, "-o """ & strEXEFileName & """ """ & strCPPFonteName & """", strWorkingDir, SW_SHOWDEFAULT
    End Sub


    @ Zvoni

    According to the ShellExecute doc:



    Shell can't specify the working directory, although it can be set prior to shelling via ChDrive and ChDir.
    thanks for all and i change it:
    Code:
    Private Sub mnuCompileCompile_Click()
        Dim strCompilerName As String
        Dim strCPPFonteName As String
        Dim strEXEFileName As String
        Dim App_Path        As String
        
        App_Path = App.Path
        
        Call ConvertCode(rtbConvertedCode, rtbTextCode)
       
        rtbConvertedCode.SaveFile App_Path & "\test.cpp", rtfCFText
        strCompilerName = """" & App_Path & "\MinGW32\bin\g++.exe" & """"
        strEXEFileName = """" & App_Path & "\test" & """"
        strCPPFonteName = """" & App_Path & "\test.cpp" & """"
        
        ShellExecute frmIDE.hWnd, "open", strCompilerName, "-o " & strEXEFileName & " " & strCPPFonteName, App.Path & "\MinGW32\bin", 10
    End Sub
    now works for long names and with spaces
    anotherthing: i change the Compile Run command
    Code:
    Private Sub mnuCompileCompleAndRun_Click()
        Call mnuCompileCompile_Click 'abre o compilador
        Sleep 1000
        Do
            If FindWindow(vbNullString, App.Path & "\MinGW32\bin\gcc.exe") <> 0 Then
                'is open
            Else
                Exit Do
            End If
            DoEvents
        Loop
        Sleep 1000
        Call mnuCompileRun_Click 'abre o executavel
    End Sub
    with that 2 sleep()'s is working better
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

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