I’m very excited to show you my new tutorial about creating a custom hint in REALbasic. Our hint will be able to display everything we like, from pictures, text to charts, progressbars etc. Watch it, learn it, enjoy it!
Insert to Window1 a Listbox Control and lock it to left, right, top and bottom. At this point we must configure our Listbox so you can do this in Listbox Property panel or by add some code to Listbox1 Sub Open () in code editor. Of course if you like you can add more data to your Listbox (look on my example available on screenshot).
1 2 3 4 5 | ListBox1.ColumnCount = 2 ListBox1.ColumnWidths = "30% 70%" ListBox1.HasHeading = true ListBox1.Cell(ListBox1.LastIndex, 0 ) = "Firefox" ListBox1.Cell(ListBox1.LastIndex, 1 ) = "Make the switch to Firefox – the faster, safer, smarter way to browse the Web." |

To create a powerful custom hint we will use a Window Class so simply go to Project Tab and add a New Window called wHint. Add to it 2 StaticText Controls and if you like a Canvas Control. You can add here what you like. Now we must configure some wHint Properties. First change the Window size to 228×111, Frame to 3 – Floating Window, Composite and HasBackColor to true, BackColor to &cFDFF9D, MacProcID to 1 and ImplicitInstance to true. You should get something like this:

This part is very easy we simply go to code editor ListBox1 Sub MouseEnter () and display the wHint Window.
1 | wHint.Show |
And next we go to ListBox1 Sub MouseExit () and paste there:
1 | wHint.Close |
As you can see so far our wHint is only displaying when the cursor is on the Listbox control and closing when it isn’t. To make this more attractive and useful we will add to Listbox1 Sub MouseMove () a code that will tell our wHint to follow the cursor and display relevant data from our Listbox by cursor position.
1 2 3 4 5 6 7 8 9 10 11 | Dim row, column As Integer row = Listbox1.RowFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top) //get the row column = Listbox1.ColumnFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top) //get the column wHint.Top = System.MouseY + 18 //display the window 18 px in Y from the cursor wHint.Left = System.MouseX + 10 //display the window 10 px in X from the cursor wHint.StaticText1.Text = Listbox1.Cell(row, 0) //displaying the software name from cell 0 wHint.StaticText2.Text = Listbox1.Cell(row, 1) //displaying the description from cell 1 |
To make our hint even more cool we can make it transparent. Go to wHint code editor and in Event Handlers Sub Open () add:
1 2 3 | Declare Function SetWindowAlpha Lib "Carbon" (inWindow As WindowPtr, inAlpha As single) as integer call SetWindowAlpha(wHint, .87) // (name of window, percent of visibility) |
If you see this message you probably want access special material for Premium Members (Source Files, Bonus Tutorials, free Classes and More). You can do this by subscribing REALbasic City site for 10 USD (access for 3 months). There is also a option to buy access only to this material. Login or register to get option to buy and support REALbasic City.
Log in
Your first bit of code references Listbox2 instead of Listbox1…
This isn’t quite perfect on Windows (even without transparency) – the title bar is still on the window and it just doesn’t look quite right. But it’s a good start to get something going if I needed to do this! Thanks…
Thx for info Bill, I changed it to Listbox1 of course
I don’t know how this wold look on Windows but when you change the window type to Floating Window and set some properties to true you should get after the compilation a nice Floating Window without controls like bar, close button etc… May by on MS Windows you must experiment with some options
And one more thx for commenting
Floating window still has the title bar, but “plain box” works – and doesn’t have the flickering that the other window types have.
The only issue is that it goes behind the listbox window when you click. Adding a whint.close on mousedown fixes that though. It adds a little window flicker as things disappear and appear, but a little experimenting could surely fix that.
Wah… good kickoff!
As RowFromXY already gives you the row why muck around with the system position to calculate the row? You also get some problems when you enter the header or go below the last row. Better is:
Dim row, column As Integer
row = me.RowFromXY(x, y) //get the row
‘column = me.ColumnFromXY(x, y) //get the column
if row > -1 then
wHint.Top = System.MouseY + 18 //display the window 18 px in Y from the cursor
wHint.Left = System.MouseX + 10 //display the window 10 px in X from the cursor
wHint.StaticText1.Text = me.Cell(row, 0) //displaying the software name from cell 0
winHint.StaticText2.Text = me.Cell(row, 1) //displaying the description from cell 1
else
winHint.Close // close if it isn’t on a row
end if
However this does not work in the MouseWheel event – anyone knows what to do about MouseWheel?
Solved the MouseWheel by adding a property OldScrollPosition as integer to the listbox and doing this in MouseWheel
Dim row, column As Integer
// the following is necessary as deltaY is not zero when the scrolling
// reaches the top or the botom of the listbox
// by checking if the scrollposition has changed one can deal with it
if me.ScrollPosition OldScrollPosition then
row = me.RowFromXY(x, y + (me.RowHeight * deltaY) ) //get the row
else
row = me.RowFromXY(x, y) //get the row
end if
[...]
OldScrollPosition = me.ScrollPosition