Непонятки с user32.dll - C#
Формулировка задачи:
using System.Runtime.InteropServices;
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern bool BringWindowToTop(IntPtr hWnd);
static void Main(string[] args)
{
IntPtr w = FindWindow(null, "Калькулятор");
BringWindowToTop(w);
}SetForegroundWindow(w); //заработало
и ещё это добавить сверху:
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetForegroundWindow(IntPtr hWnd);Решение задачи: «Непонятки с user32.dll»
textual
Листинг программы
static IntPtr HWND_TOP = new IntPtr(0);
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOSIZE = 0x0001;
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
static void BringWindowToFront(IntPtr hWnd)
{
SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}