我可以使用P / Invoke更改最大化函数的行为吗? [英] Can I change the behavior of the maximize function using P/Invoke?

查看:70
本文介绍了我可以使用P / Invoke更改最大化函数的行为吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近在C#WPF应用程序中使用DllImports和P / Invoke调用,并发现它们非常有用。但是,我想知道,当它最大化时,是否可以使用它来改变窗口的行为?比如,更改最大化的客户端窗口?

例如,当窗口最大化时,它会占用整个屏幕区域减去底部的任务栏。对于我的应用程序,我希望创建一个停靠在屏幕顶部的工具栏。我已经将它设置为最底层的形式,这使得任务栏在加载时消失。然而,当窗口最大化时,它只是重叠工具栏。我希望我的工具栏就像停靠在屏幕顶部的任务栏一样。我希望窗口调整大小,使它的顶部位置与工具栏的底部对齐,并调整大小以占用整个窗口减去我的工具栏。我希望这一切都有意义......任何想法?谢谢。

So I''ve been recently toying around with DllImports and P/Invoke calls in my C# WPF application, and have found them to be quite useful. However, I was wondering, is it possible to use this to change the behavior of a window when it is maximized? Like, change the client window which it is being maximized in?
For example, when a window is maximized, it takes up the full screen area minus the taskbar at the bottom. For my application, I wish to create a toolbar that docks at the top of the screen. I have already set it as the bottommost form, that makes the taskbar disappear when it loads. Yet when a window is maximized, it simply overlaps the toolbar. I want my toolbar to act as if it were the taskbar docked to the top of your screen. I want the window to resize so it''s top position is aligned with the bottom of the toolbar, and it resizes to take up the full window minus my toolbar. I hope this is all making sense... any ideas? Thanks.

推荐答案

您不需要使用P / Invoke来实现此类行为。没有一些非常令人信服的理由使用P / Invoke是非常糟糕的事情。您严重冒险平台兼容性,特别是对于未来,何时 - 谁知道? - WPF可能会在许多其他(非Microsoft)平台上实现,因为它恰好是Mono的 System.Windows.Forms 。即使你不关心它,它也会增加其他不兼容性的变化或只是bug。



你的布局应该足够流畅,适用于几乎所有的窗口大小,即使你没有最大化。如果你想停靠某些东西,那就有码头面板。请参阅: http://wpftutorial.net/DockPanel.html [ ^ ]。



还有很多其他布局功能,所以问题是在窗口改变大小时保持适当的布局完全超出范围。这根本不是问题。如果你的设计不是这样,那从一开始就是错的。请注意,您甚至不需要编写任何代码来处理调整大小事件,但这是另一种可能性。你根本不需要它。这是一个主题:如何忘记P / Invoke并开始编程。通过学习布局和其他基础知识。



祝你好运,

-SA
You don''t need to use P/Invoke to implement such behavior. It''s pretty bad thing to use P/Invoke without some really compelling reason. You seriously risk platform compatibility, especially for future, when — who knows? — WPF might be implemented for many other (non-Microsoft) platforms, as it happened to System.Windows.Forms for Mono. Even if you don''t care about it, it increase the change of other incompatibilities or just bugs.

You layout should be fluid enough and work for nearly all window sized, even if you don''t maximize. If you want to dock something, there are the dock panels. Please see: http://wpftutorial.net/DockPanel.html[^].

There are many other layout features, so the problem of keeping proper layout while the window changes the size is totally out of scope. This is not a problem at all. If it''s not the case in your design, it''s wrong from the very beginning. Note that you even don''t need to write any code to handle resize events, but this is another possibility. You just don''t need it for your purpose. This is about one topic: "how to forget P/Invoke and start programming". By learning layout and other basics.

Good luck,
—SA

看看处理 WM_GETMINMAXINFO 和/或 WM_NCCALCSIZE 消息。然后你应该能够做你想做的事。
Take a look at handling the WM_GETMINMAXINFO and/or the WM_NCCALCSIZE messages. You should then be able to do what you want.


这篇关于我可以使用P / Invoke更改最大化函数的行为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆