So far I have been able to Shell a program such as Microsoft Word, and I can grab the handle (I am pretty sure it is the handle). But I can not for the life of me set the window to TOPMOST. What I am currently doing is using the Shell() function to grab the Process_ID and then utilizing the OpenProcess() function to get the hWnd (I think it is getting it?) The code below will shell Microsoft Word, but it just won't set it to TOPMOST.
Code:
Public Function ShellProgram(ProgType As String, DirectoryPath As String, FilePath As String)
Dim m_intTaskButAmount As Integer
Dim m_strFileName As String
Dim sClass As String, sCaption As String
Dim buf As String
Dim buf_len As Long, hWndDesktop As Long
Dim hProcWindow As Long
sClass = vbNullString
sCaption = vbNullString
lngShellFile = Shell(FilePath, vbMaximizedFocus)
DoEvents
'm_lngHandle = InstanceToWnd(lngShellFile)
m_lngHandle = OpenProcess(&H400, 0, lngShellFile)
hWndDesktop = GetDesktopWindow
Do
m_lngWindow = FindWindowEx(hWndDesktop, m_lngHandle, sClass, sCaption)
'Get the ID of the process that owns the window
GetWindowThreadProcessId m_lngWindow, hProcWindow
'Loop until the window's process matches this process,
'or we didn't find a window
Loop Until hProcWindow = lngShellFile Or m_lngWindow = 0
'm_lngWindow = FindWindowEx(hWndDesktop, m_lngHandle, sClass, sCaption)
'DoEvents
'm_lngHandle = FindWindow( m_strFileName, vbNullString)
Call Addline(lngShellFile & " " & m_lngHandle & " " & m_lngWindow)
' buf = Space$(256)
' buf_len = GetWindowText(m_lngHandle, buf, Len(buf))
' buf = Left$(buf, buf_len)
Call SetTopMostForm(m_lngWindow, True)
End Function
Public Function SetTopMostForm(hWnd As Long, Topmost As Boolean) As Long
Call Addline("Handle of form is " & hWnd)
'Make the window topmost
If Topmost = True Then
SetTopMostForm = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
SetTopMostForm = SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
SetTopMostForm = False
End If
End Function