I have the code to make a window the topmost window(meaning it is visible at all times even if another app is active). Is there a way to keep your form the active form constantly without using a timer? Thank you very much for your help.
Joe
Printable View
I have the code to make a window the topmost window(meaning it is visible at all times even if another app is active). Is there a way to keep your form the active form constantly without using a timer? Thank you very much for your help.
Joe
VB Code:
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Const SWP_NOMOVE = 2 Private Const SWP_NOSIZE = 1 Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Private Const HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long On Error Goto ErrRtn If (Topmost) Then SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS) Else SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS) SetTopMostWindow = False End If Exit Function ErrRtn: MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel End Function 'In Form Load Event, put... 'To Make Always On Top SetTopMostWindow Me.hwnd, TRUE '(SetTopMostWindow Me.hwnd, FALSE would prevent window from being TopMost)
That code makes it the topmost, it does not keep it active. It just means it is over the top of everything else. I need code that makes my active at all times(you cannot click on any other program). Thank you for your time.
Joe
I'm sure there's a better way, but you could subclass your window, and catch the WM_KILLFOCUS event. Then use the SetForegroundWindow or SetActiveWindow API to make it active.
I don't like the sound of this Joey_k29. It sounds like you are attempting to take over control of the entire desktop with your application. That reeks of virus. What you are trying to accomplish?Quote:
Orginally posted by Joey_k29
That code makes it the topmost, it does not keep it active. It just means it is over the top of everything else. I need code that makes my active at all times(you cannot click on any other program). Thank you for your time.
lol :) That's not considered a virus! I would consider it more of an annoying prank program.
Some people would go as far to say that it is a means of keeping the user from interfering with a macro. My diabolical plan revealed. Yes, I am attempting to rid the world of user error. Please turn me in to the feds immediately. While you are at it, I will ask about a key tracking program. Sure it may appear logical to link that together and think "Hey, maybe he is making a macro program that goes along this non-user intervention crazy idea," but good old human nature will tell you better. Yep, he is creating the world's most deadly virus. My, I am way too sarcastic :) .
Thanks for the help, but at this point I am actually favoring just keeping a window topmost.
Joe
And I'm way too suspicious. My apologies. No offense intended.Quote:
Originally posted by Joey_k29
My, I am way too sarcastic
Actually, now that you mentioned it, it really isn't that difficult to do what you said even without using megatron's code. Blocking the user would not require that you keep it constantly active. Oh well, my macro actually has some advantages to keeping only the foreground window. As long as people are smart enough to follow directions, it should work.
Joe
Do you have any openings in your company? I wanna work where you do, 'cause if I left up to my users to follow directions, everybody would be a world of hurt. :DQuote:
Originally posted by Joey_k29
As long as people are smart enough to follow directions, it should work.
Like every IT department, we are under-staffed. I am 18 and get paid $8. Under-payed, under-staffed, and I still manage to implement automation techniques. So in answer to your question, there are never any openings, haha.