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. .NET (Core and Framework)
  4. Setting HWND handle to a .NET Windows form

Setting HWND handle to a .NET Windows form

Scheduled Pinned Locked Moved .NET (Core and Framework)
comquestioncsharp
17 Posts 4 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.
  • M MrBean

    If you are not able to help, please do not post relys or irrelevant questions in this thread - thank you !

    D Offline
    D Offline
    Duncan Edwards Jones
    wrote on last edited by
    #8

    System.Windows.Forms.Form.Handle Property Value An IntPtr that contains the window handle (HWND) of the control. (or form) '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

    M 1 Reply Last reply
    0
    • D Duncan Edwards Jones

      System.Windows.Forms.Form.Handle Property Value An IntPtr that contains the window handle (HWND) of the control. (or form) '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

      M Offline
      M Offline
      MrBean
      wrote on last edited by
      #9

      Yes... but that's a READ-ONLY property !

      D 1 Reply Last reply
      0
      • M MrBean

        If you are not able to help, please do not post relys or irrelevant questions in this thread - thank you !

        S Offline
        S Offline
        Serge Lobko Lobanovsky
        wrote on last edited by
        #10

        MrBean wrote: If you are not able to help, please do not post relys or irrelevant questions man, i AM trying to figure out what you wanna accomplish. sorry if i bothered u with my "irrelevant" questions. if you want a .NET form to set its Owner to a not .NET form - the answer is you can't. if you want a .NET form to become an MDI child of a .NET form - the answer is tou can't. what i was trying to understand is for what purpose you need it so that i can judge if it is at least possible. you need to provide more info. Regards, Serge (Logic Software)

        M 1 Reply Last reply
        0
        • M MrBean

          Yes... but that's a READ-ONLY property !

          D Offline
          D Offline
          Duncan Edwards Jones
          wrote on last edited by
          #11

          Yes - well, the window handle is assigned by the operating system when the window is created. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

          M 1 Reply Last reply
          0
          • D Duncan Edwards Jones

            Yes - well, the window handle is assigned by the operating system when the window is created. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

            M Offline
            M Offline
            MrBean
            wrote on last edited by
            #12

            Dude, please read my question again... I want to set the *parent* handle. Not read the Window handle of my form...

            D 1 Reply Last reply
            0
            • S Serge Lobko Lobanovsky

              MrBean wrote: If you are not able to help, please do not post relys or irrelevant questions man, i AM trying to figure out what you wanna accomplish. sorry if i bothered u with my "irrelevant" questions. if you want a .NET form to set its Owner to a not .NET form - the answer is you can't. if you want a .NET form to become an MDI child of a .NET form - the answer is tou can't. what i was trying to understand is for what purpose you need it so that i can judge if it is at least possible. you need to provide more info. Regards, Serge (Logic Software)

              M Offline
              M Offline
              MrBean
              wrote on last edited by
              #13

              So in short (regardless if it's a MDI child or not)... I can't ;( I think I have given enough info... but can can try to write it different :) I'm making a .NET DLL which contains a single Windows Form. This form is used by an VB6 based application thru COM. The VB6-based application then use my DLL/form by calling a few standard methods and setting the form size, parent handle and such. It's the application way of supporting plug-ins. The plug-ins are shown as kind of controls on a form but not as a MDI form or ActiveX control - it's a kind of embedded form. This works today but only with VB6 DLLs (COM) and VB6 forms. So I basicly need to make a plug-in for the application but this time in .NET...

              S 1 Reply Last reply
              0
              • M MrBean

                So in short (regardless if it's a MDI child or not)... I can't ;( I think I have given enough info... but can can try to write it different :) I'm making a .NET DLL which contains a single Windows Form. This form is used by an VB6 based application thru COM. The VB6-based application then use my DLL/form by calling a few standard methods and setting the form size, parent handle and such. It's the application way of supporting plug-ins. The plug-ins are shown as kind of controls on a form but not as a MDI form or ActiveX control - it's a kind of embedded form. This works today but only with VB6 DLLs (COM) and VB6 forms. So I basicly need to make a plug-in for the application but this time in .NET...

                S Offline
                S Offline
                Serge Lobko Lobanovsky
                wrote on last edited by
                #14

                Ok, now I see your problem. I am afraid you won't be able to implement it this way because of the different nature of forms in .NET and VB6. One solution that I can think of now is to implement your plugin DLL without a form, and create another DLL in Vb6 that will consume your plugin DLL methods, while providing a form for your application to show it as usual. hope that makes some sense :) Regards, Serge (Logic Software)

                1 Reply Last reply
                0
                • M MrBean

                  Dude, please read my question again... I want to set the *parent* handle. Not read the Window handle of my form...

                  D Offline
                  D Offline
                  Duncan Edwards Jones
                  wrote on last edited by
                  #15

                  Then you will need the SetParent API call...and pass it the handle you get as per the earlier post. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

                  M 1 Reply Last reply
                  0
                  • D Duncan Edwards Jones

                    Then you will need the SetParent API call...and pass it the handle you get as per the earlier post. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

                    M Offline
                    M Offline
                    MrBean
                    wrote on last edited by
                    #16

                    I have tried the SetParent API function but without luck ;( The form is created but the parent-child relationship is not set somehow. Both this... m_MyForm = new MyForm SetParent(m_MyForm.Handle.ToInt32, m_ParentHandle) m_MyForm.Show() ...and... m_MyForm = new MyForm m_MyForm.Show() SetParent(m_MyForm.Handle.ToInt32, m_ParentHandle) ...doesn't work... something else I need to call or set ?

                    1 Reply Last reply
                    0
                    • M MrBean

                      I'm developing a .NET based DLL (in VB.NET) which exposes a COM class for an old system which only supports COM/ActiveX. So I'm basicly calling my new .NET COM class from an old VB6 based application. One of the methods in my .NET based COM class takes a HWND handle (long) which is used as the parent handle for a form which my DLL creates and displays. But how do I set the parent handle to my .NET Windows form ? The form is displayed with the Show method (modeless).

                      J Offline
                      J Offline
                      James Simpson
                      wrote on last edited by
                      #17

                      Have I got this correct: HWND passed into .NET Object to be displayed as a child of a .NET form in the DLL? Look into NativeWindow.FromHandle or Control.FromHandle. This should give you a .NET object from the handle and expose some more functionality. If you just want to display the HWND as a child of a Form created in .NET you can use a windows UI function from User32, SetWindowParent will be able to reparent the child form as a child of your .NET form. J James Simpson Web Developer imebgo@hotmail.com P S - This is what part of the alphabet would look like if Q and R were eliminated
                      Mitch Hedberg

                      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