0

So I found an example from an answer provided here

There was an answer that gave this example of code to move the Notepad window to the top left corner of the screen. I tried it and it worked fine. I then tried it on a small project I am working on and I couldn't move it.

NOTE: I did change the "Notepad" to the name at the top of the window I wanted to move.

using System;
using System.Runtime.InteropServices; // For the P/Invoke signatures.

public static class PositionWindowDemo
{

// P/Invoke declarations.

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

const uint SWP_NOSIZE = 0x0001;
const uint SWP_NOZORDER = 0x0004;

public static void Main()
{
    // Find (the first-in-Z-order) Notepad window.
    IntPtr hWnd = FindWindow("Notepad", null);

    // If found, position it.
    if (hWnd != IntPtr.Zero)
    {
        // Move the window to (0,0) without changing its size or position
        // in the Z order.
        SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    }
}

}

I will give an example. Consider Visual Studios and how it has the Solution Explorer Window or the Output window, and I can drag them with the mouse and move them or undock them. Would there be a way to have an application that has windows inside of it similar to Visual Studios and get the position of them in a program?

I have seen many answers on here about moving a window or finding the active window etc. However I am not sure if I will be able to access this subWindow that is inside of another application.

Thanks

RSon1234
  • 394
  • 4
  • 14
  • Yes you should be able to, however getting the handle to your sub windows might be a little more tricky. have you tried enumerating all the windows of the application and see if its there – TheGeneral Mar 07 '18 at 04:27
  • I just did. But I did not see anything about the extra windows. I opened 3 sub Windows just to check – RSon1234 Mar 07 '18 at 04:50
  • It turns out the windows are owner-drawn. I guess this means there is nothing I can do? – RSon1234 Mar 07 '18 at 23:48
  • I was just about message on this, have you tried looking with spy++, to make sure they are truly just painted on and not part of a control ie no handle – TheGeneral Mar 07 '18 at 23:50
  • Yes I just did it and it shows no handle or any information about the window – RSon1234 Mar 08 '18 at 17:33

0 Answers0