如何确定正确的非客户区尺寸的Aero? [英] How to determine correctly the Non-Client Area Size for Aero?

查看:158
本文介绍了如何确定正确的非客户区尺寸的Aero?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用C时,Aero是一个编译的应用程序激活了非客户区尺寸VBNET或C#$ C $正确的决定? (是的, 这个问题只在运行编译应用程序时,无法从IDE启动应用程序时出现

How to determine correctly with VBNET or C# code the Non-Client Area Size when Aero is activated for a COMPILED application? (Yes, this problem only occurs when running a compiled application, not when launching the app from the IDE)

当我调整自己的状态还是我做relationed与形式的高度/宽度任何操作,我从来没有得到预期的结果。

When I resize my form or I do any operation relationed with the height/width of the form I never get the expected result.

例如,这是中的两种形式的简单对接code部分:

For example this is a part of a code of a simple Docking of two forms:

VB-NET:

Me.Location = New Point((form1.Location.X + form1.Width), form1.Location.Y)

C#:

this.Location = new Point((form1.Location.X + form1.Width), form1.Location.Y);

要举个例子,我会告诉我的一个计划。

To give an example I'll show a program of mine.

在code以上运行perfectlly航空时未激活:

The code above runs perfectlly when Aero is not activated:

...但是,如果航空被激活,则其结果会是:

...But if Aero is activated then this is the result:

注意右边的形式是怎样的左表的非客户端下边框。

Notice how the form of the right is under the Non-Client border of the left Form.

...或者这里是其他图像,其中左形式是正确形式的非客户端下边框:

...Or here is other image where the left form is under the Non-Client border of the right form:

我的问题是这是解决这个方法?

更新:

扩展框架的解决方案是行不通的。

Extending the frame solution is not working.

Form1的:

Imports System.Runtime.InteropServices

Public Class Form1
    Public Moving_From_Secondary_Form As Boolean = False

    <DllImport("dwmapi.dll")> _
    Private Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef margins As MARGINS) As Integer
    End Function

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure MARGINS
        Public leftWidth As Integer
        Public rightWidth As Integer
        Public topHeight As Integer
        Public bottomHeight As Integer
    End Structure

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim margins As New MARGINS()
        margins.leftWidth = -1
        margins.rightWidth = -1
        margins.topHeight = -1
        margins.bottomHeight = -1
        DwmExtendFrameIntoClientArea(Me.Handle, margins)
        Form2.Show()
    End Sub

    Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Move
        If Not Moving_From_Secondary_Form Then Form2.Location = New Point(Me.Right, Me.Top)
    End Sub

End Class

窗体2:

Public Class Form2

    Private Sub Form2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Move
        Form1.Moving_From_Secondary_Form = True
        Form1.Location = New Point(Me.Left - Form1.Width, Me.Top)
        Form1.Moving_From_Secondary_Form = False
    End Sub

End Class

结果:

此外,我要记住: 这个问题只在运行编译应用程序时,不启动从IDE应用程序时出现

Also I want to remember: this problem only occurs when running a compiled application, not when launching the app from the IDE

**

更新:

**

测试GetWindowRect解决方案,并始终返回0,而不是为我工作,也许我做错了什么:

Tested the GetWindowRect solution and always return a 0, not working for me, maybe I'm doing something wrong:

Imports System.Runtime.InteropServices

Public Class Form1

    Private Declare Function GetWindowRect Lib "user32" (ByVal Handle As IntPtr, Rect As RECT) As Long
    Private Declare Function CopyRect Lib "user32" (DestRect As RECT, SourceRect As RECT) As Long

    <StructLayout(LayoutKind.Sequential)> _
    Structure RECT
        Public Left As Int32
        Public Top As Int32
        Public Right As Int32
        Public Bottom As Int32
    End Structure

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Form2.Show()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim rectWindow As RECT, rectCopy As RECT

        'Get the bounding rectangle of this window
        GetWindowRect(Me.Handle, rectWindow)
        'Copy the rectangle
        CopyRect(rectCopy, rectWindow)

        MsgBox("This form's width:" & (rectCopy.Right - rectCopy.Left).ToString & " pixels")
        Form2.Location = New Point(rectCopy.Right, rectCopy.Top)
    End Sub

End Class

**

更新:

**

另一种尝试使用GetWindowRect,此番code是正确的写,但不解决问题:

Another try with GetWindowRect, This time the code is correctly wrote but don't solve the problem:

Imports System.Runtime.InteropServices

Public Class Form1
    <StructLayout(LayoutKind.Sequential)> _
    Private Structure RECT
        Public Left As Int32
        Public Top As Int32
        Public Right As Int32
        Public Bottom As Int32
    End Structure

    Private Declare Function GetWindowRect Lib "user32" (ByVal HWND As Integer, ByRef lpRect As RECT) As Integer

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim rc As RECT
        GetWindowRect(MyBase.Handle, rc)
        Dim width As Integer = rc.Right - rc.Left
        Form2.Show()
        Form2.Location = New Point(rc.Right, rc.Top)
    End Sub

End Class

我要记住:只有运行在WIN7 / Vista中,从IDE启动应用程序而不是当

推荐答案

虽然我没有测试过这种个人可以延长帧到使用DwmExtendFrameIntoClientArea和传球-1客户区。

Although I've not tested this personally you can extend the frame into the client area using DwmExtendFrameIntoClientArea and passing -1.

在理论上,应该意味着大小/位置指定将包括框架。

In theory that should mean that the size/positions you specify will include the frame.

C#签名

[DllImport("dwmapi.dll", PreserveSig = true)]
static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);

[DllImport("dwmapi.dll", PreserveSig = false)]
static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);

VB.NET签名:

<DllImport("dwmapi.dll")> _
Private Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef margins As MARGINS) As Integer
End Sub

更新

你有没有想过设置表格边框样式为none,然后用一个按钮来控制关闭/最小化?有可能让你的结果其他选项后,你太 - FixedSingle FixedToolWindow

Have you thought about setting the forms border style to none and then using a button to control close/minimize? There are other options which might get you the result your after too - FixedSingle and FixedToolWindow

更新2

我设法重新您的问题,并与下面的code解决这个问题。在调试窗口位置偏斜,但在运行编译的exe时,窗口的位置是正确的。

I managed to recreate your problem and solve it with the following code. When debugging the window position is skewed but when running the compiled exe the window location is correct.

Dim BorderWidth = (Me.Width - Me.ClientSize.Width)
Me.Location = New Point((Form1.Location.X + (Form1.Width + BorderWidth)), Form1.Location.Y)

这篇关于如何确定正确的非客户区尺寸的Aero?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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