vb.net(vs2008) 使用api函数问题?(setwindowlong,setwindowpos)

feixuyue 2009-12-19 01:54:30
代码如下:
Public Class Form1
Const SWP_SHOWWINDOW = &H40
Const SWP_HIDEWINDOW = &H80
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000
Const WS_CAPTION = &HC00000
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const WS_OVERLAPPED = &H0&
Const WS_SYSMENU = &H40000
Const HWND_TOPMOST = -1
Dim hwnd As IntPtr
Declare Auto Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Auto Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags As Boolean) As Boolean
Declare Auto Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nlndex As Integer, ByVal wNewLong As Long) As Long
Declare Auto Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Auto Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start(("cmd.exe"))
System.Threading.Thread.Sleep(18) '过快下面的FindWindow有可能找不到窗体
hwnd = FindWindow(vbNullString, "c:\windows\system32\cmd.exe")
SetParent(hwnd, Me.TabPage1.Handle) '直接嵌套到TabPage1内
SetWindowLong(hwnd, (-16), GetWindowLong(hwnd, (-16)) And (Not WS_CAPTION) And (Not WS_VSCROLL) And (Not WS_HSCROLL)) '设置窗体样式
SetWindowPos(Me.Handle, -1, 100, 100, 100, 100, SWP_SHOWWINDOW) '改变子窗体位置
'MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '替代setwindowpos 可以正常调用
End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
With TabControl1
.Width = Me.Width - Button1.Width
.Height = Me.Height
End With
MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '随父窗体一起缩放
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DestroyWindow(hwnd) '也不能正常调用,只能关闭自己
End Sub
End Class
setwindowlong 有返回值
实在找不出错误,
...全文
1008 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
shsmhq 2009-12-20
  • 打赏
  • 举报
回复
Public Class Form1
Const SWP_SHOWWINDOW = &H40
Const SWP_HIDEWINDOW = &H80
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000
Const WS_CAPTION = &HC00000
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const WS_OVERLAPPED = &H0&
Const WS_SYSMENU = &H40000
Const HWND_TOPMOST = -1
Dim hwnd As Integer
Dim hprocess As Integer
Dim pid As Integer
Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
'Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Integer) As Integer
Declare Function DestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Integer) As Integer
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags As Boolean) As Boolean
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nlndex As Integer, ByVal wNewLong As Integer) As Integer
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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 Integer) As Integer


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start(("cmd.exe"))
System.Threading.Thread.Sleep(18) '过快下面的FindWindow有可能找不到窗体
hwnd = FindWindow(vbNullString, "c:\windows\system32\cmd.exe")
SetParent(hwnd, Me.TabPage1.Handle) '直接嵌套到TabPage1内
SetWindowLong(hwnd, (-16), GetWindowLong(hwnd, (-16)) And (Not WS_CAPTION) And (Not WS_VSCROLL) And (Not WS_HSCROLL)) '设置窗体样式
SetWindowPos(Me.Handle, -1, 100, 100, 800, 500, SWP_SHOWWINDOW) '改变子窗体位置
'MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '替代setwindowpos 可以正常调用
End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
With TabControl1
.Width = Me.Width - Button1.Width - 35
.Height = Me.Height
End With
MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '随父窗体一起缩放
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DestroyWindow(hwnd) '也不能正常调用,只能关闭自己 破坏(即清除)指定的窗口以及它的所有子窗口(在vb里使用:用处不大。原文:it is unlikely to be of much use.)

End Sub
End Class


最新
feixuyue 2009-12-20
  • 打赏
  • 举报
回复
试了那么多次发现这些不能用的函数对自己基本都有效果.
feixuyue 2009-12-20
  • 打赏
  • 举报
回复
郁闷了,还是不行,算了.
不知道vb.net有没有相应的窗口函数?
feixuyue 2009-12-19
  • 打赏
  • 举报
回复
我都怀疑我这个vs2008了,正在重新安装,希望能行.
我的程序的意思是把cmd.exe窗口嵌入me.tabpage1里面,再去掉标题栏和vscroll和hscroll,
弄了一天了.
你那个弄的出来不.截个屏看看.
谢谢了.
shsmhq 2009-12-19
  • 打赏
  • 举报
回复
我用的是2008版的,能运行起来啊. 我做过第三方软件,都可以用的..
feixuyue 2009-12-19
  • 打赏
  • 举报
回复
为什么连cmd.exe都运行不起来了

feixuyue 2009-12-19
  • 打赏
  • 举报
回复
thank you
我在调用setwindowlong 和destroywindow 是返回错误是过程错误或参数无效
shsmhq 2009-12-19
  • 打赏
  • 举报
回复
你的hwnd 没有返回值!

要改为下面的
Public Class Form1
Const SWP_SHOWWINDOW = &H40
Const SWP_HIDEWINDOW = &H80
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000
Const WS_CAPTION = &HC00000
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const WS_OVERLAPPED = &H0&
Const WS_SYSMENU = &H40000
Const HWND_TOPMOST = -1
Dim hwnd As Integer
Dim hprocess As Integer
Dim pid As Integer
Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
Declare Auto Function DestroyWindow Lib "user32" (ByVal hwnd As Integer) As Integer
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags As Boolean) As Boolean
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nlndex As Integer, ByVal wNewLong As Integer) As Integer
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (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 Integer) As Integer


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start(("cmd.exe"))
System.Threading.Thread.Sleep(18) '过快下面的FindWindow有可能找不到窗体
hwnd = FindWindow(vbNullString, "c:\windows\system32\cmd.exe")
SetParent(hwnd, Me.TabPage1.Handle) '直接嵌套到TabPage1内
SetWindowLong(hwnd, (-16), GetWindowLong(hwnd, (-16)) And (Not WS_CAPTION) And (Not WS_VSCROLL) And (Not WS_HSCROLL)) '设置窗体样式
SetWindowPos(Me.Handle, -1, 100, 100, 100, 100, SWP_SHOWWINDOW) '改变子窗体位置
'MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '替代setwindowpos 可以正常调用
End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
With TabControl1
.Width = Me.Width - Button1.Width
.Height = Me.Height
End With
MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '随父窗体一起缩放
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DestroyWindow(hwnd) '也不能正常调用,只能关闭自己
' 我也没能帮你弄好关闭
End Sub
End Class
feixuyue 2009-12-19
  • 打赏
  • 举报
回复
有哪位大哥能帮忙解决下不?
feixuyue 2009-12-19
  • 打赏
  • 举报
回复
两天都没弄出来,头都晕了,都想改学vc++了;
给自己顶一个!

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧