|
-
Feb 11th, 2003, 08:27 AM
#1
Thread Starter
New Member
AppActivate & Windows 2000
Does anybody know function (API?) replacement for AppActivate?
In Win2000 AppActivate doesn't work 
I'm using VB5SP3 on Win2000
Many thanx
-
Feb 11th, 2003, 10:23 AM
#2
Frenzied Member
VB Code:
'This example requires two forms with on each for one command button.
'Both buttons should be named 'Command1'
'In Form1
Private Sub Command1_Click()
' Make the window Form2 the active window for the program. Note that
' this function will not make the window the foreground window if the user is currently
' working with a separate program.
Dim retval As Long ' return value
retval = SetActiveWindow(Form2.hwnd) ' set Form2 as the application's active window
End Sub
Private Sub Form_Load()
Form2.Show
End Sub
'In Form2:
Private Sub Command1_Click()
Dim retval As Long ' return value
retval = SetActiveWindow(Form1.hwnd) ' set Form1 as the application's active window
End Sub
'In a module:
Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
-
Feb 12th, 2003, 12:44 AM
#3
Addicted Member
If you want foreground window behavior also, then you may
opt to try:
void SwitchToThisWindow (HWND hWnd, BOOL bRestore); // User32.dll
You'll have to write the VB Declare statement to port it over,
but it will definately do the trick. BTW, use this function as a last
resort because Microsoft does not support it.
-
Feb 12th, 2003, 06:42 AM
#4
Thread Starter
New Member
Thanx for your answers, but i still have problems...
SetActiveWindow returns 0
SwitchToThisWindow does nothing
Can you take a look at my prog? what's wrong?
VB Code:
Public Const GW_HWNDNEXT = 2
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwprocessid As Long) As Long
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
Declare Function SwitchToThisWindow Lib "user32" (ByVal hwnd As Long, ByVal fAltTab As Boolean)
Declare Function GetLastError Lib "kernel32" () As Long
Public Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
ProcIDFromWnd = idProc
End Function
Public Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long
' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)
' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If
' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
Private Sub Command1_Click()
progID = Shell("notepad.exe", vbNormalFocus)
For i = 1 To 500000
DoEvents
Next i
progID = GetWinHandle(progID)
tempID = SetActiveWindow(progID)
End Sub
Last edited by krokodil; Feb 12th, 2003 at 06:47 AM.
-
Feb 12th, 2003, 02:01 PM
#5
Frenzied Member
When I open notepad with vbNormalFocus, it already has focus.
-
Feb 13th, 2003, 04:16 AM
#6
Thread Starter
New Member
Originally posted by Shawn N
When I open notepad with vbNormalFocus, it already has focus.
Even if app which are you shelling from had not focus?
Sorry for my english, i'm beginner
-
Feb 13th, 2003, 11:08 PM
#7
Frenzied Member
-
Feb 15th, 2003, 05:44 AM
#8
Thread Starter
New Member
Originally posted by Shawn N
notepad
I mean, if the VB application which runs shell hadn't focus.
Look:
If MyVbApp have focus then notepad have focus
If MyVbApp have not focus (e.g. desktop have focus), also the notepad haven't focus
But If i run second shell immediately after notepad, i can set focus to this shell by API, but i can't set focus to the first shell (notepad).
Hope you understand my english
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
|