首页/技术开发/内容

对于用VB做更漂亮的窗体的思考

技术开发2024-06-03 阅读()
首先申明:以下纯属个人观点!

  近来VB版中有一部分人问关于界面的美化问题.其实作为一个菜鸟.我也无法提供很专业的代码给大家.想必大家对如下代码应该很熟悉吧!

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 SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
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 Sub Form_Load()
Me.BackColor = &HFF0000
Dim rtn As Long
BorderStyler = 0
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, &HFF0000, 0, LWA_COLORKEY
End Sub

--------------------------------------------

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, 2, 0

End Sub

这是美化窗体的时候很好的办法,比用编程语句描述一个特殊形状的窗体要简单的多,只要选自己合意的图片即可!

我们都知道象PICTUREBOX,COMBOX,菜单,等等其实都是窗体.由此可以推出我们可以用替换法将其替换.当然这是我的设想了;毕竟我不是高手.

举个例子:

我想做一个图形化的按纽.那么我们可以用IMAGE来摸拟.用IMAGELIST放三张图片用来表示MOUSE_ON,MOUSE_DOWN,MOUSE_UP.当然如果你要求高一点可以用API来弥补其中的不足,使之更完善.

当然象CHECKBOX,OPTIONS用IMAGE来模拟都足足有余.-------------

只要设一个全局变量为BOOLEAN就行了.它们只要两张图片就够了.自己画还是引用 就随你便了.

好了例子也举完了.总结一下:

我想说的就是其实做界面并不是技术高才能做的.转个圈其实用一些简单的方法也可以解决的.

只要大家敢想什么都会变成现实!

希望我也能抛砖引玉啊,当然前提是老大们能用啊^_^.

……

相关阅读