so i remembered people talking about threads; check the example and implemented it myself. however, i found that the 'Shell "command"' was still halting even the threads returning until it was closed.
i then tested the thread program using "explorer." it sucessfully opened each explorer window in a different thread.
the reason i fgured out it halts is because in the code there is a thing to make a window always on top.
well, here's the code... my question is... is it possible to open a command prompt in a concurrently running thread? or am i doomed to wait for it to 'finish', always..
NOTE: due to the nature of this program, it is recommended to only compile and run it using the "-s gui" switch through fbc.exe.
also, this code will probably only compile in .14 without tweaking the win calls. (and, i've edited my local user32.bi to accomodate default function params :p)
Code: Select all
#Include "win\user32.bi"
#Include "fbgfx.bi"
Declare Sub cmd( ByVal num As Integer)
Declare Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Declare Function GetAllWindows() As Integer
Screen 13
ReDim Shared WinHandle(1 To 1) As Long
Dim Shared WinHandleCount As Long
Dim Shared lWindows(1 To 1) As Long
Dim Counter As Long
Dim sWindows As String
Dim WinTitle As String
Dim TitleLen As Long
Dim prompts As uInteger
Dim As Double _timer, s_timer, e_timer
Dim As Integer hwnd
WindowTitle "Shl"
hwnd = FindWindow( 0, "Shl" )
ShowWindow ByVal hwnd, sw_hide
Dim As Integer a, switch = Not 0
ReDim Shared As uInteger cmd_cnt(0)
ThreadCreate( @cmd, prompts )
prompts = 1
Do
a = GetForegroundWindow
If MultiKey( sc_control ) And MultiKey( sc_alt ) Then
If _timer = 0 Then
_timer = Timer + 1
End If
If Timer >= _timer Then
cmd_cnt( prompts ) = ThreadCreate( @cmd, prompts )
_timer = 0
End If
Else
_timer = 0
End If
If MultiKey( sc_control ) And Not MultiKey( sc_alt ) Then
If s_timer = 0 Then
s_timer = Timer + 1
End If
If Timer >= s_timer Then
switch = Not switch
MessageBeep
SetWindowPos( a, switch - 1, , , , , swp_nomove Or swp_nosize )
For flsh = 0 To 3
Dim As Double b_timer
b_timer = Timer + .3 - ( ( flsh * 4 ) / 100 )
FlashWindow( a, -1 )
Do
Sleep 1
Loop While Timer < b_timer
Next
s_timer = 0
End If
Else
s_timer = 0
End If
If MultiKey( sc_escape ) And Not MultiKey( sc_control ) Then
If e_timer = 0 Then
e_timer = Timer + 1
End If
If Timer >= e_timer Then
End
End If
Else
e_timer = 0
End If
WinHandleCount = 0
prompts = 0
If GetAllWindows() = True Then
If WinHandleCount > 0 Then
For Counter = 1 To WinHandleCount
'Get the length of the buffer we need
TitleLen = GetWindowTextLength(WinHandle(Counter)) + 1
'Create the buffer
WinTitle = Space$(TitleLen + 1)
GetWindowText(WinHandle(Counter), WinTitle, TitleLen + 1)
WinTitle = Trim$(WinTitle)
DestroyWindow (WinHandle(Counter))
If Left( WinTitle, 13 ) = "MS-DOS Prompt" Then prompts += 1
ReDim Preserve cmd_cnt( prompts - 1 )
' ? WinTitle
WinTitle = ""
Next
End If
End If
Erase WinHandle
Sleep 2
Loop
Sub cmd( ByVal num As Integer)
Shell "c:\windows\command.com"
End Sub
'Here is the callback function that returns each window handle
Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
'Inc the array index
WinHandleCount = WinHandleCount + 1
ReDim Preserve WinHandle(1 To WinHandleCount) As Long
' Add the information to the array
WinHandle(WinHandleCount) = hWnd
' Tell the function to keep going
EnumWindowsProc = 1
End Function
Function GetAllWindows() As Integer
' Start enumerating through the windows
'The @ passes the address of EnumWindowsProc
If EnumWindows(@EnumWindowsProc, 0) <> 0 Then
GetAllWindows = True
End If
End Function
the window enumeration routine was taken from some posted source of either Jerry Fielden, or fsw, to be honest i can't remember, but those are the local win32 gurus ;p