How can I make my window always staying behind all other apps? As the desktop does I mean.
Need answers soon
Printable View
How can I make my window always staying behind all other apps? As the desktop does I mean.
Need answers soon
ZOrder Method
Places a specified MDIForm, Form, or control at the front or back of the z-order within its graphical level. Doesn't supportnamed arguments.
Syntax
object.ZOrder 1
Nope, Im sorry...
I thought about a API call like SetWindowPos but I didnt find a parameter to set it always behind :(
Public Const HWND_BOTTOM = 1
Public Declare Function SetWindowPos Lib "user32.dll" _
(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
dim retval as long
retval = SetWindowPos(Form1.hWnd, HWND_BOTTOM, 0, 0, 1, 1, flags)
*hehe* already tried this ;)
Well, it puts the window behind all other... but after it gets the focus it's on top again. :(
But you know ie. the desktop is alwaysbehind...
Any other ideas?
I had to conduct a little testing for this, but alas, I was right :)
What you need to do is, find the handle to the desktop- not the field that holds the icons, but the one that contains the picture. Use the SetParent API call to make your window a child of that window. I don't know if this will do exactly what you wanted; when you make it a child it will no longer show up on the taskbar, but it is always on bottom!
ok, I'll try this.. thx!
I hope it also works when i dont have a desktop (Explorer.exe)... you should know I'm making an alternative shell...
That's the only reason I could think that you would want to do this. Just make sure you use the background window and no window directly associated with Explorer.exe. Goodluck, I hope it works.
Didn't work :( I tried both, 0 and GetDesktopWindow() as parent but nothing happened...
Anyway, thx for help
Anyone other an idea? Kedaman; Megatron, yer GURUs, help me out ;)
Hehe, sorry i was gone for a day, ok, well i see that didn't work, never tested my self anyway
And that's because most of the windows actully are parents to desktop and they have a zorder, well i'll try to think of something...
I'm pretty sure that the way this is done is explorer's desktop window (btw, this includes the icons area) sets all of the open top-level forms as children of itself. (i.e. if you open notepad, notepad becomes a child of explorer's desktop, not windows' desktop.)
Ok, so how can I replace the desktop window with my app?
I think my method might work as well, it wouldn't be a very effective if you made it a child window of explorer! Try changing you sys.ini file shell=progman.exe. This way you can still get around on your computer. THEN, find out what the handle is that holds the background image and make your app a child of it. You can find what its handle is by using WindowFromPoint or something like that.
not what i meant. once you're rid of explorer, make a maximized form with no titlebar. this is the new desktop. make all the open windows children of your form. this is how explorer does it (i think) except it also has a listview where the icons are.
Phobic
We all know that the hWnd you mean is 0
agent
Ok, that's a good idea! I'll try that, thx!
Same problem will probably return when:
You launch an application,
you could probably set it as a child but you would have to do this in a loop since other applications also could launch apps, and they will get under your desktop if you don't handle them.
So you won't get rid of the "loop" you wanted to.
Well I hope there is a way anyway ;)
BEWARE, for I have neglected to warn of one danger with my method: do not set a higher up window (a window that is a parent or a parent's parent... of yours) as a child. Windows doesn't try to prevent it and it will crash without an error message.
About the previous message; instead of looping, other forms will only go under yours if your form becomes activated (gets focus). Just check for new windows in the paint event, or better yet, subclass the gotfocus event (the vb version doesn't always work) and check for windows every time your window gets focus.
[Edited by agent on 07-05-2000 at 03:32 AM]
ok, well...
I tried something like this:
SetParent Shell("C:\Win98\Calc.exe"), Me.hWnd
well, when I selected my window again the calc was behind it :(
So how does the Explorer do that? Does it install a hook to catch new apps and make them children of itselves or does it really use a loop? (I don't hope so ;))
you'll need to get the window's handle. findwindow(vbnullstring,"Calc")
Like kedaman said: What when a program opens another app? I wouldn't know the caption or hWND :( I need another way... sorry
Code:'Add this into your module
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
Global Const conHwndTopmost = -1
Global Const conHwndNoTopmost = -2
Global Const conSwpNoActivate = &H10
Global Const conSwpShowWindow = &H40
'Ontop
SetWindowPos hwnd, conHwndTopmost, 100, 100, 205, 141, conSwpNoActivate Or conSwpShowWindow
'NotOntop
SetWindowPos hwnd, conHwndNoTopmost, 100, 100, 205, 141, conSwpNoActivate Or conSwpShowWindow
I'm so sorry Matthew, but that's absolutely not what I was looking for ;) But if you know a solution... I need code to make a window always stay behind like the desktop does.
Just a suggestion...
Wouldn't it be cooler showing the "desktop" just by clicking it?
Also, if you have an API function to send it to the back, use it in the _GotFocus event.
Bye,
-Jotaf98
"Cyberspace forever"
[email protected] - ICQ#60784495 - http://jotaf98.cjb.net
I also thought about menus coming when you move the mouse to a side, but that would also require a loop... well, for the first time I want to nearly copy the windows desktop. I like this system with the icons, even I have many improvements ;)
Thanks for the tip, i'll try that with GotFocus. I think it won't work or at least flicker, but it's worth giving it a try. :)
Code:'How to set a form as bottom of the order and keep it there
'using subClassing
'
'I didn't write this it was handed over to me..I tried it out
'and it does seem to do the trick..however you must end it by
'using dblClick on form..if you use the stop key in VB it will
'crash....so it must be unloaded via code
'bas module code
Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public 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
Public 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
Public Const GWL_WNDPROC = (-4)
Public Const WM_PAINT = &HF
Public Const WM_ACTIVATE = &H6
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_BOTTOM = 1
Public winProc As Long
Public Function WindowProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lFlags As Long
lFlags = SWP_NOSIZE Or SWP_NOMOVE
Select Case wMsg
Case WM_ACTIVATE
SetWindowPos hwnd, HWND_BOTTOM, 0, 0, 0, 0, lFlags
Case Else
WindowProc = CallWindowProc(winProc, hwnd, wMsg, wParam, lParam)
Exit Function
End Select
End Function
Public Sub SubClass(hwnd As Long)
On Error Resume Next
winProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnSubClass(hwnd As Long)
If winProc Then
SetWindowLong hwnd, GWL_WNDPROC, winProc
winProc = 0
End If
End Sub
'Form Event Code
Private Sub Form_Activate()
Me.ClipControls = False
Me.BorderStyle = 0
Me.Caption = ""
Me.Refresh
End Sub
Private Sub Form_DblClick()
UnSubClass Me.hwnd
Unload Me
End Sub
Private Sub Form_Load()
SubClass Me.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubClass Me.hwnd
End Sub
Another program:Code:'Your program
Public Const HWND_BOTTOM = 1
Public Declare Function SetWindowPos Lib "user32.dll" _
(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
Private Sub Timer1_Timer()
Dim retval as long
retval = SetWindowPos(Me.hWnd, HWND_BOTTOM, 0, 0, 1, 1, flags)
End Sub
Code:Public Const HWND_BOTTOM = 1
Public Declare Function SetWindowPos Lib "user32.dll" _
(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
Declare Function findwindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Timer1_Timer()
Dim thewindow As Long, retval As Long
thewindow = findwindow(vbNullString, "Form1")
retval = SetWindowPos(thewindow, HWND_BOTTOM, 0, 0, 1, 1, Flags)
End Sub
HeSaidJoe
Thanks a million! That's what I needed! Yeah!