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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. GetWindow

GetWindow

Scheduled Pinned Locked Moved C#
csharptutorialquestion
5 Posts 3 Posters 1 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.
  • Y Offline
    Y Offline
    yyf
    wrote on last edited by
    #1

    How to use "GetWindow" in C#.net? Thanks in advance!

    J H 2 Replies Last reply
    0
    • Y yyf

      How to use "GetWindow" in C#.net? Thanks in advance!

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      someForm.Owner The graveyards are filled with indispensible men.

      H 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        someForm.Owner The graveyards are filled with indispensible men.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        Only if your nCmd parameter to GetWindow would be GW_OWNER.

        Microsoft MVP, Visual C# My Articles

        1 Reply Last reply
        0
        • Y yyf

          How to use "GetWindow" in C#.net? Thanks in advance!

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          You'll have to P/Invoke it like so:

          [DllImport("user32.dll")]
          private static extern IntPtr GetWindow(
          IntPtr hWnd,
          [MarshalAs(UnmanagedType.U4)] int nCmd);
          private const int GW_HWNDFIRST = 0;
          private const int GW_HWNDLAST = 1;
          private const int GW_HWNDNEXT = 2;
          private const int GW_HWNDPREV = 3;
          private const int GW_OWNER = 4;
          private const int GW_CHILD = 5;

          You could define those constants as a enum, then change the declaration from int to your enum in GetWindow (leave the MarshalAsAttribute as is) if you want, but it really makes no difference if these are private and you'll be the only one calling these. You can get the window handle from Control.Handle, from which all controls (including Form) derive. You can use Control.FromHandle with the return IntPtr to get the control, which you can cast to whatever you like (like a Form).

          Microsoft MVP, Visual C# My Articles

          Y 1 Reply Last reply
          0
          • H Heath Stewart

            You'll have to P/Invoke it like so:

            [DllImport("user32.dll")]
            private static extern IntPtr GetWindow(
            IntPtr hWnd,
            [MarshalAs(UnmanagedType.U4)] int nCmd);
            private const int GW_HWNDFIRST = 0;
            private const int GW_HWNDLAST = 1;
            private const int GW_HWNDNEXT = 2;
            private const int GW_HWNDPREV = 3;
            private const int GW_OWNER = 4;
            private const int GW_CHILD = 5;

            You could define those constants as a enum, then change the declaration from int to your enum in GetWindow (leave the MarshalAsAttribute as is) if you want, but it really makes no difference if these are private and you'll be the only one calling these. You can get the window handle from Control.Handle, from which all controls (including Form) derive. You can use Control.FromHandle with the return IntPtr to get the control, which you can cast to whatever you like (like a Form).

            Microsoft MVP, Visual C# My Articles

            Y Offline
            Y Offline
            yyf
            wrote on last edited by
            #5

            Thanks a lot!

            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