如何在程序中实现窗体的最大化?

jiuweixie 2002-03-19 09:26:02
我现有一个窗体(BorderStyle=2:sizeable),我想在程序中将其最大化,并且不要标题栏,即样子像(BorderStyle=0),该如何实现?是不是得用SetWindowLong,但我用不好使,请高手指教!最好给出详细的代码!
谢谢!
...全文
85 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxlroad 2002-03-19
  • 打赏
  • 举报
回复
Private Sub Form_Load()
'设置 form 的 BorderStyle = 0
Left = 0
Top = 0
Width = Screen.Width
Height = Screen.Height
End Sub
alex_xxx 2002-03-19
  • 打赏
  • 举报
回复
BorderStyle=0

form1_load()
form1.top=0
form1.left=0
form1.width=screen.width
form1.height=screen.height
lily0000000 2002-03-19
  • 打赏
  • 举报
回复
你既然知道BorderStyle=0,那就直接用它好了嘛
lqf 2002-03-19
  • 打赏
  • 举报
回复
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000   ' WS_BORDER 或 WS_DLGFRAME
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000

Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Enum ESetWindowPosStyles
  SWP_SHOWWINDOW = &H40
  SWP_HIDEWINDOW = &H80
  SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
  SWP_NOACTIVATE = &H10
  SWP_NOCOPYBITS = &H100
  SWP_NOMOVE = &H2
  SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering
  SWP_NOREDRAW = &H8
  SWP_NOREPOSITION = SWP_NOOWNERZORDER
  SWP_NOSIZE = &H1
  SWP_NOZORDER = &H4
  SWP_DRAWFRAME = SWP_FRAMECHANGED
  HWND_NOTOPMOST = -2
End Enum

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Function ShowTitleBar(ByVal bState As Boolean)
Dim lStyle As Long
Dim tR As RECT

  ' 获取窗口的位置:
  GetWindowRect Me.hwnd, tR

  ' 调整标题栏是否可见:
  lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
  If (bState) Then
  Me.Caption = Me.Tag
  If Me.ControlBox Then
    lStyle = lStyle Or WS_SYSMENU
  End If
  If Me.MaxButton Then
    lStyle = lStyle Or WS_MAXIMIZEBOX
  End If
  If Me.MinButton Then
    lStyle = lStyle Or WS_MINIMIZEBOX
  End If
  If Me.Caption <> "" Then
    lStyle = lStyle Or WS_CAPTION
  End If
  Else
  Me.Tag = Me.Caption
  Me.Caption = ""
  lStyle = lStyle And Not WS_SYSMENU
  lStyle = lStyle And Not WS_MAXIMIZEBOX
  lStyle = lStyle And Not WS_MINIMIZEBOX
  lStyle = lStyle And Not WS_CAPTION
End If
SetWindowLong Me.hwnd, GWL_STYLE, lStyle

' 重新设定窗口:
SetWindowPos Me.hwnd, 0, tR.Left, tR.Top, tR.Right - tR.Left, tR.Bottom - tR.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
Me.Refresh

End Function
Private Sub Command1_Click()
  form1.windowstate=2
  ShowTitleBar false  
End Sub

Private Sub Command2_Click()
  form1.windowstate=2
  ShowTitleBar true 
End Sub

mmccmmcc 2002-03-19
  • 打赏
  • 举报
回复
一句话 form.windowstate=2 就搞定了 你们不要误人子弟好吗???老兄

连delphi的语法都上来了 我晕
lqf 2002-03-19
  • 打赏
  • 举报
回复
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = &H2
Private Const SWP_DRAWFRAME = &H20
Private Const GWL_STYLE = (-16)
Private Const WS_THICKFRAME = &H40000
Private Const WS_DLGFRAME = &H400000
Private Const WS_POPUP = &H80000000
Private Const WS_CAPTION = &HC00000
Private Const WS_SYSMENU = &H80000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZE = &H20000000
Private Const WS_MAXIMIZE = &H1000000
jiuweixie 2002-03-19
  • 打赏
  • 举报
回复
有没有搞错,我想的是要在程序运行时由程序自己改变窗体的大小,而像上面的那样是不可能改变的!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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