如何更改应用程序外部表单的窗口样式?
如何更改应用程序外部表单的窗口样式?很难回答?
我实际上正在尝试移动一个表单,女巫位于最上面并且没有边框。
我有窗口的句柄(hWnd)。
如果保证可以工作,我可以编写数千行代码。
how to change the window style of a form outside your app?hard question?
i am actually trying to move a form witch is topmost and has no border.
i have the handle(hWnd) of the window.
i can write thousands of lines of code if guaranteed to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设此窗口可以来自任何类型的基于 Win32 的运行时生成的任何应用程序,那么看起来您必须诉诸核心 Win32 api 的 p/invoke 来进行窗口操作。
例如,您可以使用 SetWindowPos,可以从 user32.dll 导入。它的签名是这样的:
我不会假设您之前已经完成了 ap/invoke import,所以让我们从顶部开始。让我们猛击一个 Windows 窗体应用程序:
1) 创建一个 Windows 窗体应用程序,然后将这些声明添加到 Form1 类中:
p/invoke Win32 windows 方法的烦人之处在于,您必须开始导入各种数字常量等Win32 使用 - 因此事先所有的口号。
请参阅 SetWindowPos 方法的 MSDN 链接,了解它们的作用的说明。
2) 向名为 cmdMakeHidden 的窗体添加一个按钮,然后按如下方式编写处理程序:
将“this.Handle”替换为您选择的窗口句柄以隐藏该窗口。
此方法实际上用于一次应用多个更改,因此需要使用一些
SWP_NO*
选项。例如,您应该指定 SWP_NOSIZE,否则为 cx 和 cy 传递 0 将导致窗口宽度和高度同时缩小到零。要演示移动窗口,请在窗体中添加另一个名为 cmdMove 的按钮,然后按如下所示编写单击处理程序:
每当您单击该按钮时,此代码都会将窗体移动到 100,100。
再次,根据需要替换 this.Handle。这里的 HWND_TOP 是完全可选的,因为已使用 SWP_NOZORDER 和 SWP_NOREPOSITION 标志禁用重新排序。
希望这可以帮助您走上正轨!
Assuming that this window could be from any app produced from any kind of Win32-based runtime, it looks like you'll have to resort to p/invoke of the core Win32 apis for window operations.
For example, you could use SetWindowPos, which can be imported from user32.dll. It's signature is this:
I'm not going to assume that you've done a p/invoke import before, so let's go from the top. Let's just bash out a windows forms app:
1) Create a windows forms app and then add these declarations to the Form1 class:
The annoying thing with p/invoke of Win32 windows methods is that you then have to start importing various numeric constants etc that Win32 uses - hence all the gumph beforehand.
Refer to the MSDN link for the SetWindowPos method for an explanation of what they do.
2) Add a button to the form called cmdMakeHidden and then write the handler as follows:
Replace the 'this.Handle' with the window handle of your choice to hide that window.
This method is actually used to apply multiple changes at once, hence the need to use some of the
SWP_NO*
options. For example, you should specify SWP_NOSIZE otherwise passing 0 for cx and cy will cause the window to shrink to zero width and height at the same time.To demonstrate moving a window, add another button your form called cmdMove and then write the click handler as follows:
This code moves your form to 100,100 whenever you hit the button.
Again, replace the this.Handle as you see fit. HWND_TOP here is completely optional, since reordering has been disabled with the SWP_NOZORDER and SWP_NOREPOSITION flags.
Hope this helps get you on the right track!