Results 1 to 28 of 28

Thread: Not AlwaysOnTop? [urgent]

  1. #1

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    How can I make my window always staying behind all other apps? As the desktop does I mean.

    Need answers soon

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    not sure if this is the answer but it's a thing to check out

    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

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Nope, Im sorry...

    I thought about a API call like SetWindowPos but I didnt find a parameter to set it always behind

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    I personally haven't tried this...

    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)
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    *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...

  6. #6

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Any other ideas?

  7. #7
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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!


  8. #8

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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...

  9. #9
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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.

  10. #10

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Unhappy

    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...
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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.)

  13. #13

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Ok, so how can I replace the desktop window with my app?

  14. #14
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    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.

  15. #15
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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.

  16. #16

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Phobic
    We all know that the hWnd you mean is 0

    agent
    Ok, that's a good idea! I'll try that, thx!

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  18. #18
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    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]

  19. #19

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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 )

  20. #20
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    you'll need to get the window's handle. findwindow(vbnullstring,"Calc")

  21. #21

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Like kedaman said: What when a program opens another app? I wouldn't know the caption or hWND I need another way... sorry

  22. #22
    Guest
    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

  23. #23

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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.

  24. #24
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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

  25. #25

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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.

  26. #26
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>...maybe this is what you've already tried...maybe not...

    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  27. #27
    Guest
    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
    Another program:
    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

  28. #28

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Smile

    HeSaidJoe

    Thanks a million! That's what I needed! Yeah!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width