[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?
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?
Re: [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
Zvoni
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:(
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.
Re: [VB6] - how detect if 1 window is open?
Or he could just enumrate all processes and look for gcc.exe
Re: [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
4x2y
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)
Re: [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
joaquim
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
Quote:
*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
Re: [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
4x2y
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
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
joaquim
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.
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
Bonnie West
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?
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
joaquim
1 thing: why i can't use " "(sepace) in parameters?
Can you show your code? You're probably not doing something right.
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
Bonnie West
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?
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
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.
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
Quote:
Originally Posted by
Bonnie West
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