开发者

Clicking on NotifyIcon flips between 3 states (not 2)

开发者 https://www.devze.com 2023-03-14 08:22 出处:网络
I know this can be done... since I\'ve seen other vb.net executables do it. When I hit the program\'s NotifyIcon in the SystemTray... I thought I would only need to toggle between:

I know this can be done... since I've seen other vb.net executables do it.

When I hit the program's NotifyIcon in the SystemTray... I thought I would only need to toggle between:

1>  Show my form
2>  Hide my form

But I really need to flip between all 3:

1>  Show my form
2>  Hide my form
3>  If my form is visible... but behind other programs... 
    just bring it to the front.  

I can only seem to get #1 and #2 to work. How would I do all 3? (I do NOT want to make my form permanently "always on top".)

' Flip between #1 and #2
If (Me.Visible) Then
   Me.Hide()
Else
   Me.Show()
   Me.WindowState = FormWindowState.Normal  ' In case user minimized it earlier
   Me.Activate()   ' Active and give focus (brings to front, also)
End If

I can't really check for "is my form active"... because hitting the NotifyIcon causes that very mouse-click to MAKE all forms "not active".

Edit: I'm NOT really worried about other windows like "the start bar" or "always on top" windows... appearing over mine. (Since they will ALWAYS be over mine.)

I guess I really just need to detect: "Me.Show is true... and Me.Active is false". (But my NotifiIcon-click will ALWAYS make my form non-active... so how can I check for true/false???)

I really want it to just work t开发者_JS百科he way windows does: Clicking on anything in the task-bar does NOT just make it "open" (if closed)... and "close" (if opened). It always does 1 more thing:

Detect if it's already open, but behind other windows, so do NOT close it... but rather... make the window appear.

Checks for 3 different things. Does 3 different things. (Never just 2)


You may be able to get some use out of the GetNextWindow method. You can use it to see which windows are over top of your window. It won't be easy, but you can probably make it work.

To see which windows are above yours, use

Const GW_HWNDNEXT as Integer = 2 'Returns a handle to the window below the given window.
Const GW_HWNDPREV as Integer = 3 'Returns a handle to the window above the given window.

Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Integer, ByVal wFlag As Integer) As Integer 

hWndPrev = GetWindow(Me.Handle, GW_HWNDPREV)

Bear in mind that even when your window is the active window, there will probably still be some windows above yours, like the start bar and AlwaysOnTop windows. You'll need to detect these based on their class or position/size (whether they overlap your window).

Best of luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消