We help IT Professionals succeed at work.

Hwnd_TopMost(In  this Process)

MHorner
MHorner asked
on
I am trying to display a form that sits on top of all other forms in the application but sits behing any windows form other processes that the user might switch to. I want to load this for from a user control.

I currently have a work around using the follwing code but I looking for something a bit swisher.

Private Sub Timer1_Timer()

  Dim lngHandle As Long

  Timer1.Enabled = False
 
  lngHandle = GetActiveWindow
  If lngHandle <> mlngFormHWND Then
    If lngHandle = mlngParentHWND Then
      SetWindowPos moPlanner.hWnd, HWND_TOPMOST, _
        0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    Else
      SetWindowPos moPlanner.hWnd, HWND_BOTTOM, _
        0, 0, 0, 0, SWP_NOACTIVATE Or _
        SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    End If
  End If
  Timer1.Enabled = True

End Sub

Thanks

Martin
Comment
Watch Question

Commented:
Timer is OK.  Instead of timer, you can subclass a form in your application, and watch for the WM_ACTIVATEAPP message, see:

"Detect when the application gets or loses the input focus"
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=172

Inside your app, you can use Form_Activate event, but it is not fired when switching from other applications.

Author

Commented:
Thanks for that. I suspected that subclassing was the right answer but I was hoping for an alternative.

Commented:
C grade is insulting.  Even if my answer was only confirmation of what you were doing, it required high degree of knowledge and expertize!

I am rejecting C grade!
Experts work very hard to maintain good grade averages here at experts-exchange. More likely than not, they request that questions with grades less than A be deleted because many askers do not understand the grading policy. Askers also may not know that the grade given in no way affects the question points paid, but greatly affects the expert points received.
 
To avoid that, I've determined that, if someone is graded less than an A and does not give the reasoning behind it, other than "wishing" it were different than it it, I change the grade to an A.
 
Guidelines for giving grades can be found at http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
 
If, after reading that, you still think this question warrants a grade less than an A, feel free to let us know.
 
Changed grade to A...
 
Moondancer
Community Support Moderator @ Experts Exchange

Author

Commented:
I am guilty of not reading the guidelines. I marked the response as C for average or in other words what I would expect from an Expert.

I felt afterwards that I should have just found the vb2theMax page myself instead of bothering anyone here. But I did bother people here and I am happy to change it to an A if that is the policy.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.