-- 作者:飞
-- 发布时间:2012/9/23 1:05:00
--
先上个效果图:
此主题相关图片如下:无标题.png
此主题相关图片如下:untitled.gif
建一个空白的窗口,类型为独立窗口或者模式窗口,往上面各拖一个Button与Panel控件,panel设置一下背景颜色突出显示,并锚定到窗口的上下左右
全局代码:
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowCallBack, ByVal lParam As Integer) As Integer Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Integer) As Integer Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Long) As Integer Delegate Function EnumWindowCallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer Public Const SWP_NOSIZE = &H1 Public Const HWND_TOP = 0
Public IntCalcHandle As Integer
Public Function EnumWindowProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer If IsWindowVisible(hwnd) Then Dim StrCaption As String = New String(Chr(0), 255) GetWindowText(hwnd, StrCaption, 256) StrCaption = StrCaption.Replace(Chr(0), "") If StrCaption <> "" Then If StrCaption = "计算器" Then IntCalcHandle = hwnd Return 0 End If End If End If Return 1 End Function
窗口上的Button1的Click事件代码:
Dim Proc As New Process Proc.File = "calc.exe" Proc.Start() IntCalcHandle = 0 Proc.WaitForInputIdle() System.Threading.Thread.Sleep(200) EnumWindows(AddressOf EnumWindowProc, 0) If IntCalcHandle = 0 Then Return SetWindowPos(IntCalcHandle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE) SetParent(IntCalcHandle, e.Form.Controls("Panel1").BaseControl.Handle.ToInt32)
[此贴子已经被作者于2012-9-23 1:06:48编辑过]
|