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. How to convert an API window to a control?

How to convert an API window to a control?

Scheduled Pinned Locked Moved C#
questioncsharpjsontutorial
4 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.
  • D Offline
    D Offline
    Duong Tien Nam
    wrote on last edited by
    #1

    in C#, I call an API func CreateWindow to create a new window, and I have its handler which the type is IntPtr. Although I created it with WS_CHILD property and set it parent to a Form (get a handler by property System.Window.Forms.Form.Handler) but my window is still seperate from it parent form. So how can I convert my window to a control in order to add it to my form? Thanks for your attention :)

    C 1 Reply Last reply
    0
    • D Duong Tien Nam

      in C#, I call an API func CreateWindow to create a new window, and I have its handler which the type is IntPtr. Although I created it with WS_CHILD property and set it parent to a Form (get a handler by property System.Window.Forms.Form.Handler) but my window is still seperate from it parent form. So how can I convert my window to a control in order to add it to my form? Thanks for your attention :)

      C Offline
      C Offline
      cobyjone
      wrote on last edited by
      #2

      This has worked for me in some cases but in others it is kind of flaky. IntPtr hWnd = //your handle from CreateWindow Control control = new Control(); Type type = typeof(Control); MethodInfo method = type.GetMethod("WindowAssignHandle", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(control, new object[] {hWnd, false}); {parent form/control}.Controls.Add(control);

      D 1 Reply Last reply
      0
      • C cobyjone

        This has worked for me in some cases but in others it is kind of flaky. IntPtr hWnd = //your handle from CreateWindow Control control = new Control(); Type type = typeof(Control); MethodInfo method = type.GetMethod("WindowAssignHandle", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(control, new object[] {hWnd, false}); {parent form/control}.Controls.Add(control);

        D Offline
        D Offline
        Duong Tien Nam
        wrote on last edited by
        #3

        what version of .NET framework do you use? I listed all the NonPublic methods of type Control to find the function named "WindowAssignHandle" but it doesnt exist :( , whats wrong with me????

        C 1 Reply Last reply
        0
        • D Duong Tien Nam

          what version of .NET framework do you use? I listed all the NonPublic methods of type Control to find the function named "WindowAssignHandle" but it doesnt exist :( , whats wrong with me????

          C Offline
          C Offline
          cobyjone
          wrote on last edited by
          #4

          I am using 2.0. If you are using 1.1, try the following although I have not tried this: IntPtr hWnd = //your handle from CreateWindow Control control = new Control(); Type type = typeof(Control); FieldInfo field = type.GetField("window", BindingFlags.Instance | BindingFlags.NonPublic); Type windowType = typeof(NativeWindow); NativeWindow window = (NativeWindow)field.GetValue(control); MethodInfo method = windowType.GetMethod("AssignHandle", BindingFlags.Instance | BindingFlags.NonPublic); method.Invoke(window, new object[] {hWnd, false}); {parent form/control}.Controls.Add(control);

          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