找回密码
 注册
Simdroid-非首页
查看: 107|回复: 0

[6. Basic] 求 VB嵌入DOS窗口,并固定DOS窗口位置和大小

[复制链接]
发表于 2011-8-11 21:04:20 | 显示全部楼层 |阅读模式 来自 北京
如题,代码如下
问题,SetWindowLong对DOS窗口的操作始终无效,求解……

  1. bas

  2. Option Explicit
  3. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  4. Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  5. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  6. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

  7. Public Const GWL_WNDPROC = (-4)
  8. Public Const WM_NCHITTEST = &H84
  9. Public Const HTCAPTION = 2

  10. Public oldhwnd As Long
  11. Public Flag As Boolean



  12. Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  13.    
  14.     If Flag = False Then
  15.         Flag = True
  16.         Debug.Print "WndprocHandle="; hWnd
  17.     End If
  18.    
  19.     If uMsg = WM_NCHITTEST Then
  20.         If DefWindowProc(hWnd, uMsg, wParam, lParam) = HTCAPTION Then
  21.             WndProc = 1
  22.             Exit Function
  23.         End If
  24.     End If
  25.    
  26.    WndProc = CallWindowProc(oldhwnd, hWnd, uMsg, wParam, lParam)
  27. End Function

  28. form1

  29. Option Explicit
  30. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

  31. Private Sub Command1_Click()

  32.     Dim commandstring As String
  33.     Dim TaskID As Long
  34.     Dim hWnd As Long
  35.    
  36.     TaskID = Shell("cmd.exe", vbNormalNoFocus)
  37.    
  38.     MsgBox "开始运行DOS"
  39.    
  40.     hWnd = FindWindow("ConsoleWindowClass", "C:\WINDOWS\system32\cmd.exe")
  41.    
  42.    
  43.     SetParent hWnd, Form1.hWnd
  44.    
  45.     oldhwnd = SetWindowLong(hWnd, -4, AddressOf WndProc)
  46.    
  47. End Sub

  48. Private Sub Form_Unload(Cancel As Integer)
  49.     Unload Form1
  50. End Sub

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-11-1 11:37 , Processed in 0.033629 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表