Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SetWindowPos

Posted on 2000-02-26
14
639 Views
Last Modified: 2008-02-01
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
Comment
Question by:WillP
14 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2560768
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2560784
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
 

Expert Comment

by:wireman
ID: 2585396
Perhaps consider a status bar, and putting your tips in there.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:WillP
ID: 2588255
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
 

Expert Comment

by:mbah022100
ID: 2615226
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
 

Author Comment

by:WillP
ID: 2752583
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
 

Author Comment

by:WillP
ID: 2752584
This question has a deletion request Pending
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2757344
This question no longer is pending deletion
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2757345
Why are you deleting this question?
0
 

Author Comment

by:WillP
ID: 2758134
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
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2761291
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
 

Author Comment

by:WillP
ID: 2761658
Adjusted points from 50 to 100
0
 

Author Comment

by:WillP
ID: 2761659
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2762876
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question