Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

SetWindowPos

Hello,

I have a form that I allow the user toggle back and forth from being permanently on top (HWND_TOPMOST) to not being on top(HWND_NOTTOPMOST).

This is done using SetWindowPos, as you probably know.

Anyway I've notice a stange bug. When the form is in TOPMOST mode, the tooltips for my toolbar appear behind the form.

(I verified this by making the tip for the rightmost button long enough for it to stick out from behind the form.)

In not topmost or top(HWND_TOP) mode the tooltips work fine.

Anyway, if anybody has a fix or an idea about how to correct this, I'd appreciate it.

This does not seem to affect the tooltips for the other controls.

I tried changing the ZOrder for the control. It doesn't help.

Thanks,
WillP

0
WillP
Asked:
WillP
1 Solution
 
mcriderCommented:
Unfortunately, I don't think there's anything you can do about this using tooltips... Some controls just don't function properly with always-on-top windows. See the following Microsoft KB article:

PRB: Message Box Appears Behind Form Set as Top-Most Window
http://support.microsoft.com/support/kb/articles/Q178/4/01.ASP?LNG=ENG&SA=MSDN&FR=1 

You could make your own tool-tips for that control...

Cheers!
0
 
mcriderCommented:
You could also try to subclass the toolbar and intercept the windows message to display the tooltips.  Set the form to HWND_NOTTOPMOST when you get the messages to display the tooltips, and then set it back...

See the MS article:

HOWTO: Hook Into a Window's Messages Using AddressOf
http://support.microsoft.com/support/kb/articles/Q168/7/95.asp?LNG=ENG&SA=MSDN&FR=1 


Cheers!

0
 
wiremanCommented:
Perhaps consider a status bar, and putting your tips in there.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
WillPAuthor Commented:
I don't think these comments are going to work for my project.

mcider's comment is interesting, but it's seems likely to cause problems, as the user will have click on the toolbar buttons for most of his major operations.

wireman's comment is practical, but as it happens I already have a status bar with other imformation in it. And as my form is small, I'd rather not also include tooltips in it.

Thanks Everybody.

WillP
0
 
mbah022100System enigineerCommented:
On the side http://www.vbaccelerator.com/ you can find custom controls for toolbars, status bars etc. This includes the source of them. This allows you to change to tooltip routines so that when ever a tooltip is requested, it is possible to make the tooltip form also a HWND_TOP window. The last window set to this mode will be on the top of your screen. This will be some work for you, but I'am sure when you converted your code you'll be happy.
0
 
WillPAuthor Commented:
This all won't work for what I want, that is, simplicity. I decided to set the default to "not on top" and then allow the user to change it "on top" if he wants, thus losing the tooltips only when he chooses.
0
 
WillPAuthor Commented:
This question has a deletion request Pending
0
 
mcriderCommented:
This question no longer is pending deletion
0
 
mcriderCommented:
Why are you deleting this question?
0
 
WillPAuthor Commented:
It's simply a question of a too much coding for too little result. When I posted the question, I thought there might be a simple workaround, but apparently not. Do you want the points?
I'll give them to you. Really.

WillP
0
 
mcriderCommented:
Well, I thought that you might have found another solution...


Here's a solution to your problem by adding your own tooltip code... It's really easy.  Try this example:


1) Start a new project.

2) Add a picturebox to Form1 and call it "ToolTip", then set the following properties:

     Appearance = Flat
     AutoRedraw = True
     Visible = False

3) Add two command buttons to Form1 called "Command1" and Command2".

4) Add a timer control to the form called "Timer1".

5) Add the following code to the Declarations Section of form1.

'-------------------------------------------------------------------------------
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
   
    Private LastMouse As POINTAPI
    Private TipMsg As String
    Private TipTick As Integer
   
    Private Declare Function GetCursorPos _
        Lib "user32" (lpPoint As POINTAPI) As Long
   
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        TipMsg = ""
    End Sub
   
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        TipMsg = Command1.Tag
    End Sub
   
    Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        TipMsg = Command2.Tag
    End Sub
   
    Private Sub Form_Load()
        With ToolTip
            .Visible = False
            .BackColor = &H80000018
            .ForeColor = &H80000017
        End With
        Timer1.Interval = 100
        Timer1.Enabled = True
        Command1.Tag = "This is command button #1"
        Command2.Tag = "This is command button #2"
    End Sub
   
    Private Sub Timer1_Timer()
        Const TickExpire = 18
        Dim Mouse As POINTAPI
       
        GetCursorPos Mouse
        Mouse.Y = Mouse.Y * 15
        Mouse.X = Mouse.X * 15
        If (Not LastMouse.X = Mouse.X) Or (Not LastMouse.Y = Mouse.Y) Then
            LastMouse.X = Mouse.X
            LastMouse.Y = Mouse.Y
            ToolTip.Visible = False
            TipTick = 0
            Exit Sub
        End If
        With Me
            If Mouse.X < .Left Or Mouse.X > .Left + .Width _
                Or Mouse.Y < .Top Or Mouse.Y > .Top + .Height _
                Or TipMsg = "" Then
                ToolTip.Visible = False
                TipTick = 0
                Exit Sub
            End If
        End With
        TipTick = TipTick + 1
        If TipTick >= TickExpire Then
            With ToolTip
                If .Visible = False Then
                    .Top = Mouse.Y - Me.Top - 80
                    .Left = Mouse.X - Me.Left - 80
                    .Width = .TextWidth(TipMsg) + 60
                    .Height = .TextHeight(TipMsg) + 60
                    .Cls
                    ToolTip.Print TipMsg
                    .ZOrder
                    .Visible = True
                End If
                TipTick = TickExpire
            End With
        End If
    End Sub
'-------------------------------------------------------------------------------


Run the program, then hover over command1... a tooltip will be displayed! Move the mouse over command2 and hover... Another tooltip will be displayed! Since this example doesn't use the system's tooltiptext to display the tips, this will work on AlwaysOnTop forms...

All you have to do is set the TipMsg string in the mousemove event of the control you want to show the tip for, and the timer does the rest.


Cheers!®©

0
 
WillPAuthor Commented:
Adjusted points from 50 to 100
0
 
WillPAuthor Commented:
This is excellent. Oddly I've been working on a card game using pic boxes and GetCursorPos, but I never thought to use them in this way.

Thanks for taking the time,

WillP
0
 
mcriderCommented:
Thanks for the points! Glad I could help!

By the way, this way of doing tooltips *DOES* have an advantage over the systems's tooltips... You have have this tooltip display multiple lines in the tooltips.just by doing:

   TipMsg = "This is line 1" + VbCrLf + "This is line 2"

You can't do multi-line tooltips with the system's ToolTipText property. ;-)



Cheers!®©
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now