Difference between revisions of "Floating tool windows"

From HashVB
Jump to: navigation, search
(test)
m (Reverted edit of 193.255.141.15, changed back to last version by Dee)
Line 18: Line 18:
  
 
Simple as that
 
Simple as that
<div style="overflow: auto; height: 1px;">
 
 
[_pw9_]
 
 
[http://nvnv2006.com/ nvnv]
 
 
 
</div>
 

Revision as of 13:16, 8 March 2006

float
 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