Tôi đang sử dụng mã bên dưới để xóa Thanh tiêu đề của một ứng dụng đang hoạt động hoàn hảo cho notepad. Bây giờ tôi muốn loại bỏ thanh Menu cũng. Làm thế nào để đạt được nó?Cách xóa MenuBar của ứng dụng bằng API cửa sổ?
//Finds a window by class name
[DllImport("USER32.DLL")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
//Sets a window to be a child window of another window
[DllImport("USER32.DLL")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
//Sets window attributes
[DllImport("USER32.DLL")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
//Gets window attributes
[DllImport("USER32.DLL")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
//assorted constants needed
public static int GWL_STYLE = -16;
public static int WS_BORDER = 0x00800000; //window with border
public static int WS_DLGFRAME = 0x00400000; //window with double border but no title
public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar
public void WindowsReStyle()
{
Process[] Procs = Process.GetProcesses();
foreach (Process proc in Procs)
{
if (proc.ProcessName.StartsWith("notepad"))
{
IntPtr pFoundWindow = proc.MainWindowHandle;
int style = GetWindowLong(pFoundWindow, GWL_STYLE);
SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION));
}
}
}
Tôi cần giống nhau. Nhưng khi áp dụng mã này trong ứng dụng của tôi, nó ẩn thanh tiêu đề khi thực hiện một số tương tác chuột trên nó (như kéo và thả, v.v.). Bạn có thể gợi ý cho tôi nguyên nhân gốc rễ không? –