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. Moving Other Windows

Moving Other Windows

Scheduled Pinned Locked Moved C#
helptutorialquestionworkspace
7 Posts 3 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.
  • N Offline
    N Offline
    Now_Loading
    wrote on last edited by
    #1

    I currently have a dual monitor setup on my system, one a monitor, and one a TV. the problem is, my TV is not always on, or someone is using it, therefore I am left with only one Monitor on a dual monitor setup. I could activate and deactive my setup, but that is bothersome. What I wanted to do is create a program that will allow me to move existing windows to specific locations. For example, if a window is stuck on my TV monitor, I can input the coordinates of my computer monitor, and the window will be moved. I have been trying to target the processes, but I don't seem to be able to set the location of the window. Does anyone have any ideas?

    A 1 Reply Last reply
    0
    • N Now_Loading

      I currently have a dual monitor setup on my system, one a monitor, and one a TV. the problem is, my TV is not always on, or someone is using it, therefore I am left with only one Monitor on a dual monitor setup. I could activate and deactive my setup, but that is bothersome. What I wanted to do is create a program that will allow me to move existing windows to specific locations. For example, if a window is stuck on my TV monitor, I can input the coordinates of my computer monitor, and the window will be moved. I have been trying to target the processes, but I don't seem to be able to set the location of the window. Does anyone have any ideas?

      A Offline
      A Offline
      Amar Chaudhary
      wrote on last edited by
      #2

      i dont know how to do it in c# but you can do it using hardware profile settings :):)

      It is Good to be Important but! it is more Important to be Good [My Question]

      S 1 Reply Last reply
      0
      • A Amar Chaudhary

        i dont know how to do it in c# but you can do it using hardware profile settings :):)

        It is Good to be Important but! it is more Important to be Good [My Question]

        S Offline
        S Offline
        shopi30
        wrote on last edited by
        #3

        Hi Amar Chaudhary. You can do it, using InteropServices. Example: First you need attach the follow namespace using System.Runtime.InteropServices; Second you need import the Microsoft Windows Runtime dll's for declare the extern methods. [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); Third you need declare the follow constants and methods for invoke the functions private const int WM_NCLBUTTONDOWN = 0xA1; private const int HTCAPTION = 0x2; private void MoveForm() {     ReleaseCapture();     SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } protected override void WndProc(ref Message m) {     base.WndProc(ref m);     int WM_NCHITTEST = 0x84;     if (m.Msg == WM_NCHITTEST)     {         int HTCLIENT = 1;         int HTCAPTION = 2;         if (m.Result.ToInt32() == HTCLIENT)         {             m.Result = (IntPtr)HTCAPTION;         }     } } Finally you need call the function with any MouseDown event private void button1_MouseDown(object sender, MouseEventArgs e) {     if (e.Button == MouseButtons.Left)     {         this.MoveForm();     } } Remember that you can replace the "this.Handle" for you Window Handle that you want move. I hope that this resolve your problem.

        SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

        N A 3 Replies Last reply
        0
        • S shopi30

          Hi Amar Chaudhary. You can do it, using InteropServices. Example: First you need attach the follow namespace using System.Runtime.InteropServices; Second you need import the Microsoft Windows Runtime dll's for declare the extern methods. [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); Third you need declare the follow constants and methods for invoke the functions private const int WM_NCLBUTTONDOWN = 0xA1; private const int HTCAPTION = 0x2; private void MoveForm() {     ReleaseCapture();     SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } protected override void WndProc(ref Message m) {     base.WndProc(ref m);     int WM_NCHITTEST = 0x84;     if (m.Msg == WM_NCHITTEST)     {         int HTCLIENT = 1;         int HTCAPTION = 2;         if (m.Result.ToInt32() == HTCLIENT)         {             m.Result = (IntPtr)HTCAPTION;         }     } } Finally you need call the function with any MouseDown event private void button1_MouseDown(object sender, MouseEventArgs e) {     if (e.Button == MouseButtons.Left)     {         this.MoveForm();     } } Remember that you can replace the "this.Handle" for you Window Handle that you want move. I hope that this resolve your problem.

          SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

          N Offline
          N Offline
          Now_Loading
          wrote on last edited by
          #4

          That's great. Thanks for the info.

          1 Reply Last reply
          0
          • S shopi30

            Hi Amar Chaudhary. You can do it, using InteropServices. Example: First you need attach the follow namespace using System.Runtime.InteropServices; Second you need import the Microsoft Windows Runtime dll's for declare the extern methods. [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); Third you need declare the follow constants and methods for invoke the functions private const int WM_NCLBUTTONDOWN = 0xA1; private const int HTCAPTION = 0x2; private void MoveForm() {     ReleaseCapture();     SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } protected override void WndProc(ref Message m) {     base.WndProc(ref m);     int WM_NCHITTEST = 0x84;     if (m.Msg == WM_NCHITTEST)     {         int HTCLIENT = 1;         int HTCAPTION = 2;         if (m.Result.ToInt32() == HTCLIENT)         {             m.Result = (IntPtr)HTCAPTION;         }     } } Finally you need call the function with any MouseDown event private void button1_MouseDown(object sender, MouseEventArgs e) {     if (e.Button == MouseButtons.Left)     {         this.MoveForm();     } } Remember that you can replace the "this.Handle" for you Window Handle that you want move. I hope that this resolve your problem.

            SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

            A Offline
            A Offline
            Amar Chaudhary
            wrote on last edited by
            #5

            you got my 5 :):)

            It is Good to be Important but! it is more Important to be Good [My Question]

            1 Reply Last reply
            0
            • S shopi30

              Hi Amar Chaudhary. You can do it, using InteropServices. Example: First you need attach the follow namespace using System.Runtime.InteropServices; Second you need import the Microsoft Windows Runtime dll's for declare the extern methods. [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); Third you need declare the follow constants and methods for invoke the functions private const int WM_NCLBUTTONDOWN = 0xA1; private const int HTCAPTION = 0x2; private void MoveForm() {     ReleaseCapture();     SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } protected override void WndProc(ref Message m) {     base.WndProc(ref m);     int WM_NCHITTEST = 0x84;     if (m.Msg == WM_NCHITTEST)     {         int HTCLIENT = 1;         int HTCAPTION = 2;         if (m.Result.ToInt32() == HTCLIENT)         {             m.Result = (IntPtr)HTCAPTION;         }     } } Finally you need call the function with any MouseDown event private void button1_MouseDown(object sender, MouseEventArgs e) {     if (e.Button == MouseButtons.Left)     {         this.MoveForm();     } } Remember that you can replace the "this.Handle" for you Window Handle that you want move. I hope that this resolve your problem.

              SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

              N Offline
              N Offline
              Now_Loading
              wrote on last edited by
              #6

              hey shopi30, I tried using the code, but could not get it working. I can move "my" form by using this.Handle, but if I target another handle, like iexplore, I get nothing. I have tried getting the process handle by process.Handle, and also process.MainHandle, but no luck. Do I have to set focus to the process that I want to move? If so, how do I do that? Also, is there any way that I can specify the x and y co-ordinates of the window, or is it all based on the cursor?

              S 1 Reply Last reply
              0
              • N Now_Loading

                hey shopi30, I tried using the code, but could not get it working. I can move "my" form by using this.Handle, but if I target another handle, like iexplore, I get nothing. I have tried getting the process handle by process.Handle, and also process.MainHandle, but no luck. Do I have to set focus to the process that I want to move? If so, how do I do that? Also, is there any way that I can specify the x and y co-ordinates of the window, or is it all based on the cursor?

                S Offline
                S Offline
                shopi30
                wrote on last edited by
                #7

                Hi Now_Loading. Try using: [DllImportAttribute("user32.dll")] private extern static IntPtr GetForegroundWindow(); And change "this.Handle" to "GetForegroundWindow()" GetForegroundWindow method return the Handle from the current window active. If this don't solve your problem tell me and I'll be sending you other options. By the way if you can help me with these System.Data.OleDb & Microsoft Excel I'll be thankful with you.

                SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

                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