CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: window pop up

  1. #1
    Join Date
    Sep 2001
    Posts
    8

    window pop up

    Hi.

    I´m wrinting on a programm thats mostly working in the background, but on some events it shall pop up.
    I´m currently usiong the following code to do this:

    Form1.Visible = True
    Form1.SetFocus

    But sometimes the window only appears the back behind other windows.

    Does anyone know a solution?

    Thank you


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: window pop up

    The SetWindowPos API can do this for you

    ' This will bring your form to the front
    private 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_TOP = 0
    Const SWP_NOMOVE = &H2
    Const SWP_NOSIZE = &H1

    private Sub Command1_Click()

    SetWindowPos me.hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Sep 2001
    Posts
    8

    Re: window pop up

    Thanks for your answer.

    But the code doesnt seem to work!?
    The window still appears somewhere in the back.
    Are there any other functions i could try?


  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: window pop up

    Try changing HWND_TOP into HWND_TOPMOST,
    Also, change the line Const HWND_TOP = 0 into Const HWND_TOPMOST = -1

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  5. #5
    Join Date
    Sep 2001
    Posts
    8

    Re: window pop up

    Hi.

    SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
    works really good, but i´m not able to bring another window in front of my program. It always stay on the top.

    I tried the following code:
    SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
    SetWindowPos Me.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

    But it doesnt show any effect.

    When using this code:
    SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
    SetWindowPos Me.hwnd, 1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

    The program shortly appears on top and then hides behind other windows again.

    What i´m actually want to do is to let my pogram
    appear on top of all windows but one should still be able to bring other windows in front of it.

    Thank you


  6. #6
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: window pop up

    SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
    SetWindowPos Me.hwnd, -2, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  7. #7
    Join Date
    Aug 2000
    Location
    Namibia
    Posts
    139

    Re: window pop up

    Try setting forms zorder property. Much easier than the API and will fulfill the requirement.


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

Featured