【vb】只要程序窗口为活动窗口就截获剪贴板数据
作者&投稿:蒸委 (若有异议请与网页底部的电邮联系)
VB将剪贴板内容发送到指定窗口问题~
http://blog.csdn.net/xinbin1122/category/90621.aspx
=================================================
第13楼 回复人:yefanqiu 2003-07-09 08:13:32 返回顶部
'窗体子类化(声明部分,你自己声明)
'设置
Public Sub SetSubClass(lpHwnd As Long, lngX As Long, lngY As Long)
If Not m_Hook Then
m_hWnd = lpHwnd
m_PrevWndProc = SetWindowLong(lpHwnd, GWL_WNDPROC, AddressOf WindowProc)
m_Hook = True
End If
End Sub
'取消
Public Sub UnSubClass()
If m_Hook Then
Call SetWindowLong(m_hWnd, GWL_WNDPROC, m_PrevWndProc)
m_Hook = False
End If
End Sub
Private Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim mmiInfo As MINMAXINFO
If uMsg = WM_ACTIVATE Then
If (wParam = WA_ACTIVE Or wParam = WA_CLICKACTIVE) Then
'frmMain.lblTitle.ForeColor = &H246B& '窗口得到焦点时
frmMain.imgIcon.Picture = frmMain.imgICO(0).Picture
Else
'frmMain.lblTitle.ForeColor = RGB(50, 50, 50) '窗口失去焦点时
frmMain.imgIcon.Picture = frmMain.imgICO(1).Picture
End If
End If
WindowProc = CallWindowProc(m_PrevWndProc, hw, uMsg, wParam, lParam)
End Function
============================================
第二份资料:
自定义事件,比如自定义MyGotFoucs事件代替Form_GotFoucs.
How to use VB6.0's Event.
Creat a new class named Class1, it's codes like this:
Public Event MyEvent()
Public Sub RaiseTheEvent()
'some other codes here
RaiseEvent MyEvent
End Sub
Create a new form, draw a command on it named Command1, double the command to open the code.
It codes like this:
Option Explicit
Private WithEvents Myclass As class1
Private Sub Command1_Click()
Set Myclass = New class1
Call Myclass.RaiseTheEvent 'In this sub event is raised.
End Sub
Private Sub Myclass_MyEvent()'this is the sub to dill with the event.
MsgBox "class1's event occured."
End Sub
Start the application and Click the button will raise the event.
用API
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
按Alt+Print Screen键 ,笔记本记得加上Fn。
参考:http://www.graphics.net.cn/bbs/vb/0440/179.asphttp://blog.csdn.net/xinbin1122/category/90621.aspx
=================================================
第13楼 回复人:yefanqiu 2003-07-09 08:13:32 返回顶部
'窗体子类化(声明部分,你自己声明)
'设置
Public Sub SetSubClass(lpHwnd As Long, lngX As Long, lngY As Long)
If Not m_Hook Then
m_hWnd = lpHwnd
m_PrevWndProc = SetWindowLong(lpHwnd, GWL_WNDPROC, AddressOf WindowProc)
m_Hook = True
End If
End Sub
'取消
Public Sub UnSubClass()
If m_Hook Then
Call SetWindowLong(m_hWnd, GWL_WNDPROC, m_PrevWndProc)
m_Hook = False
End If
End Sub
Private Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim mmiInfo As MINMAXINFO
If uMsg = WM_ACTIVATE Then
If (wParam = WA_ACTIVE Or wParam = WA_CLICKACTIVE) Then
'frmMain.lblTitle.ForeColor = &H246B& '窗口得到焦点时
frmMain.imgIcon.Picture = frmMain.imgICO(0).Picture
Else
'frmMain.lblTitle.ForeColor = RGB(50, 50, 50) '窗口失去焦点时
frmMain.imgIcon.Picture = frmMain.imgICO(1).Picture
End If
End If
WindowProc = CallWindowProc(m_PrevWndProc, hw, uMsg, wParam, lParam)
End Function
============================================
第二份资料:
自定义事件,比如自定义MyGotFoucs事件代替Form_GotFoucs.
How to use VB6.0's Event.
Creat a new class named Class1, it's codes like this:
Public Event MyEvent()
Public Sub RaiseTheEvent()
'some other codes here
RaiseEvent MyEvent
End Sub
Create a new form, draw a command on it named Command1, double the command to open the code.
It codes like this:
Option Explicit
Private WithEvents Myclass As class1
Private Sub Command1_Click()
Set Myclass = New class1
Call Myclass.RaiseTheEvent 'In this sub event is raised.
End Sub
Private Sub Myclass_MyEvent()'this is the sub to dill with the event.
MsgBox "class1's event occured."
End Sub
Start the application and Click the button will raise the event.
《在VB中,如何把其他正在运行的窗口设为活动窗口》
答:在Vb 6.0版本中”工程“菜单下 2.选择“属性”菜单项 3在打开的对话框中选择“通用”选项卡 4 在“启用”列表框中选择要启动的表单 却可