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. Managed C++/CLI
  4. Converting a IntPtr to HWND ?

Converting a IntPtr to HWND ?

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
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.
  • F Offline
    F Offline
    Fritzables
    wrote on last edited by
    #1

    Ok, on previous posts you may have noticed that I have been playing around with processes and the like. I have created a Console application that fires up NOTEPAD and access the menus but I need to ensure that it remains as the ForegroundWindow. To do this I need to acquire the Handle of the process that I started then apply it to the ForegroundWindow property - this is where I am having trouble. The following is how I start NOTEPAD then return it's MainWindowHandle which is a IntPtr: IntPtr Hnd; Process^ Proc = gcnew Process; Proc->StartInfo->FileName = "NOTEPAD.EXE"; Proc->Start(); Proc->WaitForInputIdle(); Hnd = Proc->MainWindowHandle; Now when I include the following line: SetForegroundWindow(Hnd); I get the following error when compiling: error C2664: 'SetForegroundWindow' : cannot convert parameter 1 from 'System::IntPtr' to 'HWND' Can I conver a IntPtr to a HWND ? Pete

    L 1 Reply Last reply
    0
    • F Fritzables

      Ok, on previous posts you may have noticed that I have been playing around with processes and the like. I have created a Console application that fires up NOTEPAD and access the menus but I need to ensure that it remains as the ForegroundWindow. To do this I need to acquire the Handle of the process that I started then apply it to the ForegroundWindow property - this is where I am having trouble. The following is how I start NOTEPAD then return it's MainWindowHandle which is a IntPtr: IntPtr Hnd; Process^ Proc = gcnew Process; Proc->StartInfo->FileName = "NOTEPAD.EXE"; Proc->Start(); Proc->WaitForInputIdle(); Hnd = Proc->MainWindowHandle; Now when I include the following line: SetForegroundWindow(Hnd); I get the following error when compiling: error C2664: 'SetForegroundWindow' : cannot convert parameter 1 from 'System::IntPtr' to 'HWND' Can I conver a IntPtr to a HWND ? Pete

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      G'Day Pete Give this a go ::SetForegroundWindow((HWND)(Hnd.ToPointer()));

      System.IO.Path.IsPathRooted() does not behave as I would expect

      F 1 Reply Last reply
      0
      • L Lost User

        G'Day Pete Give this a go ::SetForegroundWindow((HWND)(Hnd.ToPointer()));

        System.IO.Path.IsPathRooted() does not behave as I would expect

        F Offline
        F Offline
        Fritzables
        wrote on last edited by
        #3

        G'Day Josh, Yep.... look'n good. Thanks again and have a great Xmas. Pete

        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