Difference between revisions of "Floating tool windows"
m (Reverted edit of 193.255.141.15, changed back to last version by Dee) |
m (Reverted edit of 1146181331, changed back to last version by Dee) |
(One intermediate revision by one user not shown) | |
(No difference)
|
Latest revision as of 18:13, 28 April 2006
This article is based on Visual Basic 6. Find other Visual Basic 6 articles. |
There are several occasions where you may want a tool window to float above your app but not other apps without being a modal dialog. It is possible to go insane trying to come up with a workaround for this unless you know the proper way to do it. The way to do it is by setting the floating window's owner. What this means in real terms is that you just have to call SetWindowLong with the GWL_HWNDPARENT constant to change its owner (note: HWNDPARENT is a misnomer, as you are actually setting the window's owner, not its parent). The code is very simple and is as follows.
Declarations
The following API declarations are required:
Private Const GWL_HWNDPARENT = (-8) Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Setting the window's owner
This is just one line of code:
SetWindowLong myForm.hwnd, GWL_HWNDPARENT, Me.hwnd
Unsetting the window's owner
In order that your app doesn't crash, you have to unset the window's owner on exit, which is pretty much the same as setting the owner:
SetWindowLong myForm.hwnd, GWL_HWNDPARENT, 0
(Where myForm is the form that you wish to float above your app)
Simple as that