David's helpful answer cung cấp các con trỏ quan trọng và liên kết hữu ích.
Để đưa vào sử dụng trong một ví dụ khép kín mà thực hiện kịch bản mẫu trong câu hỏi, sử dụng API Windows thông qua P/Invoke (System.Windows.Forms
là không tham gia):
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);
}
}
}
Cảm ơn nguồn! :) Nó cực kỳ hữu ích. –
@DataDink, bạn có chuyển thư viện này sang GitHub không? – Theraot
đặt tên dự án: WindowScrape. Nó hiện có sẵn tại đây: http://code.google.com/p/lol-mastery-tool/source/browse/LOL+Mastery+Tool/WindowScrape.dll?r=b88d6a538d88e052a88c69ffb70aaa09fc4a735e với nguồn có sẵn: https: // bitbucket .org/crwilcox/turbo-click/commits/89a687df7511490effb22ad3fc3e48fc9ab8c47a # chg-WindowScrape/ReadMe.txt Một số nội dung của nó là readme, cho các tìm kiếm trong tương lai 'Lớp HwndObject gói gọn một số chức năng xung quanh cửa sổ xử lý đối tượng UI.' – mbrownnyc