1

我编写了一个更改 Windows 主题的程序,但在更改主题个性化窗口后仍然打开,我想关闭它。我尝试使用具有熟悉进程名称的 process.kill() 但它不起作用。谢谢你。

我正在做的代码如下:

ProcessStartInfo theinfo = new ProcessStartInfo(themepath + "aero.theme");
theinfo.CreateNoWindow = true;
Process thepr = new Process();
thepr.StartInfo = theinfo;
thepr.Start();

其中“themepath”是 aero.theme 的字符串位置。我什至将 CreateNoWindow 启用为 true,然后它也打开了个性化以更改主题,但没有自动关闭它。

4

2 回答 2

2

首先使用查找窗口通过使用查找窗口从其名称中获取窗口..

 [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName,string lpWindowName);

它会返回您想要的窗口的句柄,现在您可以使用发送消息来关闭它..

 [DllImport("User32.dll")]
    public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
    public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_CLOSE = 0xF060;
        private void closeWindow()
         {
          // retrieve the handler of the window  
            int iHandle = FindWindow("CabinetWClass", "Personalization");
            if (iHandle > 0)
             {
                 SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);  
             }  
          }   
于 2016-01-19T06:11:40.827 回答
0

您需要通过其名称获取窗口句柄,然后向其发送关闭消息。这可以防止不得不终止任何进程。有关获取窗口的信息,请参阅本文。看到这个从把手关闭窗户。

在查看代码并进行一些挖掘之后,您可以通过两次注册表编辑来完成此操作。您应该阅读这篇文章并让您的程序编辑有问题的两个注册表项。

于 2015-12-04T18:02:26.200 回答