How To Tell If Program Got Focus From Other Program Or Within Itself
How do i know if the gotfocus routine was fired becuase the user clicked on a different program and then went back to the vb program or if the gotfocus routine got fired because the program called a different function and then calls back to the other function giving it focus this way? I hope that makes sense.
Thanks
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Get My Program In Top And In Focus When The User Starts The Program.
Hello. I have a problem I have not found any good solution to:
How do I get my program to be on top and in focus whenever it starts, no mater any other circumstances.
The program I'm designing is connected to a remote control. Hence it must be able to control the entire computer as the user like.
I've tried searching, but found no satisfactory solution.
Different Program Has Focus
How would I detect, say, Ctrl+F7, and act on it even if my program does not have any active windows? I'm assuming this is an API thing, but I could be wrong...
Jacob Sheehy
http://www.sheehy.ca
The more I C, the less I see.
What Program Has Focus?
I am using SendKeys() to send keys to a program when someone presses F5. I have got all the SendKeys() and F5 code done. The only problem is I have to find out whether the person has a certain program in focus or not?
I Want To Set My Program Away On Top With Never Focus It.
From my old topic about "How to make my own tooltips?(again)"
I will see "Call SetWindowPos(hwnd, -1, 0, 0, 0, 0, 3)" can make my program away on top but in sometime it may be get focus when use Form.Show.
With my target to make my own tooltips with make my Form to show as tooltips , It's must be never get focus for any case. How can I set It?
Program Focus
Is there a way that you can force someone to complete a program before they are able to launch any other window. I want to force a user to "LogIn" through a VB6 app before they can open any other application (eg, Word or Excel) on thier PC. Any ideas would be great. Thanks in advance!!!!!! Gene
How Do I Focus On A Program?
i'm checking to see if my application is already running with the following code:
VB Code:
'is app already running?If App.PrevInstance = True Then AppActivate "MyApp" Unload Me Exit SubEnd If
however, i would also like to set focus on the application, i.e. that the currently running program gets the focus.
how can i do this?
thanks!
w.
Which Program Has Focus?
Use the GetActiveWindow API function.
Code:
Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
What Program Has Focus?
Say I have word, excel, and Microsoft internet explorer running, how can i check to see which one has the focus?
Program Focus Problems And More
Im trying to create a macro program that will allow me to push a mouse button and have the program press a key on the keyboard. When the program is not in focus, the keypress events dont work anymore. I need to have the program monitor all key and button presses all the time no matter what program has focus. Also, i am having trouble simulating the button being held down. Is there a way to hold the mouse button down and have it simulate the holding of a keyboard key?
Thank you for you input, this means alot to me if someone can help.
How To Detect When The Program Gets The Focus?
I thought the Form_GotFocus would do this, but after testing it never ever fired at all. How can I detect when my program has just gotten the focus (as in when a user switched from another program to mine, or maximizes it)?
Thanks
Setting Focus To Another Program
VB 6.0 SP 5 , Windows NT4.0
We have an application written in Windev and one I am doing in Visual Basic.
At some point my visual basic program sets itself in front of the running windev program (using windowstate and setfocus of the form).
The problem is getting the focus back to the windev program after the user has clicked something on my vb progrem.
I have used minimized, hide my form...
This hides my form and shows the windev program again but it doesnt has the focus back(toolbar is grey not blue)
Is there anyway to set the focus to another running program (except using the sendkeys command?)
Thank you for your time
If this requires some API call's please write them out because I am totally new to API calls.
Set Focus To A Window (Not In Your Own Program)
Hello,
Does anyone know how to set the focus and maximize a window that does not belong to your project?
Example:
I need my program to bring forward and maximize the Internet Explorer window, now lets say I have 5 different windows open. I would need it to get the one that is named google.com.
Is there anyway to do this?
Thank you in advance!
Stilekid007
Close The Program That Has Focus
Does anyone know the code that will close the window that is selected.
Not close my program, but the one on top, such as Halo.
Thanks
paradoX
Polling Program With Focus
If I want to have a program in the background, that polls what other program having focus, when a timer event occur, how is this solved. I guess with some kind of API?
Giving Another Program Focus
Is there any way I can give a program other than my program focus?? Say explorer.exe or something like that?? If anyone knows how I would go about doing this please let me know.
Thanks in advance.
How Do I Know That My Program Has Lost Focus
Is there anyway I can come to know that my program has lost focus. ie... if some one clicks anywhere else other than my program, or minimizes it.
I can use ZOrder to keep my program on top, but situation demands that my program should not be terminated improperly using Task Manager and it would be performance degrading if I use ZOrder every 1 milliseconds
Is there anyway I can make my code perform if a user does an End Task on my program
Focus On Form (program)
How can I hold the focus on een Dos-box who is executed by a Shell call ?
I am opening a small program from my VB-program with Shell. During the executing of this program it may NEVER lost its focus, because the program then will stopped.
Any suggestions ?
------------------
Lost Focus The Program
Does anybody know how to receive event when the program loses the focus.I want to start the timer when a user minimize my program or change the focus to another.
Hitle
Bring External Program Into Focus?
Is it possible to bring an external program to the front that's either hidden,say behind an excel sheet or that has been minimised to the task bar?, if so how
Keep Focus On Active Program After SetWindowPos
I wrote software with a messagechecker in it. When a person is receiving a message from the projectdatabase, a popup in my software shows a form. I use the command:
Code:
Const Flags As Long = &H273
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
If bSetOnTop Then
Call SetWindowPos(Me.hWnd, -1, 0, 0, 0, 0, Flags)
Else
Call SetWindowPos(Me.hWnd, -2, 0, 0, 0, 0, Flags)
End If
When an user is using excel or something, he lose his focus. I don't want the user to lose his focus, because he could be selecting or typing something in another program. Its very irritating. I only can find how to place back the focus, but I hope you've got another solution.
Edit: Sorry, I posted this in General, API would be better I think...
Settign Focus To A Program Form
hey guys. is there a code to set focus on a fom for anways on top but have it so you can turn in on on an options form and then all forms in the program are always on top> I can make it so one form is always on top but when you move to another form it is deavtivated.
All help is appreciated.
Send Keys Without Program In Focus
Hi im making a program that would send keys to any application that isnt in frocus or is minimized and when i send the keys it will stay minimizen any help?
Do Something When A Form Loses Focus To Another Program?
I'd like for my program to do some things when the user goes away from it (Like clicks anywhere other than the form, like the desktop or Notepad or whatever), but I have no idea how to do it. I've tried to use Form_LostFocus but it didn't do anything. Right now I just have a Standard EXE project open with only the following code:
VB Code:
Private Sub Form_LostFocus()Me.Caption = "AAAAAHAHAHAHAHAHHAHAHA"End Sub
The form's caption doesn't change when I go away from it. This isn't really what I'm wanting it to do in the long run, but I just put it there to see if the LostFocus thing works. I'm eventually going to want it to call some functions instead.
Main Program Loses Focus..
hi again folks..
i really appreciate all the help you guys give me with this stuff..
i am learning..
anyway,... got my program running under windows xp, but when it starts the .exe file in the dos type window.. .the focus of the main program changes to that, which is fine.. but it will not refresh the main program screen and you cannot get at any of the controls on it..
here is what i use to run my exe after the main program is running with a shell command...
strPath = (progdir & " -game tfc" & " -port " & portnum & " +map " & mapuse)
x = Shell(strPath, vbNormalFocus)
so, the other exe opens now in a dos type window in windows xp and when i try and go back to the original window of the main program., it is all wiped out by the new program opening, and the controls cannot be seen or clicked on ...
any ideas ?
thanks,
Kevin Rea
krea@socal.rr.com
How Display Cursor When Program Has Not Focus?
How can I make the cursor in my RichTextBox control visible even though my program doesn't have the focus (I'm performing drag drop from word, and in my OLEDragOver function I want to be able to show the user where his drop would occur.)
If I give my program focus, word disappears (naturally)...
Try dragging something from word-word or word-wordpad or anyting else, you'll se the effect I want....
Would really appreciate help/suggestions/comments!!!
Keeping My Shelled Program In Focus
Hi
I am writting an application for an embeeded system which will eventually run under XP embedded with a touch screen and no keyboard. The main form is maximized and boarderless. I use ShellExecute to run Date And Time Properties found in the control panel.
code:ShellExecute Me.hwnd, vbNullString, "C:WINDOWSsystem32 imedate.cpl", vbNullString, "C:", 1
When I do this I have 2 problems
1. The Date And Time Properties window can loose focus and go behind the main form, and with no keyboard, there is no way to bring it back, and
2 The main form code that does the ShellExecute doesn't wait for the Date and Time Properties window to close before continuing.
Is there any way to resolve both of these issues?
thanks
kevin
Reading Key Presses Whilst Program Not In Focus.
What I want to do is to have my visual basic program to be running in the background while I am in another non-vb program, but for the VB program which I have written to be able to know when I have pressed a particular key and be able to act upon it, does anyone know how to do this, should I use an API call or what?
Thanks in advance for any replies Century
Enable The Caps Lock Key When Program Is In Focus....
How hard would it be to have the Caps Lock key turned on when my program has focus, then to disable it when my program loses focus? I use my program for my data entry job, and all data entered must be in CAPS. Thanks in advance
Edit:
I know i could just save use the Ucase() command to convert everything to CAPS before it gets sent to the server, but i'd like to avoid this if i can.
--Joey
How To Set Focus Based On A Program's Caption/process
Ok there's two ways I need help with either 1 or the other.
How to get a program to have it be in focus by the caption or the process name.
so once someone clicks a button, it trys to set in focus a certain program by the caption or the process name. I did some searching but couldn't find what I wanted so I am posting as a thread, thanks.
(VB6)Program Not Working (API Call) When Not Form Not In Focus?
I didn't know whether this was more of a Win32 API question, or General VB question... so... here goes...
This is the source code of my module:
Code:
Dim iPressed As Long
'In a module
Public Const WH_KEYBOARD = 2
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
ElseIf idHook = LastIdHook Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
ElseIf lParam < 0 Then
Form1.SetFocus
Form1.Cls
iPressed = iPressed + 1
Form1.Text1.Text = iPressed
Form1.Print "key pressed ..." & iPressed & vbCrLf & "wparam:" & wParam & " lparam:" & lParam & " idHook:" & idHook & " hHook:" & hHook;
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
LastIdHook = idHook
End If
End Function
And this is the source code of my form (Form1.frm)
Code:
Dim iPressed As Long
Private Sub Form_Load()
iPressed = 0
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx hHook
End Sub
I am guessing it has something to do with "hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)" and the Thread ID, though I'm not sure. All that I do know is that it does not register Keys pressed when the Form (Form1.frm) is not in focus. Is there any way to make this work while the Form is not in focus?
Thanks for your help.
Control Program When Minimize Window Or Lose Focus
Hi,
Perhaps this question is very simple, but I've started with VB a short time ago. I've made a program to comunicate with a mail server. It is necessary to stay continusly receiving information from the server. But when I minimize the window or when I open another program, my program stops! How can I control this?
Thank you,
Eider
How To Direct The Program Flow (focus) Form To Module
Hello All,
Apologies in advance for what may a simplistic question.
In Vb5, how would one direct the flow (is that the 'focus' of the program?) back to the module containing the sub Main section of code from a form which has been loaded and is visible, and has only 2 command buttons ?
In effect the command buttons are Quit, and continue.
Can the flow be directed back to a different line number than that which brought the form to the visible state - if so how, please?
Thanks in advance,
Tony
#"Set Focus On An Program On Button CLICK"# - Quick Help. With SendKeys Function.....
hey,
Well im using the Sendkeys functions and wat it does is it sendskeys to currently active window. What i want to do is make sure that keys are sent only to one window.
In short i want to set focus on a program when i click a button. I knw the program's process name. But the program's titlebar is not constant and keeps changing as it has a clock on it. SO any ideas hw to set focus on an application when I click a button?
Ive tried this
..... click()
form1.windowstate=vbMinimize
but that only minizes ///// hw to se focus on some other application?
thx in advannce
pls help
View Logged In To Program, Listen For Program Writing To Txt File.(PartialResolution)
Ok let me see if i can describe this quickly.
I am working with the Never Winter Nights tool set. We wanted to make a small program to monitor who logs on and off the server so we can display it on the web page.
NeverWinter Nights (NWN) when running the server version writes a complete logg to a txt file. What i am getting at is what is the Best/most effecient/ or easiest way to get this information.
Obviously the program writes to the text file every time something happens, we can see that happening. Is there a way to listen on the program for when it writes, then analyze the string and get the information that way.
I know I can write a quick program to read through the text file and analyze the log ins and offs and determine who is logged in that way. But there has to be a more efficient and much easier way of doing it.
Anyone have any suggestions?
Thanks in advance for all the help and ideas.
How Do Reach Controls Information From A Form Or Program To Pass Into Ourself Program
Can anybody help me please?????????
It make stuck when I need to code a form in the project which let me get information from other forms or programs.
e.g: I create a project ave only form1(It's always @top-level of the window environment) and I want to get information from other controls of the 3rd party program.
please, come on..., come on... help me!!!
thanks
Call Another Program And Obtain Status Code After Program Is Closed
Hi,
I have program A (visual basic exe with user interaction) and program B( visual basic exe with user interaction). At the present they are two independent programs.
Say for example program A performs 5 steps sequentially.
I would like program A to call prgram B after step 3 of 5.
After program B completes its own processing it should close and pass a status code (success or failure) to program A.
Based on the status code program A either continues with Step 4 and 5 or undoes step 1 to 3 and then closes.
(I hope I have not confused anyone with my general explanation).
My questions how would I go about doing this?
How can I call program B from program A and then accepts a status code from program B once it completes?
Thank you
Cosito7777
Problem: Starting A Program From Within A Program And Wait Till It Finishes
Hi,
I've the following problem: in the CreateProcessA codeline I got a typematch error.
The code is:
Code:
Private 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
Const SW_SHOWNORMAL = 1
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cdReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CreateProcessA Lib "kernel32" ( _
ByVal lpApplicationName As Long, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public strCmdLine As String
Sub Main()
intFileLog = FreeFile
strLogFile = App.Path & "Rel_Mens.log"
If Dir$(strLogFile) <> "" Then
Kill strLogFile
End If
Open strLogFile For Append As intFileLog
strLinha = Format(Now(), "d m yyyy hh:mm:ss") + " - Ini."
Print #intFileLog, strLinha
strIniFile = App.Path & "Acesso.ini"
strLinha = "strIniFile: " + strIniFile
Print #intFileLog, strLinha
Dim User As String
Dim Pass As String
Dim Database As String
Dim Source As String
Dim strConnect As String
Source = IniGet(strIniFile, "General", "Source")
Database = IniGet(strIniFile, "General", "Database")
User = IniGet(strIniFile, "General", "User")
Pass = IniGet(strIniFile, "General", "Pass")
strConnect = "Provider=SQLNCLI; " & _
"Data Source = " & Source & "; " & _
"Initial Catalog = " & Database & "; " & _
"User Id = " & User & "; " & _
"Password= " & Pass & ";"
Dim objConn As ADODB.Connection
Dim rstPedidos As ADODB.Recordset
Dim rstB As ADODB.Recordset
Dim strSQL As String
Dim strParams As String
Dim strData As String
Dim strDias As String
Dim strSQL2 As String
Dim strB As String
Dim intPos As Integer
Set objConn = New ADODB.Connection
objConn.Open strConnect
Set rstB = New ADODB.Recordset
strSQL = "SELECT distinct B FROM Perf WHERE Perfil='1'"
rstB.Open strSQL, objConn
rstB.MoveFirst
Do While Not rstB.EOF
strB = Trim(rstB!B)
Set rstPedidos = New ADODB.Recordset
strSQL2 = "SELECT Params FROM Pedidos WHERE B='" & strB
strSQL2 = strSQL2 + "' and Activo='S' and Obs='Solicitado'"
rstPedidos.Open strSQL2, objConn
If rstPedidos.RecordCount = 0 Then
strLinha = Format(Now(), "d m yyyy hh:mm:ss") + " - No records for B " + strB
Print #intFileLog, strLinha
Else
Do While Not rstPedidos.EOF
strParams = rstPedidos!Params
intPos = InStr(1, strParams, ";")
strData = Mid(strParams, 1, intPos - 1)
strDias = Mid(strParams, intPos + 1)
strLogFile2 = App.Path & "Reports.ini"
If Dir$(strLogFile2) <> "" Then
Kill strLogFile2
End If
intFileLog3 = FreeFile
strLogFile3 = App.Path & "Reports.model"
Open strLogFile3 For Input As intFileLog3
intFileLog2 = FreeFile
Open strLogFile2 For Append As intFileLog2
Do While Not EOF(intFileLog3)
strLinhaIn = ""
Line Input #intFileLog3, strLinhaIn
If InStr(strLinhaIn, "Data=") <> 0 Then
strLinhaOut = Trim(strLinhaIn) + strData
ElseIf InStr(strLinhaIn, "Dias") <> 0 Then
strLinhaOut = Trim(strLinhaIn) + strDias
Else
strLinhaOut = strLinhaIn
End If
Print #intFileLog2, strLinhaOut
Loop
Close intFileLog3
Close intFileLog2
strSQL2 = "UPDATE BES_PEDIDOS SET Obs='Fase1 (CSV)' WHERE B='" & strB
strSQL2 = strSQL2 + "' and substring(Params,1,8)='" & strData
strSQL2 = strSQL2 + "' and Activo='S' and Obs='Solicitado'"
objConn.Execute (strSQL2)
'Call Relat_Mens.exe
strCmdLine = App.Path & "Relat_Mens.exe"
ExecuteCommandA strCmdLine, True
rstPedidos.MoveNext
Loop
rstPedidos.Close
End If
rstB.MoveNext
Loop
rstB.Close
Close #intFileLog
objConn.Close
Set rstPedidos = Nothing
Set rstB = Nothing
Set objConn = Nothing
End Sub
Public Sub ExecuteCommandA(ByVal sCommandLine As String, Optional ByVal bWaitForObject As Boolean = False)
Dim tProcess As PROCESS_INFORMATION
Dim tStartUp As STARTUPINFO
Dim ret As Long
tStartUp.cb = Len(tStartUp)
ret = CreateProcessA(0&, sCommandLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, tStartUp, tProcess)
<<<error received here>>>>>
' Wait for the shelled application to finish:
ret = WaitForSingleObject(proc.hProcess, INFINITE)
ret = CloseHandle(proc.hProcess)
End Sub
Can anyone give me a help with this?
Thanks.
Cheers,
Paulo
Edited by - bespjl on 3/22/2007 4:53:43 AM
After Vb6 Install On Vista, Running The Vb6 App Starts A Setup Program For Another Program
This is a odd deal, i kinda remember it happening on a win2000 computer, and i've search on here to no avail.
What is happening is after I install my vb6 application on Vista business OS that was packaged on a windows 2000 professional OS it installs fine
but when I dbl click to start the application it fires off a setup program for autocad 2008 ( which was just installed on the vista OS)..... If i hit cancel
on the setup of this the vb6 application starts up and runs...
I'm thinking that it's somehow related to the setup program and how it stores it's temp files in some directory and somehow the OS is associating
the vb6 app.exe with the setup folder and the setup folder is used by "most" applications when they are installed... its quite confusing to me..
This ring a bell for anyone? I'm thinking of going to the package deployment and see what folders are used and see if i can change the dir names.. etc..
Thanks for any help here.!
Rob
Edited by - rburn2 on 4/20/2007 11:55:12 AM
Get A Handle To A Windows File Editor When Starting Program From Within Another Program
Hi,
I am trying to make a program that starts another program, and using sendkeyes to control what the new program is going to do and then close it. Basically the new program is going to open a db and store some data in a notepad file from the db.
I know how to start another program from within a program using shell, but
1) I do not want the new program to fill the screen like it does now. I know hat you can start the program and minimize it so the program icon shows at the bottom of the screen on the same line as the start button. But I would prefer the new program to not show. Can anyone help me with this ?
2) At one point in the process when using sendkeyes, the new program automatically opens/fetches a Windows list (where you can specify the name of the file and where it is going to be stored on your computer).
I need to find a way to get a grip on that windows list from my own program, so I can send a standard file name to it.
How can I do that?
Edited by - kolibri1 on 9/25/2003 1:33:40 PM
|