Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Getting active window

Getting active window

Scheduled Pinned Locked Moved Visual Basic
questioncsharp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    koatto
    wrote on last edited by
    #1

    How can i get the currently active window in VB.Net without declaring an external user32.dll function and use it? There's a function i can call directly? Thanks, Ale.

    A 1 Reply Last reply
    0
    • K koatto

      How can i get the currently active window in VB.Net without declaring an external user32.dll function and use it? There's a function i can call directly? Thanks, Ale.

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      I don't know of a Framework call that will do that. Anyway, what's wrong with calling into Win32?

      K 1 Reply Last reply
      0
      • A Anonymous

        I don't know of a Framework call that will do that. Anyway, what's wrong with calling into Win32?

        K Offline
        K Offline
        koatto
        wrote on last edited by
        #3

        What i want to do is a background process getting notified of system messages, such as WM_APPACTIVATE and get a reference or an handle of activated process/app. I had some bad experience with NativeWindow class, i think i've not completely got all the triks it offers. Could you suggest any solution? Thanks.

        D 2 Replies Last reply
        0
        • K koatto

          What i want to do is a background process getting notified of system messages, such as WM_APPACTIVATE and get a reference or an handle of activated process/app. I had some bad experience with NativeWindow class, i think i've not completely got all the triks it offers. Could you suggest any solution? Thanks.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Just curious, but what is this project doing? RageInTheMachine9532

          K 1 Reply Last reply
          0
          • K koatto

            What i want to do is a background process getting notified of system messages, such as WM_APPACTIVATE and get a reference or an handle of activated process/app. I had some bad experience with NativeWindow class, i think i've not completely got all the triks it offers. Could you suggest any solution? Thanks.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            OK. First, there is no WM_APPACTIVATE message. The closest match to what your looking for is WM_ACTIVATE. It is sent once to two windows. First, to the window being deactivated, then to the window being activated. The WPARAM part of the message contains the details of the ACTIVATE command and the LPARAM part will contain the handle of the window being activated or deactivated and, strangely enough, CAN BE NULL! Full details on the WM_ACTIVE message are here[^]. Second, the WM_ACTIVATE message is NOT broadcast to the entire system. In order to get your hands on that message your going to have to write a CBT Hook. With this you'll get notified of all Activate, Create, Destroy, Minimize, Maximize, Move, and Size messages going to any window, along with a bunch of other things. I'm saying this because you're hook routine is going to have to pick out the messages you want, do any processing you want, and then send the message down the hook chain quickly and efficiently or else you'll degrade system performance. The top of the Windows Hooks documentation starts here[^], and the docs for writing a CBTProc hook function are here[^]. If your not familiar with writing Windows Hook functions, it's going to be a bit confusing to read at first. You might want to start with the basics of how Windows Messaging works, and that is

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              Just curious, but what is this project doing? RageInTheMachine9532

              K Offline
              K Offline
              koatto
              wrote on last edited by
              #6

              Very, very helpfull. Thank you very much. I'm working on a webapp controlling a very old application, i need to simulate a terminal server session via web browser. I'm new to .net development, i come from years of java programming. Just another little question, i start a process and i do the following : startedProcess = Process.Start(startInfo) startedProcess.WaitForInputIdle(5000) Dim name = startedProcess.MainWindowTitle() Dim mwHandle = startedProcess.MainWindowHandle() Dim topForm = Form.FromHandle(mwHandle) topForm is always null. How can i get a Form object from a window handle? thanks again.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups