Does anybody know function (API?) replacement for AppActivate?
In Win2000 AppActivate doesn't work :(
I'm using VB5SP3 on Win2000
Many thanx
Printable View
Does anybody know function (API?) replacement for AppActivate?
In Win2000 AppActivate doesn't work :(
I'm using VB5SP3 on Win2000
Many thanx
VB Code:
'Code by Mahbub ([email protected]) '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
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.
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
When I open notepad with vbNormalFocus, it already has focus.
Even if app which are you shelling from had not focus?Quote:
Originally posted by Shawn N
When I open notepad with vbNormalFocus, it already has focus.
Sorry for my english, i'm beginner
notepad
I mean, if the VB application which runs shell hadn't focus.Quote:
Originally posted by Shawn N
notepad
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 :)