调用http://www.cnblogs.com/xyocj/archive/2005/04/24/144539.html
做成的dll~
form
Imports Microsoft.WindowsCE.Forms
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Class HButtonClass HButton
Inherits System.Windows.Forms.Form
Dim messageWindow As myMessageWindow
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Function MakeBitmap()Function MakeBitmap(ByVal temp As Integer) As Bitmap
Dim bmp As New Bitmap(ImageList1.Images(temp))
Return bmp
End Function
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Windows 窗体设计器生成的代码#Region " Windows 窗体设计器生成的代码 "
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Sub New()Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
Me.messageWindow = New myMessageWindow(Me)
RegisterHKeys.RegisterRecordKey(Me.messageWindow.Hwnd)
Dim button1 As New PictureButton
Dim button2 As New PictureButton
Dim button3 As New PictureButton
Dim button4 As New PictureButton
button1.Parent = Me
button2.Parent = Me
button3.Parent = Me
button4.Parent = Me
button1.Bounds = New Rectangle(3, 0, 32, 32)
button2.Bounds = New Rectangle(38, 0, 32, 32)
button3.Bounds = New Rectangle(73, 0, 32, 32)
button4.Bounds = New Rectangle(108, 0, 32, 32)
button1.ForeColor = Color.White
button2.ForeColor = Color.White
button3.ForeColor = Color.White
button4.ForeColor = Color.White
button1.BackgroundImage = MakeBitmap(0)
button1.PressedImage = MakeBitmap(1)
button2.BackgroundImage = MakeBitmap(2)
button2.PressedImage = MakeBitmap(3)
button3.BackgroundImage = MakeBitmap(4)
button3.PressedImage = MakeBitmap(5)
button4.BackgroundImage = MakeBitmap(6)
button4.PressedImage = MakeBitmap(7)
button1.Text = ""
button1.Text = ""
button1.Text = ""
button1.Text = ""
AddHandler button1.Click, AddressOf Button1_Click
AddHandler button2.Click, AddressOf Button2_Click
AddHandler button3.Click, AddressOf Button3_Click
AddHandler button4.Click, AddressOf Button4_Click
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents Button1 As System.Windows.Forms.Button
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub InitializeComponent()Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(HButton))
Me.ImageList1 = New System.Windows.Forms.ImageList
Me.Button1 = New System.Windows.Forms.Button
'
'ImageList1
'
Me.ImageList1.Images.Add(CType(resources.GetObject("resource"), System.Drawing.Image))
Me.ImageList1.Images.Add(CType(resources.GetObject("resource1"), System.Drawing.Image))
Me.ImageList1.Images.Add(CType(resources.GetObject("resource2"), System.Drawing.Image))
Me.ImageList1.Images.Add(CType(resources.GetObject("resource3"), System.Drawing.Image))
Me.ImageList1.Images.Add(CType(resources.GetObject("resource4"), System.Drawing.Image))
Me.ImageList1.Images.Add(CType(resources.GetObject("resource5"), System.Drawing.Image))
Me.ImageList1.Images.Add(CType(resources.GetObject("resource6"), System.Drawing.Image))
Me.ImageList1.Images.Add(CType(resources.GetObject("resource7"), System.Drawing.Image))
Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32)
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular)
Me.Button1.Location = New System.Drawing.Point(143, 0)
Me.Button1.Size = New System.Drawing.Size(40, 32)
Me.Button1.Text = "exit"
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
'
'HButton
'
Me.ClientSize = New System.Drawing.Size(186, 32)
Me.ControlBox = False
Me.Controls.Add(Me.Button1)
Me.Location = New System.Drawing.Point(0, 257)
End Sub
#End Region
Dim a As xy.Power
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Sub ButtonPressed()Sub ButtonPressed(ByVal button As Integer)
Select Case button
Case HardwareButtons.Hardware1
Exit Sub
Case HardwareButtons.Hardware2
Exit Sub
Case HardwareButtons.Hardware3
Exit Sub
Case HardwareButtons.Hardware4
Exit Sub
Case HardwareButtons.Hardware5
Exit Sub
End Select
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Class myMessageWindowClass myMessageWindow
Inherits messageWindow
Public Const WM_HOTKEY = &H312
Dim example As HButton
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Sub New()Sub New(ByVal example As HButton)
Me.example = example
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Protected Overrides Sub WndProc()Sub WndProc(ByRef msg As Message)
Select Case msg.Msg
Case WM_HOTKEY
example.ButtonPressed(msg.WParam.ToInt32())
Return
End Select
MyBase.WndProc(msg)
End Sub
End Class
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
a.ScreenPowerOff()
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
a.PowerOff()
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Button3_Click()Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If MsgBox("soft reset?", MsgBoxStyle.OKCancel, "do you want to?") = MsgBoxResult.OK Then
a.SoftReset()
End If
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Button4_Click()Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If MsgBox("hard reset?", MsgBoxStyle.OKCancel, "do you want to?") = MsgBoxResult.OK Then
a.HardReset()
End If
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Sub Button1_Click_1()Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Application.Exit()
End Sub
End Class
class //定义一个pcturebutton的类
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Class PictureButtonClass PictureButton
Inherits Control
Private backgroundImg, pressedImg As Image
Private pressed As Boolean = False
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Property BackgroundImage()Property BackgroundImage() As Image
Get
Return Me.backgroundImg
End Get
Set(ByVal Value As Image)
Me.backgroundImg = Value
End Set
End Property
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Property PressedImage()Property PressedImage() As Image
Get
Return Me.pressedImg
End Get
Set(ByVal Value As Image)
Me.pressedImg = Value
End Set
End Property
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Protected Overrides Sub OnMouseDown()Sub OnMouseDown(ByVal e As MouseEventArgs)
Me.pressed = True
Me.Invalidate()
MyBase.OnMouseDown(e)
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Protected Overrides Sub OnMouseUp()Sub OnMouseUp(ByVal e As MouseEventArgs)
Me.pressed = False
Me.Invalidate()
MyBase.OnMouseUp(e)
End Sub
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Protected Overrides Sub OnPaint()Sub OnPaint(ByVal e As PaintEventArgs)
If Me.pressed AndAlso Not (Me.pressedImg Is Nothing) Then
e.Graphics.DrawImage(Me.pressedImg, 0, 0)
Else
e.Graphics.DrawImage(Me.backgroundImg, 0, 0)
End If
If Me.Text.Length > 0 Then
Dim size As SizeF = e.Graphics.MeasureString(Me.Text, Me.Font)
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), (Me.ClientSize.Width - size.Width) / 2, (Me.ClientSize.Height - size.Height) / 2)
End If
e.Graphics.DrawRectangle(New Pen(Color.Black), 0, 0, Me.ClientSize.Width - 1, Me.ClientSize.Height - 1)
MyBase.OnPaint(e)
End Sub
End Class
module //
Regist按键的一些函数放在了里面
Imports System.Runtime.InteropServices
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Enum KeyModifiersEnum KeyModifiers As Integer
None = 0
Alt = 1
Control = 2
Shift = 4
Windows = 8
Modkeyup = &H1000
End Enum
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Enum HardwareButtonsEnum HardwareButtons As Integer
Hardware1 = 193
Hardware2 = 194
Hardware3 = 195
Hardware4 = 196
Hardware5 = 202
End Enum
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Public Module RegisterHKeysModule RegisterHKeys
<DllImport("coredll.dll", Entrypoint:="RegisterHotKey", setLastError:=True)> _
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Function RegisterHotKey()Function RegisterHotKey( _
ByVal hWnd As IntPtr, _
ByVal id As Integer, _
ByVal Modifiers As KeyModifiers, _
ByVal key As Integer) As Boolean
End Function
<DllImport("coredll.dll")> _
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Private Function UnregisterFunc1()Function UnregisterFunc1( _
ByVal modifiers As KeyModifiers, _
ByVal keyID As Integer) As Boolean
End Function
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Public Sub RegisterRecordKey()Sub RegisterRecordKey(ByVal hWnd As IntPtr)
UnregisterFunc1(KeyModifiers.Windows, CType(HardwareButtons.Hardware1, Integer))
RegisterHotKey(hWnd, CType(HardwareButtons.Hardware1, Integer), KeyModifiers.Windows, CType(HardwareButtons.Hardware1, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(HardwareButtons.Hardware2, Integer))
RegisterHotKey(hWnd, CType(HardwareButtons.Hardware2, Integer), KeyModifiers.Windows, CType(HardwareButtons.Hardware2, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(HardwareButtons.Hardware3, Integer))
RegisterHotKey(hWnd, CType(HardwareButtons.Hardware3, Integer), KeyModifiers.Windows, CType(HardwareButtons.Hardware3, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(HardwareButtons.Hardware4, Integer))
RegisterHotKey(hWnd, CType(HardwareButtons.Hardware4, Integer), KeyModifiers.Windows, CType(HardwareButtons.Hardware4, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(HardwareButtons.Hardware5, Integer))
RegisterHotKey(hWnd, CType(HardwareButtons.Hardware5, Integer), KeyModifiers.Windows, CType(HardwareButtons.Hardware5, Integer))
End Sub
End Module