,VB   工具软件   办公软件   操作系统   网络安全   设计在线   程序开发   教程宝典   软件下载   软件论坛,VB
您的位置:软件 > 开发者网络 > 开发工具 > 开发专栏 > VB > 正文
用VB6建立带光栅的超级开始菜单
[文章信息]
作者:
时间:2005-04-06
出处:vb新世纪
责任编辑:方舟
[文章导读]
由于windows自身并未提供这项接口函数,因此我们必须从分析菜单的实质入手
advertisement
专题教程宝典
【软件应用】
【办公软件】
【图形图像】
【网页制作】
【操作系统】
【网络安全】
【程序开发】
【日报周刊】
【多媒体教程】
· 天极软件应用多媒体教程
· 游戏开发新手入门讲座
· 多媒体系列教程:网页设计制作
· 豪杰超级解霸V9使用手册(下)
· 打造个性化的Windows操作系统
· 图解Photoshop CS2 新功能体验
· 编程中的“拿来主义” 第三方控件推荐
· JBuilder 2005 单元测试体验
· 豪杰超级解霸V9使用手册(上)
· 数码照片后期处理与创意设计
[正文]

上一页  1 2  

  (3)选择“工程”菜单-“添加类模块”,命名为clogo,写入以下代码:

Option Explicit ’以下是令人眼花缭乱的win api引用

Private Type RECT
 left As Long
 tOp As Long
 Right As Long
 Bottom As Long
End Type

Private Declare Function FillRect Lib ″user32″ (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long) As Long

Private Declare Function CreateSolidBrush Lib ″gdi32″ (ByVal crColor As Long) As Long

Private Declare Function TextOut Lib ″gdi32″ Alias ″TextOutA″ (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long

Private Declare Function GetDeviceCaps Lib ″gdi32″ (ByVal hDC As Long, ByVal nIndex As Long) As Long

Private Const LOGPIXELSX = 88

Private Const LOGPIXELSY = 90

Private Declare Function MulDiv Lib ″kernel32″ (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long

Private Const LF_FACESIZE = 32

Private Type LOGFONT
 lfHeight As Long
 lfWidth As Long
 lfEscapement As Long
 lfOrientation As Long
 lfWeight As Long
 lfItalic As Byte
 lfUnderline As Byte
 lfStrikeOut As Byte
 lfCharSet As Byte
 lfOutPrecision As Byte
 lfClipPrecision As Byte
 lfQuality As Byte
 lfPitchAndFamily As Byte
 lfFaceName(LF_FACESIZE) As Byte
End Type

Private Declare Function CreateFontIndirect Lib ″gdi32″ Alias ″CreateFontIndirectA″ (lpLogFont As LOGFONT) As Long

Private Declare Function SelectObject Lib ″gdi32″ (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib ″gdi32″ (ByVal hObject As Long) As Long
Private Const FW_NORMAL = 400
Private Const FW_BOLD = 700
Private Const FF_DONTCARE = 0
Private Const DEFAULT_QUALITY = 0
Private Const DEFAULT_PITCH = 0
Private Const DEFAULT_CHARSET = 1
Private Declare Function OleTranslateColor Lib ″OLEPRO32.DLL″ (ByVal OLE_COLOR As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long
Private Const CLR_INVALID = -1
Private m_picThis As PictureBox
Private m_sCaption As String
Private m_bRGBStart(1 To 3) As Integer
Private m_oStartColor As OLE_COLOR
Private m_bRGBEnd(1 To 3) As Integer
Private m_oEndColor As OLE_COLOR ’api声明结束

 ’以下代码建立建立类模块的出入口函数

Public Property Let Caption(ByVal sCaption As String) ’
 m_sCaption = sCaption
End Property

Public Property Get Caption() As String ’标题栏文字
 Caption = m_sCaption
End Property

Public Property Let DrawingObject(ByRef picThis As PictureBox)‘指定目标图片
 Set m_picThis = picThis
End Property

Public Property Get StartColor() As OLE_COLOR ‘StartColor = m_oStartColor
End Property

Public Property Let StartColor(ByVal oColor As OLE_COLOR) ‘指定前段颜色
 Dim lColor As Long
 If (m_oStartColor <> oColor) Then
  m_oStartColor = oColor
  OleTranslateColor oColor, 0, lColor
  m_bRGBStart(1) = lColor And &HFF&
  m_bRGBStart(2) = ((lColor And &HFF00&) \ &H100)
  m_bRGBStart(3) = ((lColor And &HFF0000) \ &H10000)
  If Not (m_picThis Is Nothing) Then
   Draw
  End If
 End If
End Property
Public Property Get EndColor() As OLE_COLOR
 EndColor = m_oEndColor
End Property

Public Property Let EndColor(ByVal oColor As OLE_COLOR) ‘指定后段颜色
 Dim lColor As Long
 If (m_oEndColor <> oColor) Then
  m_oEndColor = oColor
  OleTranslateColor oColor, 0, lColor
  m_bRGBEnd(1) = lColor And &HFF&
  m_bRGBEnd(2) = ((lColor And &HFF00&) \ &H100)
  m_bRGBEnd(3) = ((lColor And &HFF0000) \ &H10000)
  If Not (m_picThis Is Nothing) Then
   Draw
  End If
 End If
End Property

Public Sub Draw() ‘画背景颜色
 Dim lHeight As Long, lWidth As Long
 Dim lYStep As Long
 Dim lY As Long
 Dim bRGB(1 To 3) As Integer
 Dim tLF As LOGFONT
 Dim hFnt As Long
 Dim hFntOld As Long
 Dim lR As Long
 Dim rct As RECT
 Dim hBr As Long
 Dim hDC As Long
 Dim dR(1 To 3) As Double
 On Error GoTo DrawError
 hDC = m_picThis.hDC
 lHeight = m_picThis.Height \ Screen.TwipsPerPixelY
 rct.Right = m_picThis.Width \ Screen.TwipsPerPixelY
 lYStep = lHeight \ 255
 If (lYStep = 0) Then
  lYStep = 1
 End If
 rct.Bottom = lHeight
 bRGB(1) = m_bRGBStart(1)
 bRGB(2) = m_bRGBStart(2)
 bRGB(3) = m_bRGBStart(3)
 dR(1) = m_bRGBEnd(1) - m_bRGBStart(1)
 dR(2) = m_bRGBEnd(2) - m_bRGBStart(2)
 dR(3) = m_bRGBEnd(3) - m_bRGBStart(3)
 For lY = lHeight To 0 Step -lYStep
  rct.tOp = rct.Bottom - lYStep
  hBr = CreateSolidBrush((bRGB(3) * &H10000 + bRGB(2) * &H100& + bRGB(1)))
  FillRect hDC, rct, hBr
  DeleteObject hBr
  rct.Bottom = rct.tOp
  bRGB(1) = m_bRGBStart(1) + dR(1) * (lHeight - lY) / lHeight
  bRGB(2) = m_bRGBStart(2) + dR(2) * (lHeight - lY) / lHeight
  bRGB(3) = m_bRGBStart(3) + dR(3) * (lHeight - lY) / lHeight
 Next lY
 pOLEFontToLogFont m_picThis.Font, hDC, tLF
 tLF.lfEscapement = 900
 hFnt = CreateFontIndirect(tLF)
 If (hFnt <> 0) Then
  hFntOld = SelectObject(hDC, hFnt)
  lR = TextOut(hDC, 0, lHeight - 16, m_sCaption, Len(m_sCaption))
  SelectObject hDC, hFntOld
  DeleteObject hFnt
 End If
 m_picThis.Refresh
Exit Sub
 DrawError:
 Debug.Print ″Problem: ″ & Err.Description
End Sub

Private Sub pOLEFontToLogFont(fntThis As StdFont, hDC As Long, tLF As LOGFONT) ‘文字字体
 Dim sFont As String
 Dim iChar As Integer
 With tLF
  sFont = fntThis.Name
  For iChar = 1 To Len(sFont)
   .lfFaceName(iChar - 1) =CByte(Asc(Mid$(sFont, iChar, 1)))
  Next iChar
  .lfHeight = -MulDiv((fntThis.Size), (GetDeviceCaps(hDC, LOGPIXELSY)), 72)
  .lfItalic = fntThis.Italic
  If (fntThis.Bold) Then
   .lfWeight = FW_BOLD
  Else
   .lfWeight = FW_NORMAL
  End If
  .lfUnderline = fntThis.Underline
  .lfStrikeOut = fntThis.Strikethrough
 End With
End Sub

Private Sub Class_Initialize()
 StartColor = &H0
 EndColor = vbButtonFace
End Sub ‘模块定义结束

  调试、运行。

上一页  1 2  

发表评论推荐给朋友我想参加相关培训打印我对此感兴趣订阅电子杂志
天极社区邀请您:写博客日记  上传相片   论坛聊天  订阅电子杂志  推荐网摘   免费图铃工具
笔名:   请您注意:

 遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。

 天极网拥有管理笔名和留言的一切权利。
评论:
 
,VB相关内容,VB焦点新闻
  • 用Visual Basic创建多线程应用程序
  • 在VB中调用CHM 帮助的几种方法
  • Visual Basic创建“五星”级控件
  • Visual Basic 的常见问题及解答
  • 让Visual Basic应用程序支持鼠标滚轮
  • FVD刺激高清碟机加速商业化 抢占商机最重要
  • 3家搜索引擎集体诉讼8848 吕春维未敢出席
  • 杨元庆:没有准备不会获批的备用方案
  • 军队信息化诞生新领域 电子军务呼之欲出
  • 世界经济论坛公布信息化程度全球最新排名
  • 2004政务绩效评估:政府门户尚处于发展阶段
  • 甲骨文出资5.15亿美元 意图收购RetekInc
  • 技术并购:帮你突破传统增长的“天花板”
  • ,VBAdvertisement