Go Back   Tech Support Forum > The IT Pro > Programming

Stop A Program From Losing Focus

This is a discussion on Stop A Program From Losing Focus within the Programming forums, part of the Tech Support Forum category. I have a problem with my computer losing focus on a certain screen. So im trying make in program that


Reply
 
Thread Tools Search this Thread
Old 03-05-2012, 12:21 PM   #1
Registered Member
 
Join Date: Nov 2011
Posts: 83
OS: xp



I have a problem with my computer losing focus on a certain screen. So im trying make in program that always running, in if the SCREEN lose focus an a program will bring it back up automatic. Are prevent it fom losong focus.

Thanks

__________________
Focus2 is offline   Reply With Quote
Old 03-05-2012, 04:25 PM   #2
Games Team | Tech
 
Special2God's Avatar
 
Join Date: Oct 2009
Location: Earth
Posts: 4,451
OS: Win 7 (x64)

My System


First question, what language are you trying to program this in?
What OS are you working with?
You can google "Windows keep window focus" for various answers in C#, C++, etc...

Open task manager (right click on taskbar > task manager), go to options and select "always on top", watch the resulting behavior of the task manager window, is that the result you want?

__________________
Special2God is offline   Reply With Quote
Old 03-05-2012, 06:05 PM   #3
Registered Member
 
Join Date: Nov 2011
Posts: 83
OS: xp



I working with vb, in I looking for something simple.
__________________
Focus2 is offline   Reply With Quote
Old 03-05-2012, 06:56 PM   #4
Games Team | Tech
 
Special2God's Avatar
 
Join Date: Oct 2009
Location: Earth
Posts: 4,451
OS: Win 7 (x64)

My System


Try reading this microsoft page about creating forms that are always on top of other windows.
__________________
Special2God is offline   Reply With Quote
Old 03-07-2012, 10:12 AM   #5
Registered Member
 
Join Date: Nov 2011
Posts: 83
OS: xp



Thanks, but I couldnt get it to work. I have two program that will be running at the same time. But for some reason, the program thats minimize keep pop over the program thats needs to always be on display.

I have in code below, can some help me, on what Im doing wrong to focus on a process in task manager. In order for the program can stay in display.

PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim objWMIService, colProcesses
Dim Process AsString
 
Process =
"OUTLOOK.exe"
If Process = "OUTLOOK.exe"Then
Process = Focus()
' MessageBox.Show("test")
Else
EndIf
objWMIService = GetObject("winmgmts:")
colProcesses = objWMIService.ExecQuery(
"Select * from Win32_Process where name='" & Process & "'")
If colProcesses.Count Then
colProcesses = vbMaximizedFocus
MsgBox(
"Process is Running")
Else
MsgBox("Process is Not Running")
EndIf
If Process = "OUTLOOK.EXE"Then
EndIf
EndSub
End
Class
__________________
Focus2 is offline   Reply With Quote
Old 03-07-2012, 03:39 PM   #6
Games Team | Tech
 
Special2God's Avatar
 
Join Date: Oct 2009
Location: Earth
Posts: 4,451
OS: Win 7 (x64)

My System


Since I'm not familiar with VB, I would recommend following the "step-by-step example" in the "more information" section of the link I posted and setup a new project and copy-paste the example code into the new project.

Get an exact working copy of the example code in the new project and then try to copy the necessary parts of the example into your project.
__________________
Special2God is offline   Reply With Quote
Old 03-11-2012, 08:47 PM   #7
Registered Member
 
Join Date: Jan 2012
Location: United States
Posts: 6
OS: XP, Vista, Win7



Here is an example for you in C# it should be easy enough to convert to VB.Net:
pinvoke.net: SetForegroundWindow (user32)
__________________
TLF_KoBE is offline   Reply With Quote
Old 03-12-2012, 07:57 AM   #8
Registered Member
 
Join Date: Nov 2011
Posts: 83
OS: xp



Thanks for you help everyone, But i have finally figure it out. Such a small code, but it gets the job done. Im posting the code, just in case someone may need it oneday..

Happy Coding


PublicClassForm1
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
EndSub
PrivateDeclareFunction FindWindow Lib"user32"Alias"FindWindowA" (ByVal lpClassName AsString, ByVal lpWindowName AsString) AsLong
PrivateDeclareFunction ShowWindow Lib"user32" (ByVal hwnd AsLong, ByVal nCmdShow AsLong) AsLong
PrivateConst SW_SHOWNORMAL = 1
PrivateConst SW_SHOWMINIMIZED = 2
PrivateConst SW_SHOWMAXIMIZED = 3
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = False
EndSub
PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Format(TimeOfDay,
"h:mm:ss tt")
AppActivate(
"Today Test.txt")
EndSub
PrivateSub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled =
True
EndSub
End
Class
__________________
Focus2 is offline   Reply With Quote
Old 03-12-2012, 03:41 PM   #9
Games Team | Tech
 
Special2God's Avatar
 
Join Date: Oct 2009
Location: Earth
Posts: 4,451
OS: Win 7 (x64)

My System


Thanks for telling us Focus2, glad you were able to solve the problem.
Happy coding

__________________
Special2God is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Removing the screw inserts from the holes used to hold the CPU cooler in pla
I want to remove the screw inserts from the holes in the motherboard that are used to hold the CPU cooler in place. Somehow someone got them in there, and I need them to come out so I can install a staked-in model that doesn't suck. If this involves removing the motherboard I'll hate you. JK but...
dm01 Cases and Cooling 14 06-27-2012 09:02 AM
suddenly my backspace,t,y, shift, and tab keys stop w
i have read several people having this exact same combination of keys not working , so i don't think it is just a key board issue. i believe i typed something to all of a sudden de-activate these keys. the don't start getting sticky, the just stop working all a once completely.
esoesbasura Windows XP Support 3 03-06-2012 03:08 AM
Changing careers from business to software eng/dev because of dress code aversion
I graduated almost a year ago with a degree in Industrial Engineering. Since then Iíve had a job that requires a business casual dress code (no surprise with my degree). Since my childhood Iíve had a severe subconscious aversion/anxiety disorder with formal clothing fabrics, buttons and...
tripleCitizen Certification & Career 9 03-05-2012 08:33 PM
Cleaned Dust From PC. Now Won't Start.
Hi this is my first time posting and I'm not sure where to put this but I think it's mobo related. So today I opened up my gaming PC to clean the massive amount of dust in it. I used an air compressor and after I put the sides back on and turned it on there is no single to the display!! I tried...
IcyCold44 Motherboards, Bios & CPU 1 03-05-2012 04:33 AM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2


All times are GMT -7. The time now is 12:30 PM.


Copyright 2001 - 2014, Tech Support Forum

Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts