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. Make a control a child of the Desktop?

Make a control a child of the Desktop?

Scheduled Pinned Locked Moved C#
csharpdesigndockerjsonhelp
22 Posts 6 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.
  • R Offline
    R Offline
    Rocky Moore
    wrote on last edited by
    #1

    I am trying to make a combobox type control (not using an actual combobox and do not plan to subclass the ComboLBox) that will drop down a DataGrid or a List, but of course I keep hitting that dead end of trying to parent my DataGrid control (or a container for my control) to the Desktop so that it will not make my application lose focus when it is clicked on. Of course .NET does not appear to have any method to obtain the desktop window handle and when I have tried to use GetDesktopWindow() it always seems to return zero. Just parenting this control to the desktop is more work the the rest of the control. Any help is appreciated. Can hardly wait to design controls that don't have to exist outside the form's clipping region ;) Rocky Moore

    N 1 Reply Last reply
    0
    • R Rocky Moore

      I am trying to make a combobox type control (not using an actual combobox and do not plan to subclass the ComboLBox) that will drop down a DataGrid or a List, but of course I keep hitting that dead end of trying to parent my DataGrid control (or a container for my control) to the Desktop so that it will not make my application lose focus when it is clicked on. Of course .NET does not appear to have any method to obtain the desktop window handle and when I have tried to use GetDesktopWindow() it always seems to return zero. Just parenting this control to the desktop is more work the the rest of the control. Any help is appreciated. Can hardly wait to design controls that don't have to exist outside the form's clipping region ;) Rocky Moore

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      Rocky Moore wrote: GetDesktopWindow() it always seems to return zero. :-) The desktop's HWND is 0 Nish


      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

      D N R 3 Replies Last reply
      0
      • N Nish Nishant

        Rocky Moore wrote: GetDesktopWindow() it always seems to return zero. :-) The desktop's HWND is 0 Nish


        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        Most people does not seem to notice that: INVALID_HANDLE == (HANDLE)0xffffffff Crivo Automated Credit Assessment

        N N 2 Replies Last reply
        0
        • D Daniel Turini

          Most people does not seem to notice that: INVALID_HANDLE == (HANDLE)0xffffffff Crivo Automated Credit Assessment

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Yeah :-) When he got the 0, he thought it was an error :-) Nish


          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

          N 1 Reply Last reply
          0
          • N Nish Nishant

            Rocky Moore wrote: GetDesktopWindow() it always seems to return zero. :-) The desktop's HWND is 0 Nish


            Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

            N Offline
            N Offline
            Neil Van Note
            wrote on last edited by
            #5

            GetDesktopWindow() does not necessarily return 0. It does not on my machine (Windows XP Pro), this morning it is returning 0x00010014. Regards

            C N 2 Replies Last reply
            0
            • D Daniel Turini

              Most people does not seem to notice that: INVALID_HANDLE == (HANDLE)0xffffffff Crivo Automated Credit Assessment

              N Offline
              N Offline
              Neil Van Note
              wrote on last edited by
              #6

              The only time I have seen INVALID_HANDLE (INVALID_HANDLE_VALUE) mentioned is for operations on file handles. i.e. CreateWindow/CreateWindowEx return NULL on failure. NULL is a common failure result when dealing with window handles. IsWindow is a safer check. Regards

              1 Reply Last reply
              0
              • N Nish Nishant

                Yeah :-) When he got the 0, he thought it was an error :-) Nish


                Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                N Offline
                N Offline
                Neil Van Note
                wrote on last edited by
                #7

                Nish, There is no reason to slam people for asking a question. Educate me, which functions that return window handles return something other than NULL to indicate a failure. Like I mentioned above, IsWindow is a much safer check, as the documentation for GetDesktopWindow doesn't indicate it could fail. I wonder what this returns for a process that is running in a state where there is no desktop? In addition, HWND_DESKTOP, which is defined as ((HWND)0), fails IsWindow(HWND_DESKTOP) under Windows XP Pro. I haven't checked Windows 2000 yet. Regards

                N 1 Reply Last reply
                0
                • N Neil Van Note

                  GetDesktopWindow() does not necessarily return 0. It does not on my machine (Windows XP Pro), this morning it is returning 0x00010014. Regards

                  C Offline
                  C Offline
                  Corto Maltese
                  wrote on last edited by
                  #8

                  My XP Pro returns 0x00010014 and Win2k 0x0001000C :) -Gile

                  1 Reply Last reply
                  0
                  • N Nish Nishant

                    Rocky Moore wrote: GetDesktopWindow() it always seems to return zero. :-) The desktop's HWND is 0 Nish


                    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                    R Offline
                    R Offline
                    Rocky Moore
                    wrote on last edited by
                    #9

                    Nish [BusterBoy] wrote: The desktop's HWND is 0 As you have noticed from other posts, the GetDesktopWindow() does not actually return (0). If you look at your window tree with Spy, it returns the window at the very top of the tree. At least it does under the normal API in C++, but in C# it only wants to return (0) which is useless. In C# I call it as:

                    [DllImport("user32.dll")]
                    extern static IntPtr GetDesktopWindow();

                    and later in the class I simply use:

                    GetDesktopWindow();

                    It always seems to get zero, am I doing something wrong here? Rocky Moore

                    R N 2 Replies Last reply
                    0
                    • R Rocky Moore

                      Nish [BusterBoy] wrote: The desktop's HWND is 0 As you have noticed from other posts, the GetDesktopWindow() does not actually return (0). If you look at your window tree with Spy, it returns the window at the very top of the tree. At least it does under the normal API in C++, but in C# it only wants to return (0) which is useless. In C# I call it as:

                      [DllImport("user32.dll")]
                      extern static IntPtr GetDesktopWindow();

                      and later in the class I simply use:

                      GetDesktopWindow();

                      It always seems to get zero, am I doing something wrong here? Rocky Moore

                      R Offline
                      R Offline
                      Rama Krishna Vavilala
                      wrote on last edited by
                      #10

                      I get correct values all the time.:wtf:

                      R 1 Reply Last reply
                      0
                      • R Rocky Moore

                        Rama Krishna wrote: I get correct values all the time. ::Throwing Tantrum:: ::Feet Stumping:: ::Purple Face:: That's not fair, I just get zeros! ;) So, they code you use and actual get a value is the same as I showed in the last post? Rocky Moore

                        R Offline
                        R Offline
                        Rama Krishna Vavilala
                        wrote on last edited by
                        #11

                        Here is the code as it is:-

                        using System;
                        using System.Drawing;
                        using System.Collections;
                        using System.ComponentModel;
                        using System.Windows.Forms;
                        using System.Data;

                        namespace WindowsApplication2
                        {
                        /// /// Summary description for Form1.
                        ///
                        public class Form1 : System.Windows.Forms.Form
                        {
                        /// /// Required designer variable.
                        ///
                        private System.ComponentModel.Container components = null;

                        	\[System.Runtime.InteropServices.DllImport("User32.dll")\]
                        	extern static IntPtr GetDesktopWindow();
                        
                        	public Form1()
                        	{
                        		//
                        		// Required for Windows Form Designer support
                        		//
                        		InitializeComponent();
                        
                        		IntPtr hwnd = GetDesktopWindow();
                        
                        		System.Diagnostics.Debug.Assert(hwnd != IntPtr.Zero);
                        	}
                        
                        	/// /// Clean up any resources being used.
                        	/// 
                        	protected override void Dispose( bool disposing )
                        	{
                        		if( disposing )
                        		{
                        			if (components != null) 
                        			{
                        				components.Dispose();
                        			}
                        		}
                        		base.Dispose( disposing );
                        	}
                        
                        	#region Windows Form Designer generated code
                        	/// /// Required method for Designer support - do not modify
                        	/// the contents of this method with the code editor.
                        	/// 
                        	private void InitializeComponent()
                        	{
                        		this.components = new System.ComponentModel.Container();
                        		this.Size = new System.Drawing.Size(300,300);
                        		this.Text = "Form1";
                        	}
                        	#endregion
                        
                        	/// /// The main entry point for the application.
                        	/// 
                        	\[STAThread\]
                        	static void Main() 
                        	{
                        		Application.Run(new Form1());
                        	}
                        }
                        

                        }

                        R 1 Reply Last reply
                        0
                        • R Rama Krishna Vavilala

                          I get correct values all the time.:wtf:

                          R Offline
                          R Offline
                          Rocky Moore
                          wrote on last edited by
                          #12

                          Rama Krishna wrote: I get correct values all the time. ::Throwing Tantrum:: ::Feet Stumping:: ::Purple Face:: That's not fair, I just get zeros! ;) So, they code you use and actual get a value is the same as I showed in the last post? Rocky Moore

                          R 1 Reply Last reply
                          0
                          • R Rama Krishna Vavilala

                            Here is the code as it is:-

                            using System;
                            using System.Drawing;
                            using System.Collections;
                            using System.ComponentModel;
                            using System.Windows.Forms;
                            using System.Data;

                            namespace WindowsApplication2
                            {
                            /// /// Summary description for Form1.
                            ///
                            public class Form1 : System.Windows.Forms.Form
                            {
                            /// /// Required designer variable.
                            ///
                            private System.ComponentModel.Container components = null;

                            	\[System.Runtime.InteropServices.DllImport("User32.dll")\]
                            	extern static IntPtr GetDesktopWindow();
                            
                            	public Form1()
                            	{
                            		//
                            		// Required for Windows Form Designer support
                            		//
                            		InitializeComponent();
                            
                            		IntPtr hwnd = GetDesktopWindow();
                            
                            		System.Diagnostics.Debug.Assert(hwnd != IntPtr.Zero);
                            	}
                            
                            	/// /// Clean up any resources being used.
                            	/// 
                            	protected override void Dispose( bool disposing )
                            	{
                            		if( disposing )
                            		{
                            			if (components != null) 
                            			{
                            				components.Dispose();
                            			}
                            		}
                            		base.Dispose( disposing );
                            	}
                            
                            	#region Windows Form Designer generated code
                            	/// /// Required method for Designer support - do not modify
                            	/// the contents of this method with the code editor.
                            	/// 
                            	private void InitializeComponent()
                            	{
                            		this.components = new System.ComponentModel.Container();
                            		this.Size = new System.Drawing.Size(300,300);
                            		this.Text = "Form1";
                            	}
                            	#endregion
                            
                            	/// /// The main entry point for the application.
                            	/// 
                            	\[STAThread\]
                            	static void Main() 
                            	{
                            		Application.Run(new Form1());
                            	}
                            }
                            

                            }

                            R Offline
                            R Offline
                            Rocky Moore
                            wrote on last edited by
                            #13

                            That worked, must be something in the code around it that is causing the problem. At least now I can look in the right direction. Thanks for the test! I should have thought to test it in a different project first :-O Rocky Moore

                            N R 2 Replies Last reply
                            0
                            • R Rocky Moore

                              That worked, must be something in the code around it that is causing the problem. At least now I can look in the right direction. Thanks for the test! I should have thought to test it in a different project first :-O Rocky Moore

                              N Offline
                              N Offline
                              Neil Van Note
                              wrote on last edited by
                              #14

                              Again, Try a IsWindow(hWnd) on the return value; it can't be assumed that it returns anything consistent, including null. The docs just do not specify null is or is not an invalid value.

                              1 Reply Last reply
                              0
                              • R Rocky Moore

                                That worked, must be something in the code around it that is causing the problem. At least now I can look in the right direction. Thanks for the test! I should have thought to test it in a different project first :-O Rocky Moore

                                R Offline
                                R Offline
                                Rama Krishna Vavilala
                                wrote on last edited by
                                #15

                                Are you calling any other unmanaged function before?

                                1 Reply Last reply
                                0
                                • N Neil Van Note

                                  Nish, There is no reason to slam people for asking a question. Educate me, which functions that return window handles return something other than NULL to indicate a failure. Like I mentioned above, IsWindow is a much safer check, as the documentation for GetDesktopWindow doesn't indicate it could fail. I wonder what this returns for a process that is running in a state where there is no desktop? In addition, HWND_DESKTOP, which is defined as ((HWND)0), fails IsWindow(HWND_DESKTOP) under Windows XP Pro. I haven't checked Windows 2000 yet. Regards

                                  N Offline
                                  N Offline
                                  Nish Nishant
                                  wrote on last edited by
                                  #16

                                  Neil Van Note wrote: Nish, There is no reason to slam people for asking a question I wasn't slamming him :( I just thought it funny that MS was returning a 0 for GetDesktopWindow() and that too for a valid window handle, that of the desktop. Usually a 0 is supposed to indicate error or NULL as far as handles go. I apologize to all, if my words were insulting. I didnt meant them that way. Sorry! Nish


                                  Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                  1 Reply Last reply
                                  0
                                  • N Neil Van Note

                                    GetDesktopWindow() does not necessarily return 0. It does not on my machine (Windows XP Pro), this morning it is returning 0x00010014. Regards

                                    N Offline
                                    N Offline
                                    Nish Nishant
                                    wrote on last edited by
                                    #17

                                    Could be that with XP pro, we actually can have multiple virtual desktops. Nish


                                    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                    C 1 Reply Last reply
                                    0
                                    • R Rocky Moore

                                      Nish [BusterBoy] wrote: The desktop's HWND is 0 As you have noticed from other posts, the GetDesktopWindow() does not actually return (0). If you look at your window tree with Spy, it returns the window at the very top of the tree. At least it does under the normal API in C++, but in C# it only wants to return (0) which is useless. In C# I call it as:

                                      [DllImport("user32.dll")]
                                      extern static IntPtr GetDesktopWindow();

                                      and later in the class I simply use:

                                      GetDesktopWindow();

                                      It always seems to get zero, am I doing something wrong here? Rocky Moore

                                      N Offline
                                      N Offline
                                      Nish Nishant
                                      wrote on last edited by
                                      #18

                                      Rocky Moore wrote: As you have noticed from other posts, the GetDesktopWindow() does not actually return (0). Sorry Rocky, if I sounded insulting, but I have explained my reasons for smiling in my reply to Neil Van Note. It was the irony caused my MS that made me smile. Hope it's okay now :-) Nish


                                      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                      R N 2 Replies Last reply
                                      0
                                      • N Nish Nishant

                                        Rocky Moore wrote: As you have noticed from other posts, the GetDesktopWindow() does not actually return (0). Sorry Rocky, if I sounded insulting, but I have explained my reasons for smiling in my reply to Neil Van Note. It was the irony caused my MS that made me smile. Hope it's okay now :-) Nish


                                        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                        R Offline
                                        R Offline
                                        Rocky Moore
                                        wrote on last edited by
                                        #19

                                        Nish [BusterBoy] wrote: Sorry Rocky, if I sounded insulting, but I have explained my reasons for smiling in my reply to Neil Van Note. It was the irony caused my MS that made me smile. Hope it's okay now Wasn't taken that way, I am not a softy like others here :rolleyes: I truly appreciate any help I get, and Lord knows I need a lot at times ;) I still do not know why it was returning zero but I have done a bit of rewriting all around it and it seems to be working. One of those strange things, just glad I can finally move on. Now if I can just figure a way to get rid of the 'add a new row' row in the DataGrid that is using a dataset bound to the datasource instead of a dataview, my life would be much easier.. Thanks again! Rocky Moore

                                        1 Reply Last reply
                                        0
                                        • N Nish Nishant

                                          Could be that with XP pro, we actually can have multiple virtual desktops. Nish


                                          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                          C Offline
                                          C Offline
                                          Corto Maltese
                                          wrote on last edited by
                                          #20

                                          Multiple virtual desktops are more about extending window manager than being related to the OS (XP, Win2K, Win 9x, etc.). So, I guess we can have them with any MS OS flavor. It is just that with MS the actual line between the OS, shell and the window manager is kind of blurry (for the end user at least). -Gile

                                          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