明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

對于用VB做更漂亮的窗體的思考

[摘要]首先申明:以下純屬個人觀點!  近來VB版中有一部分人問關于界面的美化問題.其實作為一個菜鳥.我也無法提供很專業(yè)的代碼給大家.想必大家對如下代碼應該很熟悉吧!Private Declare Func...
首先申明:以下純屬個人觀點!

  近來VB版中有一部分人問關于界面的美化問題.其實作為一個菜鳥.我也無法提供很專業(yè)的代碼給大家.想必大家對如下代碼應該很熟悉吧!

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就行了.它們只要兩張圖片就夠了.自己畫還是引用 就隨你便了.

好了例子也舉完了.總結(jié)一下:

我想說的就是其實做界面并不是技術高才能做的.轉(zhuǎn)個圈其實用一些簡單的方法也可以解決的.

只要大家敢想什么都會變成現(xiàn)實!

希望我也能拋磚引玉啊,當然前提是老大們能用啊^_^.