有时候我们想通过程序进行窗口的显示与隐藏,这时候只要简单地设置窗口样式即可(样式包括style和exStyle):
//改变窗口样式和显示 var newStyle1 = WindowStyles1.WS_POPUP | WindowStyles1.WS_VISIBLE | WindowStyles1.WS_CLIPSIBLINGS | WindowStyles1.WS_CLIPCHILDREN | WindowStyles1.WS_SYSMENU | WindowStyles1.WS_THICKFRAME | WindowStyles1.WS_MINIMIZEBOX | WindowStyles1.WS_MAXIMIZEBOX; var newExtendStyle = WindowStylesEx1.WS_EX_LEFT | WindowStylesEx1.WS_EX_LTRREADING | WindowStylesEx1.WS_EX_RIGHTSCROLLBAR | WindowStylesEx1.WS_EX_WINDOWEDGE | WindowStylesEx1.WS_EX_LAYERED; var r = Win32Wrapper.SetWindowLong((IntPtr) myHandle, WindowLong.GWL_EXSTYLE, (uint) newExtendStyle); var r2 = Win32Wrapper.SetWindowPos((IntPtr) myHandle, HWndValues.HWND_TOP, 0, 0, 0, 0, SetWindowPosOptions.SWP_NOSIZE | SetWindowPosOptions.SWP_NOMOVE | SetWindowPosOptions.SWP_FRAMECHANGED | SetWindowPosOptions.SWP_SHOWWINDOW); var r3 = Win32Wrapper.SetWindowLong((IntPtr) myHandle, WindowLong.GWL_STYLE, (uint) newStyle1); var r4 = Win32Wrapper.SetWindowPos((IntPtr) myHandle, HWndValues.HWND_TOP, 0, 0, 0, 0, SetWindowPosOptions.SWP_NOSIZE | SetWindowPosOptions.SWP_NOMOVE | SetWindowPosOptions.SWP_FRAMECHANGED | SetWindowPosOptions.SWP_SHOWWINDOW);
界面图如下(根据主进程名字找到进程的mainWindow,然后在窗口的某个坐标下模拟点击事件):
源码下载:https://files.cnblogs.com/files/lizhijian/2020-8-18-Win32%E6%A8%A1%E6%8B%9F%E7%82%B9%E5%87%BB%E7%AA%97%E5%8F%A3%E6%8E%A7%E5%88%B6-%E9%80%9A%E8%BF%87%E8%AE%BE%E7%BD%AE%E7%AA%97%E4%BD%93%E6%A0%B7%E5%BC%8F%E6%8E%A7%E5%88%B6.rar