使用 WM_SHOWWINDOW 显示窗口而不是 ShowWindow()

发布于 2024-09-16 23:43:48 字数 390 浏览 2 评论 0原文

我正在尝试使用热键实用程序(或 NirCMD 等)的 SendMessage 功能来弹出隐藏窗口。例如,我可以通过发送 0x0010 (WM_CLOSE) 来关闭窗口,但是当我尝试发送 wParam 为 1 且 lParam 为 0 的 0x0018 (WM_SHOWWINDOW) 时,什么也没有发生。

我环顾四周,发现有人抱怨 WM_SHOWWINDOW 不起作用的少数地方,他们很高兴地接受了使用 ShowWindow() 的建议。

但是我没有 ShowWindow() 可用;我只能发送 Windows 消息。但 ShowWindow() 并不神奇,它肯定是通过 SendMessage-ing WM_SHOWWINDOW 或幕后的东西来工作的。

如何通过向窗口发送消息来使其自动显示?

谢谢。

I’m trying to use the SendMessage function of a hotkey utility (or NirCMD, etc.) to get a hidden window to pop up. I can for example get windows to close by sending 0x0010 (WM_CLOSE), but when I try sending 0x0018 (WM_SHOWWINDOW) with a wParam of 1 and an lParam of 0, nothing happens.

I’ve looked around, and the few places where someone complained that WM_SHOWWINDOW did not work, they happily took the suggestion to use ShowWindow() instead.

However I don’t have ShowWindow() available; I can only send Windows messages. But ShowWindow() is not magic, surely it works by SendMessage-ing a WM_SHOWWINDOW or something under the covers.

How can I get a window to display itself by sending it a message?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

就像说晚安 2024-09-23 23:43:48

尝试这两条消息:

SendMessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0);
SendMessage(h,WM_SYSCOMMAND,SC_RESTORE,0);

或者,如果可以使用第 3 方应用程序,请尝试 cmdow

Try these two messages:

SendMessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0);
SendMessage(h,WM_SYSCOMMAND,SC_RESTORE,0);

Or if using 3rd party apps is ok, try cmdow

葬花如无物 2024-09-23 23:43:48

WM_SHOWWINDOW 是一个通知,而不是一个命令。来自 MSDN:

当窗口即将隐藏或显示时,将向窗口发送 WM_SHOWWINDOW 消息。

我不相信有任何消息可以用来让窗口自动显示。事实上,这个想法对我来说似乎有点奇怪。窗口管理器是负责显示和隐藏窗口的系统组件。要显示窗口,您必须使用窗口管理器 API 之一。

WM_SHOWWINDOW is a notification, not a command. From MSDN:

The WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown.

I don't believe there is any message that you can use to make a window show itself. Actually, the very idea seems a little strange to me. The window manager is the system component responsible for showing and hiding windows. To show a window, you must use one of the window manager APIs.

拿命拼未来 2024-09-23 23:43:48

我认为使用 SendMessage 无法没有办法实现这一点(WM_SYSCOMMAND 对我不起作用)。我实际上在 C# 中尝试过。单击该按钮,窗口将通过 ShowWindow() 最小化,然后您可以看到发送了哪些消息:

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class Form1: Form
    {
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool ShowWindow(IntPtr window, int showCommand);

        private const int SW_MINIMIZE = 6;
        private bool print = false;

        public Form1()
        {
            Button button = new Button();
            button.Click += onButtonsClick;
            Controls.Add(button);
        }

        private void onButtonsClick(object sender, EventArgs e)
        {
            print = true;
            ShowWindow(Handle, SW_MINIMIZE);
            print = false;
        }

        protected override void WndProc(ref Message m)
        {
            if (print)
                Console.WriteLine(m.Msg.ToString() + "\t0x" + m.Msg.ToString("x4") + "\t" + m.WParam + "\t" + m.LParam);
            base.WndProc(ref m);
        }
    }
}   

I think there is no way to achieve that with SendMessage (WM_SYSCOMMAND didn't work for me). I tried actually in C#. You click the button, the window will be minimized via ShowWindow() and then you can see what messages are sent:

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class Form1: Form
    {
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool ShowWindow(IntPtr window, int showCommand);

        private const int SW_MINIMIZE = 6;
        private bool print = false;

        public Form1()
        {
            Button button = new Button();
            button.Click += onButtonsClick;
            Controls.Add(button);
        }

        private void onButtonsClick(object sender, EventArgs e)
        {
            print = true;
            ShowWindow(Handle, SW_MINIMIZE);
            print = false;
        }

        protected override void WndProc(ref Message m)
        {
            if (print)
                Console.WriteLine(m.Msg.ToString() + "\t0x" + m.Msg.ToString("x4") + "\t" + m.WParam + "\t" + m.LParam);
            base.WndProc(ref m);
        }
    }
}   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文