CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    71

    Sending application to front

    Hi,

    We have two applications, one for logging information and one DOS application that starts in a DOS-box.

    What we want is that the logging application is always the top window when the DOS box is started (the logging application starts with Windows and can't be shutdown by the user).

    How can this be done. I know it has something to do with ordering Windows.


    Thanks for your time

    Jeroen van den Bergh



  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Sending application to front

    Use the SetWindowPos api:


    option Explicit

    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    Const SWP_NOSIZE = &H1
    Const SWP_NOMOVE = &H2
    Const SWP_NOACTIVATE = &H10
    Const SWP_SHOWWINDOW = &H40
    private Declare Sub 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)

    private Sub Form_Activate()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    'set the window position to topmost
    SetWindowPos me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    End Sub






  3. #3
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    71

    Re: Sending application to front

    Hi,

    This is not what I mean. Both applications are not programmed by me. I want to create an app running in the system tray (that's already done) that checks for the given application names (given from e.g. the command line, so can be variable).

    It should be like this:
    - App.One is started with Windows startup
    - App.Two is started when the user wants to use the application
    - The new application that controls the topmost Windows (this is were it's all about)

    App.One is not necesseraly the topmost Window when started. When App.Two starts, App.One must become the topmost Window. This should be detected and controlled by the systray app that I want to create.

    Jeroen


  4. #4
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Sending application to front

    Your systray app will need to get the window handle of App.One somehow so it can send it the message to become the front window. You'll need to use either the EnumWindows API or FindWindow API to locate App.One, etc.


  5. #5
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    71

    Re: Sending application to front

    Okay,

    That part I figured out myself, but how to do this?

    Let's say both applicationnames are variables, how do I search with these API's to find a window or app. that's called like the name given?


    Thanks for your support.

    Jeroen.


  6. #6
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Sending application to front


    option Explicit
    private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (byval lpClassName as string, byval lpWindowName as string) as Long

    private Sub Command1_Click()
    Dim hWnd1 as Long
    Dim hWnd2 as Long
    Dim strWindow1 as string
    Dim strWindow2 as string


    strWindow1 = "Form1"
    strWindow2 = "Form2"

    hWnd1 = FindWindow(vbNullString, strWindow1)
    hWnd2 = FindWindow(vbNullString, strWindow2)
    MsgBox hWnd1 & " " & hWnd2
    'Return value 0 means window not found...
    End Sub





  7. #7
    Join Date
    Oct 2000
    Location
    Netherlands
    Posts
    71

    Re: Sending application to front

    Thanks for the support. This is just what I needed, it works fine now (in combination with topic found earlier to send a window to the front).


    Jeroen van den Bergh



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