windows 10 GetLastWin32Error()ERROR_ACCESS_DENIED

时间:2017-08-28 09:08:18

标签: c#

你好我有视觉工作室2017免费版 我尝试使程序使用movewindow问题是,当我使用它我有错误nr 5 ERROR_ACCESS_DENIED,这就是为什么movewindow不工作。

我打开vs2017与管理权保险及其剂量工作。

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {




        IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero,null,"Kalkulator");


        if (hWnd != IntPtr.Zero)
        {


            diagnoza.Text = "znalazl" + "\r\n";


            MoveWindow(hWnd,0,0,100,100,true);
            int error = Marshal.GetLastWin32Error();
            diagnoza.Text += "błąd nr : " + error;
        }

        else { diagnoza.Text = "nie znalazl" + "\r\n" ;
            int error = Marshal.GetLastWin32Error();
            diagnoza.Text += "błąd nr : " + error;
        }
    }


    [DllImport("User32.dll", SetLastError = true)]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

   [DllImport("User32.dll", SetLastError = true)]
    internal static extern bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);



}

0 个答案:

没有答案