Click to See Complete Forum and Search --> : How to make a window float over my app
Wuzel
Oct 22nd, 2000, 05:27 AM
Hi!
I want to have some windows floating over my application, like toolwindows. They should not be visible outside of my app!
I did some experiments with SetWindowPos but it only sets those windows systemtop so I see them in every other appliction too. If I set them Hwnd:NoTopMost, the float only until another form gets the focus.
I got a SDI App.
Thanks
Wuzel
kedaman
Oct 22nd, 2000, 07:03 AM
I think what you need is to subclass your app for Killfocus and setfocus events, so that you know when to hide and show the toolbox.
Paste this into a module:
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal ndx As Long, ByVal newValue As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const HWND_TOPMOST = -1
Const GWL_WNDPROC = -4
Public Const WM_KILLFOCUS = &H8
Public Const WM_SETFOCUS = &H7
Private saveHWnd As Long
Private oldProcAddr As Long
Public killed As Boolean
Sub startsubclassing(ByVal hwnd As Long)
saveHWnd = hwnd
oldProcAddr = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Sub stopsubclassing()
SetWindowLong saveHWnd, GWL_WNDPROC, oldProcAddr
End Sub
Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim temp As Long, n As Form
WndProc = CallWindowProc(oldProcAddr, hwnd, uMsg, wParam, lParam)
Select Case uMsg
Case WM_KILLFOCUS:
temp = GetForegroundWindow
For Each n In Forms
If n.hwnd = temp Then temp = 0: Exit For
Next n
If temp Then frmtools.Hide: killed = True
Case WM_SETFOCUS
temp = GetForegroundWindow
For Each n In Forms
If n.hwnd = temp Then If n.hwnd <> saveHWnd Then temp = 0: Exit For
Next n
If temp And killed Then frmtools.Show: killed = False
End Select
End Function
In the main form put these in the events, form load and unload:
Private Sub Form_Load()
frmtools.Show
startsubclassing hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
stopsubclassing
End Sub
And in the toolbox activate event:
Private Sub Form_Activate()
SetWindowPos hwnd, -1, 0, 0, 0, 0, 3
If Form1.WindowState = vbMinimized Then
Me.Hide
killed = True
End If
End Sub
the last one is for not leaving the toolbox there if user minimizes the main form.
Good luck!
Wuzel
Oct 22nd, 2000, 08:59 AM
Originally posted by kedaman
Thanks Kedaman!
Thats allready very near to what I want to have!
The only thing that bothers me is that while my app is running (and not minimized) then all other application to which I'm ALT-Tabbing have the frmtools in front of them.
I want the toolbox to be on top of myapp only, to hide while I',m doing other things and to reappear when I come back to myapp.
THANK you very much!
Wuzel
kedaman
Oct 22nd, 2000, 01:16 PM
Alt-Tab you say, that should also hide the toolbox..
Wuzel
Oct 22nd, 2000, 01:16 PM
Thank you for writing the code fpr me!
There are some things that I don't understand:
How do I prevent the frmtools form to be displayed in the taskbar
How to do this for multiple toolwins
and how can I prevent the toolwin to be shown when an other app has the focus.
I'm very sorry, I spent about 2 hours trying to figure out your code, when I try to set breakpoints and more it likely crushes my vb6 developer.
So I write here in the hope youre going to spend more of your time to help me
;( not very pleased to say I'm too stupid, but ...
Thank you
Wuzel
kedaman
Oct 22nd, 2000, 01:28 PM
ACtually what my code does is hiding the toolbox if it's focus is lost.
That event isn't included in vb, so i'm subclassing for WM_Killfocus. Also when the app gets focus again, it shows all the toolboxes again.
I've noticed if you press alt-tab, and then go back and press alt-tab until some window comes between the toolbox and the form, then it won't hide the toolbox.
The problem seems to be that the toolbox is shown in the taskbar, as you mentioned, set the toolbox showintaskbar property to false
I'm so sorry that i forgot to tell you but subclassing is a bit dangerous, you can't put breakpoints neither end the app, without a crash.
If you need a breakpoint or really need to end the app, goto immediate window and type stopsubclassing, or for breakpoints type:
Stopsubclassing
Stop
Now to have multiple toolbars, you just need to add the toolbars, add the active event to each of them.
Then hide all tooboxes and show alltoolboxes at respective places i've put toolbox.hide and toolbox.show
Hope this helps!
Wuzel
Nov 11th, 2000, 01:18 PM
Originally posted by kedaman
ACtually what my code does is hiding the toolbox if it's focus is lost.
Hi kedaman!
Actually your code does hide the forms bur only if i fetch a window from behind, by clicking on it.
If I reactivate a program from the toolbar, my toolwin stays on top.
Are there any other messages I am missing?
Thank
you
Wuzel
kedaman
Nov 11th, 2000, 04:15 PM
Hmm, that's really odd, i noticed there's a bug in windows, when the main form isn't overlapped by the click on another window in taskbar, it still has the active titlebar color, you actually have to paint it away by moving another window over it.
Well anyway i found a solution to this, you subclass both forms:
Private Sub Form_Load()
frmtools.Show
startsubclassing hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
stopsubclassing hwnd
End Sub
You notice you pass the window handle this time in stopsubclassing, which means the module knows what window is supposed to stop subclassing. So you change it:
Sub stopsubclassing(hwnd)
SetWindowLong hWnd, GWL_WNDPROC, oldProcAddr
End Sub
that should do it :)
Wuzel
Nov 12th, 2000, 03:41 AM
Originally posted by kedaman
Hmm, that's really odd, ...
Hi Kedaman!
I'm sorry, something is behaving very strange!
I implemented your code, here is what it does to my nerves ;)
Although the projekt works fine some of the time, there are situations I want you to see:
I write it as a step by step so you can reproduce the effects
1.
minimize the mainform
(it now shows in taskbar, frmtools ist hidden from taskbar)
click on it in the tastbar
both windows reappear, both having focus(!)-coloured window-titles
here sometimes after a few seconds the area around the toolbox (top right corner)
of the mainform grays, the rest odf the titlebar stays in 'focus' color.
now click on the application behind our project, maybe your browser
the frmtools stays in front (ontop) greyed titlebar
click again at the taskbar
form1 comes up again now havin the focus
click on the application behind, now sometimes our project behaves correctly and vanishes,
sometimes you have to repeat the last 2 steps
2.
tooltips of the frmtools seem to appear behind the frmtools window :)
3.
put project in taskbar
click on it in the taskbar
click on any other app in the taskbar
frmtools stays in front
click on the project again, mainform reappears wiht focus
click on any other app in the taskbar
frmtools stays in front
and so on, you will never get frmtool to disappear.
I'm very sorry to bother you with this problem to that extend.
But I'm really trying to figure out how to build simple toolwindows with VB6.
It seems to me VB ist not quite ready for that :(
Thank you
Wuzel
kedaman
Nov 12th, 2000, 09:04 AM
Exactly Exactly Exactly! Windows is behaving really strange, it should not leave the other window with focus, and it looks like both windows have.
But i guess you didn't subclass both forms, did you? Because now it works just perfectly for, me, i tried anything and the toolwindow never ever does that.
If you want i could send you the whole project and you see what i mean. ;)
Wuzel
Nov 12th, 2000, 10:53 AM
Originally posted by kedaman
If you want i could send you the whole project and you see what i mean. ;)
Hi Kedaman!
Yeah please send it to me, maybe I'm doing something wrong!
Thank you very much
Wuzel :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.