Which API I need to make my software appears in front of other started software in user desktop?

Posted on 2011-10-26
Last Modified: 2012-05-12
  Hi experts!

I have a complicate software system which is actually of 6 different separated programs running in same time. I want to implement functionality when user click on Control Center all of my modules to goes in front of screen. Sometimes user start other program and is not comfortable to click on task bar to restore all of my started modules. I hope I ‘m clear what I need .

In a sentence – I need a VB6 code which to put my program in front of desktop of user. To use all the time SetTopMOST is not a option. May be to set up and then to remove topmost and software will stay at first position? Which command I need ?
Question by:dvplayltd
    LVL 14

    Accepted Solution

    Put this in your Declarations section:

    Public Enum SetWindowPosFlagsEnum
       SWP_HIDEWINDOW = &H80
       SWP_NOACTIVATE = &H10
       SWP_NOCOPYBITS = &H100
       SWP_NOMOVE = &H2
       SWP_NOREDRAW = &H8
       SWP_NOSIZE = &H1
       SWP_NOZORDER = &H4
       SWP_SHOWWINDOW = &H40
    End Enum

    Public Enum WndInsertAfterEnum
       HWND_BOTTOM = 1
       HWND_DESKTOP = 0
       HWND_NOTOPMOST = -2
       HWND_TOP = 0
       HWND_TOPMOST = -1
    End Enum

    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As WndInsertAfterEnum, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As SetWindowPosFlagsEnum) As Long

    Then, this code, executed once will put the window on top, but then allow others to appear on top of it later. That is what you want as I understand your question:

    SetWindowPos Form1.hwnd, -1, 0, 0, 0, 0, 3
    SetWindowPos Form1.hwnd, -2, 0, 0, 0, 0, 3

    Author Comment

    I’m not sure I need exactly this, but will test does it work tomorrow. I’ in Europe based, now is 1 a.m in the morning.

    My concert is not in start. IN start – as this is new programs it appears on top. My ask is later, once all my software modules are started.

    Well, may be if I put it on topmost they will appears before other programs (if have such), but then I should remove topmost properties, may be this will work.

    Author Comment

    It is Ok - it work. Due to your offer I write a function:

    Public Sub SetPopup(ByVal frmHwnd As Long, Optional ByVal bRemove As Boolean = False)
      If bRemove Then
        Call SetWindowPos(frmHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE)
      End If
    End Sub

    when I call it like this it work as I need:

     SetPopup Me.hwnd
     SetPopup Me.hwnd, True

    this make form on top of all, and after that user can put other on his top.

    Thank you!

    Author Closing Comment


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now