Results 1 to 11 of 11

Thread: TopMost too easy....

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    TopMost too easy....

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. 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
    2.  
    3. Private Const SWP_NOMOVE = 2
    4. Private Const SWP_NOSIZE = 1
    5. Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    6. Private Const HWND_TOPMOST = -1
    7. Private Const HWND_NOTOPMOST = -2
    8.  
    9. Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
    10.   On Error Goto ErrRtn
    11.    If (Topmost) Then
    12.       SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
    13.    Else
    14.       SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
    15.       SetTopMostWindow = False
    16.    End If
    17.    Exit Function
    18. ErrRtn:
    19. MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel
    20. End Function
    21.  
    22. 'In Form Load Event, put...
    23. 'To Make Always On Top
    24. SetTopMostWindow Me.hwnd, TRUE
    25. '(SetTopMostWindow Me.hwnd, FALSE would prevent window from being TopMost)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Hack, that is for making it 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

  4. #4
    Megatron
    Guest
    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.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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.
    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?

  6. #6
    Megatron
    Guest
    lol That's not considered a virus! I would consider it more of an annoying prank program.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352
    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

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Originally posted by Joey_k29
    My, I am way too sarcastic
    And I'm way too suspicious. My apologies. No offense intended.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    None taken...

    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

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Originally posted by Joey_k29
    As long as people are smart enough to follow directions, it should work.
    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.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Hmm....

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width