Using WM_SHOWWINDOW to display a window instead of ShowWindow ()

I am trying to use the SendMessage function of a hotkey utility (or NirCMD, etc.) to open a hidden window. For example, I can close the windows by sending 0x0010 (WM_CLOSE), but when I try to send 0x0018 (WM_SHOWWINDOW) with wParam 1 and lParam of 0, nothing will happen.

Ive looked around, and in several places where someone complained that WM_SHOWWINDOW was not working, they gladly accepted the offer to use ShowWindow ().

However, I do not have ShowWindow (); I can only send windows messages. But ShowWindow () is not magic, of course, it works using SendMessage - WM_SHOWWINDOW or something under the covers.

How can I get a window to display myself by sending him a message?

Thank.

+3
source share
3 answers

Try these two posts:

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

Or if using third-party apps is ok try cmdow

+3
source

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

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

I do not believe that there is any message that you can use to create a window. Actually, the idea itself seems a little strange to me. Window Manager is the system component responsible for displaying and hiding windows. To show the window, you must use one of the window manager APIs.

+2
source

I think I could not achieve this with SendMessage(WM_SYSCOMMAND did not work for me). I tried actually in C #. You press the button, the window will be minimized with ShowWindow(), and then you will see which 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);
        }
    }
}   
0
source

Source: https://habr.com/ru/post/1762959/


All Articles