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. C#
  4. managed code that will do the same as SetForegroundWindow

managed code that will do the same as SetForegroundWindow

Scheduled Pinned Locked Moved C#
question
3 Posts 2 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
    kevinnicol
    wrote on last edited by
    #1

    Does anyone know any way to set a process to be the foreground window in managed code, I have a Process object and need to set that process to be the front form. I was previously using the user32.dll function SetForegroundWindow(p.MainWindowHandle);, but I know have a requirement to use only managed code. Any ideas?

    D 1 Reply Last reply
    0
    • K kevinnicol

      Does anyone know any way to set a process to be the foreground window in managed code, I have a Process object and need to set that process to be the front form. I was previously using the user32.dll function SetForegroundWindow(p.MainWindowHandle);, but I know have a requirement to use only managed code. Any ideas?

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      If the window is one in your application then you can call Activate(); on the instance and it will activate the form. Why only managed code? Alot of the managed classes are just wrappers around the native stuff (or wrappers around managed wrappers!), calling API functions yourself is just the same so long as it is done correctly.

      Dave
      Tip: Passing values between objects using events (C#) BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Why are you using VB6? Do you hate yourself? (Christian Graus)

      K 1 Reply Last reply
      0
      • D DaveyM69

        If the window is one in your application then you can call Activate(); on the instance and it will activate the form. Why only managed code? Alot of the managed classes are just wrappers around the native stuff (or wrappers around managed wrappers!), calling API functions yourself is just the same so long as it is done correctly.

        Dave
        Tip: Passing values between objects using events (C#) BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Why are you using VB6? Do you hate yourself? (Christian Graus)

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

        The process is not in my app, so the Activate(); trick wont work for me. The managed code is a microsoft certification requirement. It's fine if there are 3rd party assemblies in my project that call unmanaged code, but there cannot be any in any of the code I've written.

        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