Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Visual Basic





See Related Forum Messages: Follow the Links Below to View Complete Thread

SetForeGroundWindow
I'm working on a couple of applications. The first is the main application (MainApp), the second is an ActiveX application (SearchApp) that searches and returns data to MainApp. When MainApp calls SearchApp, MainAppForm is disabled and waits for the data return. After SearchApp returns the data, SearchAppForm is hidden. MainApp then process the data, set some fields on MainAppForm, enables and sets focus to MainAppForm.

My first problem was between SearchAppForm.hide and MainAppForm.setFocus, the focus goes to the last app active before MainApp. To fix this I had SearchApp loop until MainAppForm was enabled and moved to the foreground before hidding SearchAppForm. This works in Win95/98/NT.

My problem now is that it does not work in Win2K. In Win2K I can see the title bar of MainAppForm change like it has focus but it does not come to the foregournd. I tried using the api call SetForegroundWindow and in Win2K it still just blinks in the background. Any ideas on what I need to do in Win2k to get this to work?

TIA
Bob

SetForegroundWindow On Asp-net
Hi, i'm trying to use the SetForegroundWindow function under the asp-net(aspx) developer, i used the same code un a normal VB6 exe project and works beautifully, but when we implement that code on asp-net(aspx) it doesn't works. We even tried by passing by the asp we are calling from vb6 (Another application that calls a web asp that is programmed on asp-net(aspx)) and we are passing the windows handler as a parameter, but when we call the function Call SetForegroundWindow(winWnd) it doesnt works.

Does anyone have any idea why it doesnt works for asp-net???

This is the code that works on VB

Dim Ret As Long
Dim winWnd As Long 'manejador de la ventana

Find the window
winWnd = FindWindo (vbNullString, "C:SoftphoneIntegra.htm - Microsoft Internet Explorer")
MsgBox "The windows id is: " & winWnd

If winWnd > 0 Then
call ShowWindow(winWnd, 3)

call SetForegroundWindow(winWnd)

Else
MsgBox "That app is not open."
End If

thanks.

GetForegroundWindow And SetForegroundWindow
This was first asked in the general section, but has turned into an API question, but the first thread is http://www.xtremevbtalk.com/t43148.html
The program pops up a borderless form (form2) whenever the NewTitle function is called (it is always called from form1). The problem I have, is that form2 steals focus from the last active window for 1.5 seconds. I am using msgboxs to show the hwnd returned at different points. When these boxes are used, it appears to work properly. However, when commented out, the program does not return focus until form2 is unloaded.

here is the NewTitle function:

Code:
Private Function NewTitle()
hwndLast = GetForegroundWindow
If lngWinamp <> 0 Then
Timer1.Interval = 65535
Sleep 30
strTitle = strWinampTitle
If Form2.Visible = True Then
Form2.Timer1.Enabled = False
Form2.Visible = False
Form2.Hide
End If
Form2.Show
Form2.Visible = True
Form2.Label1.Caption = strWinampTitle
Form2.Label1.Left = 0
Form2.Width = Form2.Label1.Width
Form2.Height = Form2.Label1.Height
Form2.Timer1.Enabled = True
Timer1.Interval = 3000
End If
End Function

And the form2 Load:

Code:
Private Sub Form_Load()
SetForegroundWindow hwndLast
MsgBox hwndLast
MsgBox GetForegroundWindow
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOMOVE Or SWP_NOSIZE
MsgBox GetForegroundWindow
End Sub

And hwndLast is a global variable as long.
I need to be able to return the cursor to where it was, any pointers?

SetWindowPos Vs SetForegroundWindow
Hi!

I've to make a window (a browser window) the window in the foreground. Depending on the options chosen when calling my function it stays always on top or not.

Code:
SetWindowPos lhWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
This is the line which is troubling me. The window is placed on top of the Z order but it doesn't stay there. In this special case I can't make it always on top.

Is there a difference between SetWindowPos and SetForegroundWindow? Or do I simply have to omit the SWP_NOACTIVATE part in order to let the selected window stay on top of the Z order?

The browser window that I'm talking about contains some Textboxes where the user has to authentificate himself to the system by entering his ID / pass. Our program is constantly checking if the user has logged on or not, thus bringing our application always in the foreground again, I suppose.

SetForegroundWindow Doesnt Always Become The Top Win..
Im having a bit of a trouble here trying to keep my form on top.. kind of a Locker program, to stop people from messing around with the pc.

But for some reason i can still get round from showing the task manager. I've even subclassed the form to see if it loses focus and then return it back to my application.

So the below code is on a timer, but although the Task Manager gets hidden, it still prints that IT has the focus... Unless i click back to my app..

Why doesnt SetForegroundWindow always work..??

Is there another API?


Code:

If SetForegroundWindow(me.hWnd) = 0 Then
Print "i dont have focus"

If FindWindow("#32770", "Windows Task Manager") <> 0 Then 'Task Manager
rtnValue = ShowWindow(FindWindow("#32770", "Windows Task Manager"), 0)
Print "inside tsk mngr find window"
rtnValue = SetForegroundWindow(me.hWnd)

End If
Else
Print "i have focus"
End If

SetForegroundWindow API Not Working
Hey, i know there have been a lot of posts on this topic but i can't seem to find the answer to this question. I have an excel spreadsheet with cells full of visio shapes. When a double click is made on a cell, the shape is found and set to blink in visio. However, i am having trouble getting the visio window to pop up infront of the excel window

I am using SetForegroundWindow API by calling this:
'g_ovAppVisio is the Visio Application object
SetForegroundWindow g_ovAppVisio.WindowHandle32

this however, only causes the visio window to flash 3 times in the task bar, and not pop up. What else do I need to do to make it pop up in front of the excel window? Thanks!

SetForegroundWindow Isn't Working When .vbp Is Made Into .exe
There seems to be a bug on this forum...I accidently type in SetForeGroundWindow, when i meant to type FindWindow (been using them both all day and its been a very long day) and when i try and edit the title, it doesnt change it.

Anyway FindWindow is the one im having problems with. Basically when I make the program into any exe it returns a value of 0, even though when i run it in the IDE it allways finds the window and returns a value.


And its bugging the hell out of me.

Does anyone have any idea why this might be happening...?

Many thanks

Nid Sample On API FindFirstChangeNotification & SetForegroundWindow
the FindFirstChangeNotification is an API to detect any changes on files/folder specified, i just need some sample codes

the SetForeGroundWindow also an API to automatically set focus on the specified form, i really need some sample codes


Please i really need some help....

ComboBox Not Visible After SetForegroundWindow
Greetings,

after opening a new window and calling the SetForegroundWindow comboboxes are not anymore visible.
There still there and if you click on them (as long you know where there are there getting visible again.

I would like if the objects are visible straight away

Many thanks in advance

SetForegroundWindow Alternative?&lt;Unresolved&gt;
Just went 2 days with no internet connection because it turned out my new neighbors broke into the cable-box and stole my cable signal...that has absolutely nothing to do with my question, I just gotta blow off some steam!

Now that it is out of my system, here is the question. In my application I have an icon in the systemtray. I am trying to make it so that if another application has focus, clicking on my icon will bring my application to the front. I tried some simple things like setting the Zorder and using frmMain.Show, that didn't work. Then I tried using the SetForegroundWindow API; what happens is the window flashes in the taskbar but the focus doesn't go to my application. I am using windows ME so that might possibly be the problem...is there another way to bring my application to the front?

Thanks


God Bless America

Edited by - IDontKnow on 8/14/2003 10:16:24 PM

(SetForegroundWindow+Tray Menu) PROBLEM!!!
Hey,

Around 2 weeks ago, i finally found a solution for the tray menu problem (where the user would like to cancel a tray menu of a VB app by clicking outside of it), and the solution to this problem was the 'SetForegroundWindow' API...


Now as a solution to that problem, this function worked well, and i marked the thread resolved.. But after further testing of my app, i found that the 'SetForegroundWindow' function was causing many undersired "side effects" !!!


In short description, the 'SetForegroundWindow' call is causing a FOCUS problem in the form to be displayed from the tray menu (Options or Help or About forms).. For example, these forms appear unfocused when i show them from the menu after a 'SetForegroundWindow' call, and the focus is then set on the main form (where the tray menu call was made from), which allows an "Alt+Tab" press to bring that main form (which is supposedly in hidden mode and in tray) into focus, something that i dont want to happen, especially cause it interferes with many other aspects of my program flow and logic...

I tried the SetFocus and Zorder functions in the form load or/and activate and/or other form events, but to no avail.. I also tried using all possible combinations of GetForegroundWindow, GetActiveWindow, SetActiveWindow, and SetForegroundWindow within my forms, but also it didnt work out.. Well, i didnt really know what i was doing there, was just experimenting with those API's, but nothing solved my problem.


So what i am asking for is one of those 2 options:


1) A way to be able to cancel the tray menu without using the 'SetForegroundWindow' API..

or

2) A solution to the described problem, which lets me use the 'SetForegroundWindow' API without the mentioned side effects...



THIS IS REALLY URGENT GUYS, ANY HELP WOULD BE APPRECIATED!!!


Thank you ...

*Resolved* Send Message To Screen (SetForegroundWindow API)
I am trying to send a message to the screen every so often. Here is the code I am using . . .


VB Code:
Option Explicit Private Declare Function GetCurrentProcessId _        Lib "kernel32" () As LongPrivate Declare Function SetProp _        Lib "user32" _        Alias "SetPropA" _        (ByVal hwnd As Long, _        ByVal lpString As String, _        ByVal hData As Long) As LongPrivate Declare Function GetProp _        Lib "user32" _        Alias "GetPropA" _        (ByVal hwnd As Long, _        ByVal lpString As String) As LongPrivate Declare Function AllowSetForegroundWindow _        Lib "user32.dll" _        (ByVal dwProcessId As Long) As LongPrivate Declare Function SetForegroundWindow _        Lib "user32" _        (ByVal hwnd As Long) As Long Dim hProcessID As LongConst ASFW_ANY = (-1) Private Sub Form_Load()     Me.Visible = False    Me.WindowState = vbMaximized        'SetProp Me.hwnd, "ProcessID", GetCurrentProcessId    'hProcessID = GetProp(Me.hwnd, "ProcessID")    'AllowSetForegroundWindow hProcessID    AllowSetForegroundWindow ASFW_ANY    tmrWait.Interval = 5000    tmrDisplay.Interval = 1000    End SubPrivate Sub tmrWait_Timer()        'this timer tells program how long to wait before next display    Me.Visible = True    SetForegroundWindow Me.hwnd    tmrWait.Enabled = False    tmrDisplay.Enabled = True    End SubPrivate Sub tmrDisplay_Timer()        'this timer tells form how long to display    Me.Visible = False    tmrDisplay.Enabled = False    tmrWait.Enabled = True End Sub


You can see from my commented lines that I tried it a couple of different ways. It thows the current form full screen to the front when in VB, but as soon I open any other window, it only flashes in the taskbar. I thought the allowsetforegroundwindow api would allow the window to move to front, but I can't get it to work.

Any ideas?

Copyright 2005-08 www.BigResource.com, All rights reserved