調用API讓VB實現透明表單

來源:互聯網
上載者:User
Private Declare Function GetWindowLong()Function GetWindowLong Lib "user32" Alias "GetWindowLongA" 

(ByVal hwnd As Long,ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong()Function SetWindowLong Lib "user32" Alias "SetWindowLongA"

(ByVal hwnd As Long,ByVal nIndex As Long,ByVal dwNewLong As Long) As Long 

Private Declare Function SetLayeredWindowAttributes()Function SetLayeredWindowAttributes Lib "user32"

(ByVal hwnd As Long,ByVal crKey As Long,ByVal bAlpha As Byte,ByVal dwFlags As Long)As Long  


'其中hwnd是透明表單的控制代碼,crKey為顏色值,bAlpha是透明度,   
'取值範圍是[0,255],dwFlags是透明方式,可以取兩個值:當取值為LWA_ALPHA時,   
'crKey參數無效,bAlpha參數有效;當取值為LWA_COLORKEY時,bAlpha參數有效而   
'表單中的所有顏色為crKey的地方將變為透明--這個功能很有用:我們不必再為建立   
'不規則形狀的表單而調用一大堆地區分析、建立、合并函數了,只需指定透明處的顏色'   
'值即可,哈哈哈哈!請看具體代碼。   


Private Const WS_EX_LAYERED = &H80000   
Private Const GWL_EXSTYLE = (-20)   
Private Const LWA_ALPHA = &H2   
Private Const LWA_COLORKEY = &H1   


'代碼一:   一個半透明表單   
Private Sub Form_Load()Sub Form_Load()   
  Dim rtn As Long   
  rtn = GetWindowLong(hwnd,   GWL_EXSTYLE)   
  rtn = rtn Or WS_EX_LAYERED   
  SetWindowLong hwnd, GWL_EXSTYLE, rtn   
  SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA   
End Sub   
    
'代碼二:   形狀不規則的表單   
'Private Sub Form_Load()   
'  Dim rtn As Long   
'  BorderStyler = 0   
'  rtn = GetWindowLong(hwnd, GWL_EXSTYLE)   
'  rtn = rtn Or WS_EX_LAYERED   
'  SetWindowLong hwnd, GWL_EXSTYLE, rtn   
'  SetLayeredWindowAttributes hwnd,RGB(255,0,0),0,LWA_COLORKEY'將扣去視窗中的紅色   
'End Sub

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.