求C#无边框窗体最大化后不档住任务栏的解决办法

littlelam 2008-10-16 11:18:06

Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib ""user32"" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib ""user32"" Alias ""FindWindowA"" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib ""user32"" Alias ""FindWindowExA"" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetDesktopWindow Lib ""user32"" () As Long

Private Sub Command1_Click()
Me.WindowState = 2
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()
Dim hTaskBar As Long
hTaskBar = FindWindow(""Shell_TrayWnd"", vbNullString)
Debug.Print hTaskBar
Dim RC As RECT
Dim i As Long
i = GetWindowRect(hTaskBar, RC)
Dim taskheight As Long
taskheight = RC.Bottom - RC.Top '任务栏高度
i = GetWindowRect(GetDesktopWindow, RC)
Dim maxwidth As Long
Dim maxheight As Long
maxwidth = RC.Right - RC.Left '获取屏幕宽度
maxheight = RC.Bottom - RC.Top - taskheight '屏幕高度-任务栏高度
LockWindow Me.hwnd, , , maxwidth, maxheight
End Sub

模块代码:
Option Explicit

Public Type POINTAPI
x As Long
y As Long
End Type

Public Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type

Public Declare Sub CopyMemory Lib ""kernel32"" Alias ""RtlMoveMemory"" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function CallWindowProc Lib ""user32"" Alias ""CallWindowProcA"" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Function SetWindowLong Lib ""user32"" Alias ""SetWindowLongA"" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SendMessage Lib ""user32"" Alias ""SendMessageA"" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_GETMINMAXINFO = &H24
Public Const GWL_WNDPROC = -4

Global lpPrevWndProc As Long
Public procOld As Long
Public udtMMI As MINMAXINFO

Public Function WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_GETMINMAXINFO
Dim udtMINMAXINFO As MINMAXINFO
CopyMemory udtMINMAXINFO, ByVal lParam, 40&
With udtMINMAXINFO
.ptMaxSize.x = udtMMI.ptMaxSize.x
.ptMaxSize.y = udtMMI.ptMaxSize.y
.ptMaxPosition.x = 0
.ptMaxPosition.y = 0
.ptMaxTrackSize.x = .ptMaxSize.x
.ptMaxTrackSize.y = .ptMaxSize.y
.ptMinTrackSize.x = udtMMI.ptMinTrackSize.x
.ptMinTrackSize.y = udtMMI.ptMinTrackSize.y
Debug.Print .ptMaxSize.x & "","" & .ptMaxSize.y
End With
CopyMemory ByVal lParam, udtMINMAXINFO, 40&
WindowProc = False
Exit Function
End Select
WindowProc = CallWindowProc(procOld, hwnd, iMsg, wParam, lParam)
End Function

Public Function LockWindow(hwnd As Long, Optional MinWidth As Long, Optional MinHeight As Long, Optional maxwidth As Long, Optional maxheight As Long) As Boolean
With udtMMI
'指定窗体最小宽度
If MinWidth = 0 Then .ptMinTrackSize.x = 0 Else .ptMinTrackSize.x = MinWidth
'指定窗体最小高度
If MinHeight = 0 Then .ptMinTrackSize.y = 0 Else .ptMinTrackSize.y = MinHeight
'指定窗体最大宽度
If maxwidth = 0 Then .ptMaxSize.x = Screen.Width \ Screen.TwipsPerPixelX Else .ptMaxSize.x = maxwidth
'指定窗体最大高度
If maxheight = 0 Then .ptMaxSize.y = Screen.Width \ Screen.TwipsPerPixelX Else .ptMaxSize.y = maxheight
End With
procOld = SetWindowLong(hwnd, -4, AddressOf WindowProc)
End Function

上面一个是VB.NET的
求C#无边框窗体最大化后不档住任务栏的解决办法
...全文
1220 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ericly 2012-08-31
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 的回复:]

Me.MaximizeBox = False
Me.MaximizedBounds = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea
[/Quote]


可以在窗体组件初始化完后,加入
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;

this.Size = Screen.PrimaryScreen.WorkingArea.Size;
niulei 2011-04-21
  • 打赏
  • 举报
回复
Me.MaximizeBox = False
Me.MaximizedBounds = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea
miss987 2009-07-22
  • 打赏
  • 举报
回复
得分回复需要阅读
wangyanboq 2008-10-16
  • 打赏
  • 举报
回复
还有一种方法是在form的form.designer.vb中设置
me.MaxinumSize = new System.Drawing.Size(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height)
littlelam 2008-10-16
  • 打赏
  • 举报
回复
原来能设置。。。。
MaximizedBounds
shangwei97 2008-10-16
  • 打赏
  • 举报
回复
关注,应该不会太难吧,
我做windows mobile 的全屏
wangyanboq 2008-10-16
  • 打赏
  • 举报
回复
ME.MaximizedBounds=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
CloneCenter 2008-10-16
  • 打赏
  • 举报
回复
无边框的窗体,你如何最大化?用代码?用户肯定是没有办法操作的。

所以这里就不要想什么最大化了,修改一下窗体的 Size 即可!Top和Left属性设置为-1,Width和Height设置为Screen.WorkingArea.Width + 2和 Height + 2。试试看……
liujb526 2008-10-16
  • 打赏
  • 举报
回复
呵呵,帮顶顺便学习
ZengHD 2008-10-16
  • 打赏
  • 举报
回复
晕,标题有歧义啊

littlelam 2008-10-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cpio 的回复:]
主要是最大化后,把窗口置前
[/Quote]
我不是要最前,是不要 档住任务栏
和普通窗口最大化一样的效果,也就是不要全屏
wangxiao2008 2008-10-16
  • 打赏
  • 举报
回复
学习一下
ZengHD 2008-10-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cpio 的回复:]

新建一个窗口,放一个button,就两行代码就可以的,你试试看
private void button1_Click(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}
[/Quote]
呵呵,我也想到这个方法了

cpio 2008-10-16
  • 打赏
  • 举报
回复
要是还不放心,可以置顶


FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;

TopMost = true;//置顶
cpio 2008-10-16
  • 打赏
  • 举报
回复

新建一个窗口,放一个button,就两行代码就可以的,你试试看
private void button1_Click(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}
cpio 2008-10-16
  • 打赏
  • 举报
回复
主要是最大化后,把窗口置前

110,530

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧