none
怎样让窗体嵌入桌面? RRS feed

  • 问题

  • 我想让窗体在桌面上能显示,但处于最底层,包括桌面图标也处在它上面,其它一些窗口都在它上面。而且鼠标、键盘对它不起作用。只通过NotifyIcon的托盘来让它恢复成普通窗口后进行各种操作。请各位指点,如何实现?

    网上找了好多,都有一个同样的问题,就是其中me.hwnd有弯曲的下划线,不知道还要设置些什么?

    Public Class Form1
      Private Declare Function GetWindowInteger Lib "user32" Alias _
     "GetWindowIntegerA" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
      Private Declare Function SetWindowInteger Lib "user32" Alias _
       "SetWindowIntegerA" (ByVal hWnd As Integer, ByVal nIndex As Integer, _
       ByVal dwNewInteger As Integer) As Integer
      Private Declare Function SetLayeredWindowAttributes Lib "user32" _
       (ByVal hWnd As Integer, ByVal crKey As Integer, ByVal bAlpha As Byte, _
       ByVal dwFlags As Integer) As Integer
    
      Private Const GWL_EXSTYLE = (-20)
      Private Const WS_EX_LAYERED = &H80000
      Private Const WS_EX_TRANSPARENT = &H20&
      Private Const LWA_ALPHA = &H2&
    
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Style As Integer
        hwnd = CType(Me.Handle, Integer)
    
        Style = GetWindowInteger(Me.hWnd, GWL_EXSTYLE)
        Style = Style Or WS_EX_LAYERED Or WS_EX_TRANSPARENT
        SetWindowInteger(Me.hWnd, GWL_EXSTYLE, Style)
        SetLayeredWindowAttributes(Me.hWnd, 0, 255, LWA_ALPHA)
      End Sub
    End Class
    
    2011年4月6日 7:38

答案

全部回复