|
发表于 2005-1-6 11:37:00
|
显示全部楼层
9. 为程序注册热键
方法一:修改注册表
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id _
As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id _
As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, _ ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal _ wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
' 声明常数
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private HotKey_Fg As Boolean
Private Sub Form_Load()
Dim Message As Msg
'注册 Ctrl+Y 为热键
RegisterHotKey Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyY
'RegisterHotKey Me.hWnd, &HBFF2&, MOD_CONTROL, vbKeyU
Me.Show
Form1.Hide
'等待处理消息
HotKey_Fg = False
Do While Not HotKey_Fg
'等待消息
WaitMessage
'检查是否热键被按下
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
Form1.Show 1
End If
'转让控制权,允许操作系统处理其他事件
DoEvents
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
HotKey_Fg = True
'撤销热键的注册
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
方法二:SendMessage
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_SETHOTKEY = &H32
Private Const HOTKEYF_SHIFT = &H1
Private Const HOTKEYF_ALT = &H4
Private Sub Form_Load()
Dim l As Long
Dim wHotkey As Long
wHotkey = (HOTKEYF_ALT) * (2 ^ 8) + 65 '定义ALT+A为热键
l = SendMessage(Me.hwnd, WM_SETHOTKEY, wHotkey, 0)
End Sub
10.在状态栏显示无边框窗体图标。
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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd _ As Long, ByVal nIndex As Long) As Long
Const GWL_STYLE = (-16&)
Const WS_SYSMENU = &H80000
Private Sub Form_Load()
'Make Form's Icon visible in the taskbar
SetWindowLong Me.hWnd, GWL_STYLE, GetWindowLong(Me.hWnd, GWL_STYLE) Or WS_SYSMENU
End Sub
11. 记录窗体的大小及位置和程序中的一些设置
Private Sub Form_Load()
Me.Width = GetSetting(App.Title, Me.Name, "Width", 7200)
Me.Height = GetSetting(App.Title, Me.Name, "Height", 6300)
Me.Top = GetSetting(App.Title, Me.Name, "Top", 100)
Me.Left = GetSetting(App.Title, Me.Name, "Left", 100)
Check1.Value = GetSetting(App.Title, Me.Name, "check1", 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SaveSetting(App.Title, Me.Name, "Width", Me.Width)
Call SaveSetting(App.Title, Me.Name, "Height", Me.Height)
Call SaveSetting(App.Title, Me.Name, "Top", Me.Top)
Call SaveSetting(App.Title, Me.Name, "Left", Me.Left)
Call SaveSetting(App.Title, Me.Name, "check1", Check1.Value)
End Sub
12. 解决mschart控件数据更改时的闪动现象
1、在有MSChart控件的窗体中另外加入一个PictureBox控件,如MSChart1和Picture1。
2、使Picture1和MSChart1大小一致,位置相同(通过左对齐和顶端对齐)。
3、使Picture1在MSChart1前端,设置Picture1的Visible为False,即不可见。只有刷新数据时Picture1才显示。
'刷新数据过程
Private Sub Refresh()
Dim V_newchar() 'n维数组
……
Picture1.Visible = True
MSChart1.ChartData = V_newchar '给MSChart1重新赋值,即刷新数据
MSChart1.EditCopy '将当前图表的图片复制到剪贴板中
Picture1.Picture = Clipboard.GetData() '给Picture1赋值剪贴板中的图片
End Sub
这样每一次刷新数据时Picture1显示的图片都不会产生闪烁现象
|
|