|
-
Jun 5th, 2013, 09:07 AM
#1
Thread Starter
PowerPoster
[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?
-
Jun 5th, 2013, 09:21 AM
#2
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
-
Jun 5th, 2013, 09:26 AM
#3
Thread Starter
PowerPoster
Re: [VB6] - how detect if 1 window is open?
 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
-
Jun 5th, 2013, 09:30 AM
#4
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.
-
Jun 5th, 2013, 09:36 AM
#5
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
-
Jun 5th, 2013, 09:41 AM
#6
Thread Starter
PowerPoster
Re: [VB6] - how detect if 1 window is open?
 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)
-
Jun 5th, 2013, 09:51 AM
#7
Re: [VB6] - how detect if 1 window is open?
 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
*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
-
Jun 5th, 2013, 09:55 AM
#8
Thread Starter
PowerPoster
Re: [VB6] - how detect if 1 window is open?
 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
-
Jun 6th, 2013, 09:35 AM
#9
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
 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.
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)
-
Jun 6th, 2013, 09:45 AM
#10
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
 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?
-
Jun 6th, 2013, 09:54 AM
#11
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
 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.
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)
-
Jun 6th, 2013, 11:10 AM
#12
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
 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?
-
Jun 6th, 2013, 11:27 AM
#13
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
-
Jun 6th, 2013, 12:18 PM
#14
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:
 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)
-
Jun 9th, 2013, 07:12 AM
#15
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6] - how detect if 1 window is open?
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|