教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> VB >> 编程技巧 >> 在运行时显示或隐藏窗体的标题栏 RSS订阅
处理 SSI 文件时出错
在运行时显示或隐藏窗体的标题栏
处理 SSI 文件时出错
   这则代码告诉你如何在运行时显示或隐藏窗体的标题栏。要使一个窗口的标题栏消失,你必须去掉control box、最大化按钮和最小化按钮,并且将caption设为空。不幸的是,VB中窗体的ControlBox、MinButton和MaxButton属性在运行期是只读的,因此,你只能在设计时做这些事。其实,只要能熟练操作关于窗口式样的API,你同样能在运行时办到这一点。
  新建一个项目,把以下代码写入窗体:

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 Dont 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 

你可能需要在Form_Resize中加一点代码,因为客户区的大小已经改变:
Form_Resize 

End Function 


  为了试验一下代码,在窗体上放一个CheckBox,将它的Value属性设为1 (Checked)。然后写入以下代码:

Private Sub Check1_Click() 
  If (Check1.Value = Checked) Then 
  ShowTitleBar True 
  Else 
  ShowTitleBar False 
End If 
End Sub 

  运行,当你点击这个CheckBox时,窗体的标题栏将会在隐藏或显示之间切换。

来源:编程技术-十度教育
作者:
关键字:标题栏
发表日期:2006-10-18 13:46:34

处理 SSI 文件时出错

上一篇:把图片框的完整内容复制到剪贴板   下一篇:判别剪贴板上所有可用的格式


2008-9-7 8:05:01
本文的相类似文章
  • vb 获得标题栏的高度
  • 闪烁的标题栏
  • 拖动没有标题栏的窗体
  • 制作垂直标题栏的窗体
  • 闪烁的标题栏
  • 拖动没有标题栏的窗体
  • 制作垂直标题栏的窗体
  • 移动没有标题栏的窗口
  • 在运行时显示或隐藏窗体的标题栏
  • 用VB5 制作“闪烁标题栏”窗体
  • 在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com