Moving Other Windows
-
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?
-
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?
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]
-
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]
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 functionsprivate 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 eventprivate 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?
-
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 functionsprivate 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 eventprivate 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?
That's great. Thanks for the info.
-
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 functionsprivate 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 eventprivate 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?
you got my 5 :):)
It is Good to be Important but! it is more Important to be Good [My Question]
-
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 functionsprivate 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 eventprivate 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?
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?
-
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?
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?