Option ExplicitPrivate 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 = &H1Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Const WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2 Private Declare Sub ReleaseCapture Lib "User32" () Private Sub Form_Load() Dim rtn As Long Me.BorderStyle = 0 rtn = GetWindowLong(hWnd, GWL_EXSTYLE) rtn = rtn Or WS_EX_LAYERED SetWindowLong hWnd, GWL_EXSTYLE, rtn SetLayeredWindowAttributes Picture1.hWnd, 0, 200, LWA_ALPHA '将窗口设置透明度 SetLayeredWindowAttributes hWnd, &HFF0000, 0, LWA_COLORKEY '将扣去窗口中的蓝色
End SubPrivate Sub picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Call ReleaseCapture SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0& End If End Sub
Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long 说明 为当前的应用程序释放鼠标捕获 返回值 Long,TRUE(非零)表示成功,零表示失败 注解 我的理解:与SetCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
其实,,如果你把SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&这个句中的Me.hwnd ,,换成Picture1.hWnd的话,,你就可以托动Picture1在Form1中移动了。 *************************************** 对了,,你上面的问题解决了。 还有 我想让窗体像普通窗体一样显示在任务栏上 用 ShowInTaskbar=true 可以设置窗体显示在任务栏上 但是不显示窗体图标 而且在任务栏上右击程序在任务栏上的“按钮“不能弹出菜单 请问如何解决 ***************************************Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPrivate Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As LongPrivate Sub Command1_Click() Unload Me End SubPrivate Sub Form_Load() Dim lRgn As Long Me.ScaleMode = 3 lRgn = CreateRectRgn(5, 30, Me.ScaleWidth - 5, Me.ScaleHeight - 5) SetWindowRgn Me.hWnd, lRgn, True End Sub
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 = &H1Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Private Declare Sub ReleaseCapture Lib "User32" () Private Sub Form_Load()
Dim rtn As Long
Me.BorderStyle = 0
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes Picture1.hWnd, 0, 200, LWA_ALPHA '将窗口设置透明度
SetLayeredWindowAttributes hWnd, &HFF0000, 0, LWA_COLORKEY '将扣去窗口中的蓝色
End SubPrivate Sub picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Call ReleaseCapture
SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End If
End Sub
程序运行时,,你就会看到透明的效果了。
SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
窗体透明的api我明白了
但这两个拖动窗口的api分别是什么意思
我想让窗体像普通窗体一样显示在任务栏上
用 ShowInTaskbar=true 可以设置窗体显示在任务栏上
但是不显示窗体图标
而且在任务栏上右击程序在任务栏上的“按钮“不能弹出菜单
请问如何解决
说明
为当前的应用程序释放鼠标捕获
返回值
Long,TRUE(非零)表示成功,零表示失败
注解
我的理解:与SetCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
这个函数是发送系统消息的,,有很多的用处的!!!
这一句的用处就是相当于,首先,说明一下吧,,,很多控件都是window对象类,,,其中包括picture,command,text他们都是window对象类的,,说白了这些控件全都是window,它们都有标题栏(也就是caption)只不过咱们看不见罢了。我们再来说说这个句话的意思,,,
因为这个句是在picture1_MouseMove事件中,
也就是当用户用鼠标左键点击picture1的时候,相当于点击了form1的标题栏。HTCAPTION 就表示标题栏。WM_NCLBUTTONDOWN 就是发出一个鼠标左键按下的消息。。
OK??
***************************************
对了,,你上面的问题解决了。
还有
我想让窗体像普通窗体一样显示在任务栏上
用 ShowInTaskbar=true 可以设置窗体显示在任务栏上
但是不显示窗体图标
而且在任务栏上右击程序在任务栏上的“按钮“不能弹出菜单
请问如何解决
***************************************Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPrivate Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As LongPrivate Sub Command1_Click()
Unload Me
End SubPrivate Sub Form_Load()
Dim lRgn As Long
Me.ScaleMode = 3
lRgn = CreateRectRgn(5, 30, Me.ScaleWidth - 5, Me.ScaleHeight - 5)
SetWindowRgn Me.hWnd, lRgn, True
End Sub
Dim lRgn As Long
Me.ScaleMode = 3
lRgn = CreateRectRgn(5, 30, Me.ScaleWidth - 5, Me.ScaleHeight - 5)
SetWindowRgn Me.hWnd, lRgn, True
可以实现(borderstyle<>0),但是当拖拽Picture1,移动窗体时(释放左键)
窗体的边框(包括标题栏)就会闪现出来,随即消失
不管用不用这个方法,当鼠标移动到Picture1上去会有一个小点闪烁一下(我用的是window 2000 ,VB6)
把你的图片顶着边放!!!!! OK????
给分吧!!!!
我急着分用呢,,
再不给分,,不理你了!!!!!!!!!!!!!!!
给分!!