[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr FindWindow(string strClass, string strWindow);
IntPtr hh = FindWindow("Notepad", "");
MessageBox.Show(hh.ToString());
用spy++看下,记事本的窗口类是不是叫Notepad。另外第二个参数传null,而不是""
也可以第一个null,第二个写窗口标题
static CWnd* PASCAL FindWindow(
LPCTSTR lpszClassName,
LPCTSTR lpszWindowName
);
Collapse imageParameters
lpszClassName
Points to a null-terminated string that specifies the window's class name (a WNDCLASS structure). If lpClassName is NULL, all class names match.
lpszWindowName
Points to a null-terminated string that specifies the window name (the window's title). If lpWindowName is NULL, all window names match.